Question: Exercise 11-1. Create a class called Integer that has a single, private data member of type int . Provide a class constructor that outputs a

Exercise 11-1. Create a class called Integer that has a single, private data member of type

int . Provide a class constructor that outputs a message when an object is created. Define

function members to get and set the data member, and to output its value. Write a test program

to create and manipulate at least three Integer objects, and verify that you cant assign a value

directly to the data member. Exercise all the class function members by getting, setting, and

outputting the value of the data member of each object.

Exercise 11-2. Modify the constructor for the Integer class in the previous exercise so that

the data member is initialized to zero in the constructor initialization list and implement a

copy constructor. Add a function member that compares the current object with an Integer

object passed as an argument. The function should return 1 if the current object is less than

the argument, 0 if they = objects are equal, and +1 if the current object is greater than the

argument. Try two versions of the Integer class, one where the compare() function argument is

passed by value and the other where it is passed by reference. What do you see output from the

constructors when the function is called? Make sure that you understand why this is so.

You cant have both functions present in the class as overloaded functions. Why not?

Exercise 11-3. Implement function members add() , subtract() , and multiply() for the

Integer class that will add, subtract, and multiply the current object by the value represented

by the argument of type Integer . Demonstrate the operation of these functions in your class

with a version of main() that creates Integer objects encapsulating values 4, 5, 6, 7, and 8, and

then uses these to calculate the value of 4*5^3 +6* 5^2 +7*5+8. Implement the functions so that the

calculation and the output of the result can be performed in a single statement.

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!