Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SPECIFICATIONS: Create a C++ class called Display, which is designed to display, on the standard output device any text that is sent to it and

SPECIFICATIONS:
Create a C++ class called "Display", which is designed to display,
on the standard output device any text that is sent to it and
whose definition is prototyped exactly as:
class Display {
private: // PRIVATE member data
int currentLine;
int lineLimit;
public: // PUBLIC member functions
Display( ); // default constructor
Display(int); // parameter constructor
void setLimit(int);
void show(const char *);
void operator<<(const char *);
void operator++( );
};
A Display object itself does NOT store any string(s) in memory!
The Display class has the following publicly available members:
PART 1:
Display( )
Default Display objects print a newline after every 3 strings
have been output.
PART 2:
Display(int n)
Alternatively, a Display object may be created by supplying
an integer 'n' which is used to control how many strings are
displayed before outputting a new line.
NOTE: All Display objects start out having displayed 0 strings!
PART 3:
void setLimit(int n)
This function accepts an integer 'n' and returns nothing.
The setLimit function updates the value used to control how
many strings are displayed before outputting a new line,
but only if 'n' is within the range 0 to 5 inclusive.
Values of 'n' outside this range are to be ignored and DO NOT
update any class values.
PART 4:
void show(const char *s)
The show function outputs the constant string 's' on the screen.
A space is then displayed unless the count of strings on the current
line matches the value in lineLimit is which case no space is
displayed and the value that controls the string count is
reset to zero.
PART 5:
void operator<<(const char *s)
It is possible to send a constant string to a Display object
using the << operator with a Display object on the left and a
constant string on the right. This operator performs the same
operation as the show( ) function specified earlier (see above)
and returns no value.
PART 6:
void operator++( )
It is possible to increase the number of strings that a Display
object sends to the standard output before displaying a newline by
overloading the prefix operator ++. This operator returns no value
and may only increase the value to a maximum of 5.
MAIN PROGRAM:
For example, the following main( ) program:
#include
#include
#define NUM 15
class Display {
private: // PRIVATE member data
int currentLine;
int lineLimit;
public: // PUBLIC member functions
Display( ); // default constructor
Display(int); // parameter constructor
void setLimit(int);
void show(const char *);
void operator<<(const char *);
void operator++( );
};
int main( ) {
Display x1, x2(2);
int i;
char text[NUM][21] = { "Now", "we", "finally", "understand", "what", "is"
"happening", "it", "has", "only", "taken", "5", "long",
"weeks", "!" };
for(i=0; i
x1 << text[i];
}
x2.setLimit(4); // changes x2's line limit to 4 from the initial value of 2
printf("-------------------------------------------------- ");
for(i=0; i
x2 << text[i];
}
printf("-------------------------------------------------- ");
++x2; // increases x2's line limit to 5
++x2; // line limit is already set to 5, so this does not change anything
x2.setLimit(12); // this should not alter the lineLimit or change anything in the class
for(i=0; i
x2.show(text[i)];
}
return 0;
}
// Correct Program OUTPUT is:
Now we finally
understand what is
happening it has
only taken 5
long weeks !
--------------------------------------------------
Now we finally understand
what is happening it
has only taken 5
long weeks !
--------------------------------------------------
Now we finally understand what
is happening it has only
taken 5 long weeks !

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

Students also viewed these Databases questions