Respuesta :
Answer:
- public class Averager {
- private int sum;
- private int count;
- public Averager(int sum, int count) {
- this.sum = 0;
- this.count = 0;
- }
- public int getSum(){
- return sum;
- }
- public void add( int num){
- this.sum+=num;
- this.count++;
- }
- public int getCount(){
- return this.count;
- }
- public double getAverage(){
- double ave = (int)this.sum/this.count;
- return ave;
- }
- }
Explanation:
- Lines 1-3 contains the class declaration and the member (data fields)
- Lines 4-7 is the constructor that initializes the fields to 0
- Lines 8-10 is the method that returns the value of sum getSum()
- lines 11-14 iss the method add() that adds a number to the member field sum and increases count by 1
- lines 15 - 17 is the method that returns total count getCount()
- Lines 18-21 is the method getAverage() That computes the average and returns a double representing the average values
Answer:
#ifndef AVERAGER
#define AVERAGER
class Averager{
public:
int sum;
int count;
Averager(){
sum = 0;
count = 0;
}
int getSum(){
return sum;
}
void add(int n){
sum += n;
count++;
}
int getCount(){
return count;
}
double getAverage(){
return (double)sum/count;
}
};
#endif
Explanation: