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;
}
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.