SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Operator Overloading Friends And References
Exercise:
Programming Projects
Question:4 | ISBN:9780132846813 | Edition: 5

Question

Cumulatively modify the example from Display 8.7 as follows.

a. In Display 8.7 , replace the private char members first and second with an

array of char of size 100 and a private data member named size.

Provide a default constructor that initializes size to 10 and sets the first 10 of the char positions to '#' . (This only uses 10 of the possible 100 slots.)

Provide an accessor function that returns the value of the private member size.

Test.

b. Add an operator[] member that returns a char& that allows the user to

access or to set any member of the private data array using a non- negative index that is less than size .

Test.

c. Add a constructor that takes an int argument, sz, that sets the first sz

members of the char array to '#'.

Test.

d. Add a constructor that takes an int argument, sz , and an array of char of

size sz. The constructor should set the first sz members of the private data array to the sz members of the argument array of char.

Test.

NOTES: When you test, you should test with known good values, with data on boundaries and with deliberately bad values. You are not required to put checks for index out of bounds errors in your code, but that would be a nice touch. Error handling alternatives: Issue an error message then die (that is, call exit(1) ) or give the user another chance to make a correct entry.


TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.