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
Paladinen [302]
3 years ago
14

Write a class named Accumulator containing: An instance variable named sum of type integer. A constructor that accepts an intege

r parameter, whose value is used to initialize the sum instance variable. A method named getSum that returns the value of sum. A method named add that accepts an integer parameter. The value of sum is increased by the value of the parameter.
Computers and Technology
1 answer:
Genrish500 [490]3 years ago
4 0

Answer:

The following are the code in the C++ Programming Language.

//define header file

#include <iostream>

// using namespace

using namespace std;

//define a class

class Accumulator

{

//set private access modifier

private:  

//declare integer type variable

int sum;

//set public access modifier

public:

//define constructor  

Accumulator (int sum)

{

//refer the same class as instance variable

this->sum = sum;

}

//define integer type function

int getSum()

{

//return the value of sum

return sum;

}

//define void type function

void add (int value)

{

//variable sum is increased by the argument value

sum += value;

}

};

Explanation:

<u>The following are the description of the code</u>.

  • Firstly, set the required header file and namespace then, define a class 'Accumulator' and inside the class.
  • Set private access modifier then, declare an integer data type variable 'sum'.
  • Declare a class constructor whose name is the same as the class name 'Accumulator()' and pass integer data type argument 'sum' in its parameter that refers to the same class as instance variable.
  • Define a integer data type function 'getSum()' that return the value of the variable sum.
  • Finally, define a void type function 'add()' and pass the integer data type argument 'value' in its parameter in which the variable sum is increased by the argument value .
You might be interested in
Patronage of most Medieval musicians was supplied by the
Arturiano [62]

Answer:

wrong^^its church

Explanation:

3 0
3 years ago
Que es la felicidad??​
olchik [2.2K]
Se feliz el amor es nada
4 0
2 years ago
I need help now I really do what is the answer thank you
Svetradugi [14.3K]
The answer is c
just replace the y with the y value and the x with the x value
4 0
3 years ago
19. Fair use applies to which of the following situations?
MatroZZZ [7]
I think it’s B if not it’s D both are similar
4 0
3 years ago
The navigation bar appears in the same position on each page and uses the same colors, fonts, and font styles.
Ivan

Answer:

true

Explanation:

I think that's what it has been in my time of classes

3 0
2 years ago
Other questions:
  • Which one of these variables has an illegal name?
    11·1 answer
  • You view a portion of a document on the screen through a ____.
    15·1 answer
  • The steps for moving data from one cell to another are _____.
    14·1 answer
  • Machines may aid in making work easier over a longer distance. true or false.
    7·1 answer
  • May someone type this down below just like how it is shown in the picture.
    7·1 answer
  • Travis just got promoted to network administrator after the previous administrator left rather abruptly. There are three new hir
    14·1 answer
  • Neview of related literature happens in two wayo (1) Traditional and
    6·1 answer
  • mary needs to rename her report.txt file to final_report.txt. which command will allow her to do this?
    10·2 answers
  • Which of the following is ture?
    11·1 answer
  • Which of the following is a mathematical function defined in the sql standard?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!