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
President Roosevelt's Fireside Chats were:
larisa86 [58]
C. Entertaining radio shows that families listened to in the evening. He did these chats to inform the public on what he was going to do about the problems facing the public.
3 0
3 years ago
Read 2 more answers
What is the purpose of the domain name?
Aloiza [94]

Answer:

Purpose. Domain names serve to identify Internet resources, such as computers, networks, and services, with a text-based label that is easier to memorize than the numerical addresses used in the Internet protocols.

6 0
3 years ago
How many answers do you need to be able to write messages on here??
Kipish [7]

1,000

Hope this helps!



~Courtney

3 0
3 years ago
Choosing the “Quick Print” button will ____________.
harkovskaia [24]
Choosing the "Quick Print" button will print to the default print (Answer is B). The quick print function is accessible in the Quick Access Tool bar . By clicking the drop down arrow of the quick access tool bar it will let you choose different types of default access including your Quick print.
7 0
3 years ago
How does a light bulb work
koban [17]
A light bulb is usually powered by a wire producing electricity. The energy can also come from wind turbines or solar panels.

Hope this helps
7 0
4 years ago
Read 2 more answers
Other questions:
  • When a crystal grows in unrestricted space, how does growth occur?
    14·2 answers
  • What are the challenges of photographing at night? Why did the photographer “paint” the waterfall with the flashlight?
    9·1 answer
  • Database administrators must make sure that ________ and ________ techniques and procedures are operating to protect the databas
    6·1 answer
  • Which data type or collection of data types can SOQL statements populate or evaluate to?
    9·1 answer
  • What are two examples of ways an electronic record may be distributed to others?
    15·1 answer
  • Tower Building Activity
    12·1 answer
  • What’s bigger 4,000,000 KB or 2.8 GB
    5·2 answers
  • What is said to be the first mechanical calculator​
    7·2 answers
  • Your company is a small start-up that has leased office space in a building shared by other businesses. All businesses share a c
    6·1 answer
  • In which of the following stages of the development process is a team MOST likely to interview a potential user of an app?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!