Question: Problem 1 Define a class called cMultipleThree that has the following properties.. It has a private integer member called num. That should be always positive
Problem 1
Define a class called cMultipleThree that has the following properties..
It has a private integer member called num. That should be always positive or zero.
Has a default constructor that sets num to 0
A constructor that accepts an integer and assigns it to num if the integer is a multiple of 3. If the integer is not a multiple of 3, it sets num to the next multiple of 3.
Display message code 10: Invalid value, negative number, whenever num becomes negative.
Provide an accessor method for num.
Provide a mutator method (setNum) that accepts an integer and sets num to that integer. If the integer is not a multiple of 3 it displays a message code 1: Invalid input, not multiple of 3. If the input is negative it displays a message code 10: Invalid value, negative number
Overload the operators postfix ++ to return the actual object and set num to the next multiple of 3.
Overload the operators prefix -- to set num to the previous multiple of 3 and return the object.
Overload operators + and between two cMultipleThree that should return a cMultipleThree. If the result is negative, display code 5: +/- yielding negative number
Overload operators + and between an cMultipleThree and an integer returning an cMultipleThree. The integer is added to num (for +); if the result of the addition is not a multiple of 3, num must be set to the first multiple of 3 greater than the result (same for -). If the result is negative display code 5: +/- yielding a negative number
Overload operators + and between an Integer and an cMultipleThree returning an Integer.
Overload the operators << and >> to output and input num.
What would be the output of the following main
void main () {
cMultipleThree n1(6), n2;
cMultipleThree n3 = n2 n1;
cout << n3 = << n3 << endl;
n1 = n1 + 5;
cout << n1 = << n1 << endl
n1 = n2++;
cout << n1 = << n1 << n2 = << n2 << endl;
int var = -5 n1;
cout << n1 = << n1 << var = << var << endl;
cMultipleThree n3 = (--n1) +2;
cout << n1 = << n1 << n3 = << n3 << endl;
cMultipleThree n3;
n3.setNum(5);
n1 = n1 + n3;
cout << n1 = << n1 << n3 = << n3 << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
