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
What part of the code is a signal for the function to execute and pass back a value?
Trava [24]

Answer:

2

Explanation:

6 0
3 years ago
Read 2 more answers
Three homework questions I can't figure out, please help?
Burka [1]

It A

iT b

YOU CANT TRY THE TWO ONE THE WHO ARE WRITE

8 0
2 years ago
The faster alcohol is consumed, the faster it reaches the __________.
Anni [7]
The faster it reaches the bloodstream

6 0
3 years ago
Read 2 more answers
is skill in using productivity software, such as word processors, spreadsheets, database management systems, and presentation so
Digiron [165]

Answer:

It is general knowledge

Explanation:

What you covered is general knowledge and the entrance to computer science.

4 0
3 years ago
Develop an sec (single error correction) code for a 16-bit data word. generate the code for the data word 0101000000111001. show
Kipish [7]

Answer:

code = 010100000001101000101

Explanation:

Steps:

The inequality yields 2^{k} - 1 > = M+K, where M = 16. Therefore,

The second step will be to arrange the data bits and check the bits. This will be as follows:

Bit position              number              Check bits            Data Bits

21                                   10101

20                                  10100

The bits are checked up to bit position 1

Thus, the code is 010100000001101000101

3 0
3 years ago
Read 2 more answers
Other questions:
  • What procedures are involved in saving a file for the first time?
    10·2 answers
  • Frank is a writer. He needs to work for long hours and type for long periods on the computer. What injury can Frank develop?
    15·2 answers
  • What is a series of instructions or commands that a computer follows used to create software
    9·1 answer
  • What is the difference between line art and continuous tone copy?
    14·1 answer
  • ________ consists of detailed, preprogrammed instructions that control and coordinate the computer hardware components in an inf
    11·1 answer
  • Rachael has been posting negative comments on several of her peers' social media pages. Which of the six Ps is Rachael abusing?
    15·1 answer
  • You are attempting to upgrade a Windows Server 2008 R2 server to Windows Server 2016 Standard. What must be done in order to acc
    5·1 answer
  • Lab 6B: printing a binary number
    13·1 answer
  • Which directory stores the cron configuration file?.
    8·1 answer
  • 2. what are the advantages of breaking up a single logical message into a number of fixed-sized packets and then sending each on
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!