1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Softa [21]
4 years ago
6

Write a full class definition for a class named Averager, and containing the following members:______An data member named sum of

type integer.An data member named count of type integer.A constructor with no parameters. Theconstructor initializes the data members sum and the data member count to 0.A function named getSum that accepts noparameters and returns an integer. getSumreturns the value of sum.A function named add that accepts an integer parameter and returns no value. add increases the value of sum by the value of theparameter, and increments the value of countby one.A function named getCount that accepts noparameters and returns an integer. getCountreturns the value of the count data member, that is, the number of values added to sum.A function named getAverage that accepts noparameters and returns a double. getAveragereturns the average of the values added to sum. The value returned should be a value of type double (and therefore you must cast the data members to double prior to performing the division).
Computers and Technology
2 answers:
alina1380 [7]4 years ago
6 0

Answer:

  1. public class Averager {
  2.    private int sum;
  3.    private int count;
  4.    public Averager(int sum, int count) {
  5.        this.sum = 0;
  6.        this.count = 0;
  7.    }
  8.    public int getSum(){
  9.        return sum;
  10.    }
  11.    public void add( int num){
  12.        this.sum+=num;
  13.        this.count++;
  14.    }
  15.    public int getCount(){
  16.        return this.count;
  17.    }
  18.    public double getAverage(){
  19.        double ave = (int)this.sum/this.count;
  20.        return  ave;
  21.    }
  22. }

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

balandron [24]4 years ago
3 0

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:

You might be interested in
STOP DELETING MY ANSWERS AND QUESTIONS!!!!!!!
puteri [66]

Answer:

no

Explanation:

trolled

3 0
3 years ago
What is the solution to the equation ?
ki77a [65]
There’s no solution to the equation
4 0
3 years ago
Read 2 more answers
WHO WANTS TO PLAY AMONG US
Elza [17]

Answer:

Explanation:

ME

8 0
3 years ago
Read 2 more answers
What can be written to perform a certain number of iterations or to iterate until a specific result is achieved?
OlgaM077 [116]

Answer:

The answer to this question is given below in the explanation section. However, the correct option is B. i.e a for loop.

Explanation:

The correct answer to this question is for-loop. Beause, in the for loop is written to perform a certain number of iterations or to iterate until a specific result is achieved.

for example, to calculate the average of 10 numbers, we use the for loop to iterate statements written in its body 10 times to calculate the average.

when the specific numbers of the iteration are reached it will get terminated.

for example

for (int i=0; i<=10; i++)

{

// perfrom average, code

}

this loop iterate 10 times or less, when it reached above the limit it gets stopped.

however, the other options are not correct, because an ordered data structure is like a list of order data, print function print something to the user or on screen. while an array is like a list of data of the same data type.

7 0
3 years ago
Which of the following statements about global variables is true? 1.A global variable is accessible only to the main function. 2
Korvikt [17]

Answer:

A global variable can have the same name as a variable that is declared locally within the function.

Explanation:

In computer program, we refer to a global variable as that variable that comes with a global perspective and scope, ensuring its visibility throughout the program, except it is shadowed. The set of this kind of variable is referred to as global state or global environment. One feature of global environment is that it can have similar name as a variable declared locally within the function.

7 0
3 years ago
Other questions:
  • Write a program whose inputs are three integers, and whose output is the smallest of the three values.
    6·1 answer
  • Most engines will contain how many cylinders in order to maintain a proper balance of weight and forces?
    12·2 answers
  • We have two processors. They are named PL and PS. PL has a large number of registers, and PS has a small number of registers. Th
    7·1 answer
  • HELP PLEASE ASAP!!! Does anyone know how to fix a broken iPhone which when I connect it to the charger it comes up with the Appl
    5·1 answer
  • Given an array a, write an expression that refers to the first element of the array .
    5·1 answer
  • When creating a storyboard, in which section do you mention how you move from one shot to the next?
    8·1 answer
  • Do you want my hero academia?<br><br><br><br><br><br> if so, who's your favorite character :&gt;
    5·2 answers
  • Write A Code In Python
    8·2 answers
  • Does anyone know the answer
    10·1 answer
  • A data mart is the operational database for the company. group of answer choices true false
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!