Design and code a class named Eboard that holds information for an electronic billboard.  Upon instantiation, an Eboard object may receive two integers specifying the width and height of the board and a null-terminated C-string containing the message to be displayed.  If the dimensions are omitted, assume a width of 10 characters and a height of 3 lines.  If the message is omitted, assume an empty message. 

For your Eboard objects to work properly, you will need to include a copy constructor, an assignment operator, and a destructor.  The assignment operator should accommodate changes to the size of the display.

Your class should also include the following overloaded operators:

  • an extraction operator (>>) that accepts a message from standard input
  • an insertion operator (<<) that displays the message on standard output
  • an assignment operator (=) that accepts a new message
  • an append operator (+=) that appends text to the existing message

Your objects should validate the width and height dimensions received from the user or programmer.  Your objects may truncate the message received to fit the dimensions of the billboard.  Your objects should display the message by wrapping it to fit the number of characters per line as shown in the example below, but should not display beyond the number of lines available on the billboard.

Both the new message assignment operator and the append operator should leave the size of the object´┐Żs display unchanged.  The append operator should insert a blank character between the existing message and the additional text whenever necessary.

For example, consider the following main program

 #include <iostream>
 using namespace std;
 #include "Eboard.h"
 int main () {
     EBoard test = "This is a long message", help(5, 6, "Help me please");

     cout << test;
     test = "Test 1 test 2";
     cout << test;
     test += "test 3";  // bonus
     cout << test;      // bonus
     cout << help;
     cin >> help;
     cout << help;
     return 0;

When used with your class, this program produces the following output

 This is a
 long messa
 Test 1 tes
 t 2
 Test 1 tes
 t 2 test 3
 me pl
 Enter max number of characters per line : 5
 Enter max number of lines : 5
 Enter message : It's ok now, I'm doing fine
 ok no
 w, I'
 m doi
 ng fi

  Designed by Chris Szalwinski   Copying From This Site   
Creative Commons License