Question: Exercise C6 The class Demo2 is defined as follows: class Demo2 { public: void setValues(double num 1, double num2); // to set the values of


Exercise C6 The class Demo2 is defined as follows: class Demo2 \{ public: void setValues(double num 1, double num2); // to set the values of both member variables double getValuel(void); // to return the value of member variable vall double getValue2(void); // to return the value of member variable val2 double getAverage (); // to compute the average of the values of both variables private: double vall; // the first data member double val2; // the second data member /*------------------------ function setValues() / set the values of the member variables to the given values void Demo2:: setValues(double num1, double num2) vall= num 1 val 2= num 2 /di /*returnsthevalueofthefirstmedoubleDemo2:*getValuel(void)return(vall); / function getValue2() / returns the value of the second member variable double Demo2:: getValue2(void) i return (val2); f 1. Declare object item of the class Demo2. 2. Read the values for the member variables of object item, and set the values of its member variables. 3. Compute the average of the values of the member variables of object item and print it. 4. Write a function named addDemo2 () that receives as arguments two objects of the class Demo2 and then builds and returns another object of the class Demo2 such that the value of each of its member variables is the sum of the values of the corresponding member variables of its arguments. 5. Write the sequence of statements to do the following: i. Declare object objl and set its member variables to 5 and 7 respectively ii. Declare object obj2 and set its member variables to 14 and 9 respectively. iii. Create a third object named objR such that the value of each of its member variables is the sum of the values of the corresponding member variables of objects objl and obj2 by calling function addDemo2( ). 6. Write a function incrDemo2 that receives as argument an object of the class Demo2 and increments the value of each of its member variables by 5 . 7. Write the statement(s) to increment the value of each member variable of object objl by 5 by calling function incrDemo2()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
