Question: Given a program with the following class definition: class TwoNumbers { public: TwoNumbers(int n1, int n2); TwoNumbers(); // initializes number1, number2 to 0 double sum();

Given a program with the following class definition:

class TwoNumbers {

public:

TwoNumbers(int n1, int n2); TwoNumbers(); // initializes number1, number2 to 0 double sum(); // returns sum of number1 & number2 double difference(); // returns difference of number1 from number2

double max(); // returns larger of number1, number2

private: double number1, number2;

};

Part a: Give definitions to all 5 functions based on the given comments

Part b: Given the following instructions in main(), explain why the code cannot be compile

TwoNumbers thisOne, thatOne(5,7); thisOne.number1++; thisOne.number2 -= 7; thatOne.number2 = thatOne.sum() + thisOne.difference();

cout << thisOne.max() / thatOne.max();

Part c: What change should we make to the class definition so the above code can be compiled

Part d: When you make the change, what will these instructions do

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!