Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ myprogramming lab Q 10887, (not a whole program! no main, just the class) *u

ID: 3832405 • Letter: C

Question

C++ myprogramming lab Q 10887, (not a whole program! no main, just the class) *use +=, ++

Write the implementation (.cpp file) of the Accumulator class of the previous exercise. The full specification of the class is:

An data member named sum of type integer .

A constructor that accepts an integer parameter . THe constructor initializes the data member sum to the value of the parameter .

A function named getSum that accepts no parameters and returns an integer . getSum returns 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 the parameter .

Explanation / Answer

class Accumulator {
  
int sum;
  
  
public :
Accumulator(int val){
sum = val;
}
  
int getSum()
{
return sum;
}
  
void add(int parameter){
sum = sum + parameter;
}
  
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote