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 ,julia Lobur
Chapter:
Friends Overloaded Operators And Arrays In Classes
Exercise:
Programming Projects
Question:8 | ISBN:9780321531346 | Edition: 7

Question

Define a class called Text whose objects store lists of words. The class Text will be just like the class StringVar except that the class Text will use a dynamic array with base type StringVar rather than base type char and

will mark the end of the array with a StringVar object consisting of a single blank, rather than using '\0' as the end marker. Intuitively, an object of the class Text represents some text consisting of words separated by blanks.

Enforce the restriction that the array elements of type StringVar contain no blanks (except for the end marker elements of type StringVar).

Your class Text will have member functions corresponding to all the member functions of StringVar. The constructor with an argument of type const char a[] will initialize the Text object in the same way as described below for input_line. If the C-string argument contains the new-line symbol '\n', that is considered an error and ends the program with an error message.

The member function input_line will read blank separated strings and store each string in one element of the dynamic array with base type StringVar.

Multiple blank spaces are treated the same as a single blank space. When

outputting an object of the class Text, insert one blank between each value of

type StringVar. You may either assume that no tab symbols are used or you can treat the tab symbols the same as a blank; if this is a class assignment, ask your instructor how you should treat the tab symbol.

Add the enhancements described in Programming Project 6. The

overloaded version of the extraction operator >> will fill only one element

of the dynamic array.

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'.