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]
3 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]3 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]3 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
Which tectonic plate setting is associated with the following features: great earthquakes; explosive volcanic eruptions; oceanic
yarga [219]

Answer:

Convergent Plate Boundary (subduction zone)

Explanation:

A convergent plate boundary is a location where two tectonic plates are moving toward each other, often causing one plate to slide below the other (in a process known as subduction). The collision of tectonic plates can result in earthquakes, volcanoes, the formation of mountains, and other geological events. An example is the one the formed Andes Mountain.

Cheers

8 0
2 years ago
Select all that apply.
VARVARA [1.3K]

You can move one cell to the right by using the Tab key.

8 0
3 years ago
What is the name of the fifth Sims 3 expansion pack
olga2289 [7]
2 were released as part 5 for the Sims 3 Expansion Pack Series. These two packs were the Pets Expansion and the Master Suite pack which added buyable and ownable pets and hotels.
8 0
2 years ago
The set of Visual Basic instructions that tells an object how to behave after an action by the user (such as clicking a button)
alexdok [17]

Answer:

Event procedure

Explanation:

Whenever a user perform certain action, such as press a button on the keyboard or click the mouse, etc. such action are called an event. when an event occurs, Visual Basic looks for BASIC instructions to tell the object in the program how to behave to the user event. The Visual Basic instructions that responds to this specific event is called an event procedure.

7 0
3 years ago
Create a Delegate to Compare two Integers.
Yanka [14]

Answer:

Delegate is a function pointer which points the address of a function.

Explanation:

Let the function to compare two integers takes two integers as arguments

C#.net syntax:

delegate void  Del(int,int);

Here delegate is the keyword. Del is the name of the delegate which stores the address of the function whose return type is void and which takes 2 integer arguments.

public void CompareIntegers(int x, int y)

{

if (x>y) Console.WriteLine("X is greater");

else Console.WriteLine("Y is greater");

}

delegate void  Del(int,int);

void main(){

Del del1=new Del(CompareIntegers);

}

6 0
3 years ago
Other questions:
  • A complete traversal of an n node binary tree is a(n)____ "operation if visiting a node is O(1)for the iterative implementation
    5·1 answer
  • Which element is located on the top left of the Word screen?
    6·1 answer
  • Write a java program that would request user name, id number, and state the time the user has reported at work.​
    12·1 answer
  • The following are part of characteristics of a software requirement specification.
    6·1 answer
  • Write a program that displays the middle value of three unduplicated input values. Hint: Review the four solutions in the smalle
    10·1 answer
  • During system testing, developers test the program in an environment that is very similar to how the program will eventually be
    11·2 answers
  • Can I make all front end project with Javascript OOP(Object Oriented Programming)?
    11·1 answer
  • To create a program in Scratch, you need to think systematically about the order of steps. This is known as
    11·1 answer
  • Which type of computer serves as the heart of the computing systems for many, perhaps most, major corporations and government ag
    12·1 answer
  • Differenciate between foreign key and primary key in database.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!