Question: Create a C++ structure called a Banner that can store up to and including 70 characters as a C string (a char array) and whose

Create a C++ structure called a "Banner" that can store up to and including 70 characters as a C string (a char array) and whose definition is prototyped exactly as: class Banner { private: // PRIVATE member data char s[71]; int index; public: // PUBLIC member functions Banner( ); // default constructor Banner(const char *, int); // parameter constructor int setIndex(int); int setString(const char *); int addToBanner(const char *); const char* getString( ); }; A Banner can be created/instantiated (when a variable is declared in main( ) or some other function), in one of 2 ways: PART 1: Without accepting ANY parameters, a Banner object would store the string: "Whom the Gods would destroy they first make mad!" and set its index to 0 to indicate where to begin displaying the string. This is the default constructor. PART 2: By accepting 2 parameters: a constant string 'sParam' and an integer 'n'. If created in this way, only up to the first 70 characters of the string 'sParam' are copied into the Banner's string 's' and its starting index would be set to 'n' but only if 'n' is within the range 0 to 69 inclusive. If 'n' is outside that range, then the Banner's starting index is set to 0. So for example, if the string 'sParam' was: "Hello World!", and 'n' was 6, then the Banner object would store the string: 012345678901 "Hello World!" and would begin displaying the string starting at index 6 ^ | +---- begin displaying the string here A Banner object also contains the following other public: member functions: PART 3: int setIndex(int newIndex) This function changes the Banner's index to 'newIndex' but only if it is in the range of 0 to 1 less than the length of the current Banner's string inclusive. If 'newIndex' is outside this range, then the Banner's index is not changed. The function returns 1 if the index was changed or 0 otherwise. For example, if the Banner's string is: "Hello" (5 characters) and newIndex is: 20, then the index is NOT changed and a return value of 0 is sent back. For example, if the Banner's string is: "Hello" (5 characters) and newIndex is: 4, then the index IS changed and a return value of 1 is sent back. PART 4: int setString(const char *s1) This function replaces the Banner's string with 's1' and updates its index to 0, but only if the length of 's1' is less than or equal to 70. If 's1' is longer than 70 characters, then it is not copied over and the object's index is not changed. This function returns 1 if the Banner's string was changed or 0 otherwise. PART 5: int addToBanner(const char *s2) This function ADDS to the Banner's string as many characters from 's2' as the Banner's string can hold without exceeding 70 characters. For example if the Banner's string is currently: "Where do you want" and 's2' is: " to go Today?", then the Banner's string becomes: "Where do you want to go Today?". This function does NOT update the index. The function returns 1 if the Banner was changed or 0 otherwise. NOTE: Be very careful with your solution to this function! As long as the Banner's string is less than 70 characters, then it will accept additional characters from 's2', but not any more than 70 total! PART 6: const char* getString( ) This function simply returns the address of the string being stored in the Banner object offset by the value in its index. So that, if the string is: "Hello World!" and the index is: 4, then the return value would be the address + 4 (which would display: "o World!" if output using printf( )). 
#include  #include  // structure declaration class Banner { private: char s[71]; int index; public: Banner( ); Banner(const char *, int); int setIndex(int newIndex); int setString(const char *); int addToBanner(const char *); const char* getString( ); }; Main Program: int main( ) { int i, pos; Banner c1, c2("Where The Streets Have No Name by: U2", 10), c3("abc", 1); char addToString[10][4] = { "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "yz", "!@#", "$%^" }; c2.setIndex(6); printf("c1: %s c2: %s c3: %s ", c1.getString( ), c2.getString( ), c3.getString( )); // checking the setIndex and getString functions for(i=0; i<121; i++) { pos = c1.setIndex(i); if(pos) printf("%s ", c1.getString( )); } // checking the addToBanner function for(i=0; i<10; i++) { pos = c3.addToBanner(addToString[i]); if(i > 7) c3.setIndex(0); if(pos) printf("%s ", c3.getString( )); } // checking the setString function and checking when attempting to overfill the Banner c1.setString("0123456789"); for(i=0; i<70; i++) { pos = c1.addToBanner(addToString[i % 10]); if(pos) printf("%s ", c1.getString( )); } return 0; } // Correct Program OUTPUT is: c1: Whom the Gods would destroy they first make mad! c2: The Streets Have No Name by: U2 c3: bc Whom the Gods would destroy they first make mad! hom the Gods would destroy they first make mad! om the Gods would destroy they first make mad! m the Gods would destroy they first make mad! the Gods would destroy they first make mad! the Gods would destroy they first make mad! he Gods would destroy they first make mad! e Gods would destroy they first make mad! Gods would destroy they first make mad! Gods would destroy they first make mad! ods would destroy they first make mad! ds would destroy they first make mad! s would destroy they first make mad! would destroy they first make mad! would destroy they first make mad! ould destroy they first make mad! uld destroy they first make mad! ld destroy they first make mad! d destroy they first make mad! destroy they first make mad! destroy they first make mad! estroy they first make mad! stroy they first make mad! troy they first make mad! roy they first make mad! oy they first make mad! y they first make mad! they first make mad! they first make mad! hey first make mad! ey first make mad! y first make mad! first make mad! first make mad! irst make mad! rst make mad! st make mad! t make mad! make mad! make mad! ake mad! ke mad! e mad! mad! mad! ad! d! ! bcdef bcdefghi bcdefghijkl bcdefghijklmno bcdefghijklmnopqr bcdefghijklmnopqrstu bcdefghijklmnopqrstuvwx bcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz!@# abcdefghijklmnopqrstuvwxyz!@#$%^ 0123456789def 0123456789defghi 0123456789defghijkl 0123456789defghijklmno 0123456789defghijklmnopqr 0123456789defghijklmnopqrstu 0123456789defghijklmnopqrstuvwx 0123456789defghijklmnopqrstuvwxyz 0123456789defghijklmnopqrstuvwxyz!@# 0123456789defghijklmnopqrstuvwxyz!@#$%^ 0123456789defghijklmnopqrstuvwxyz!@#$%^def 0123456789defghijklmnopqrstuvwxyz!@#$%^defghi 0123456789defghijklmnopqrstuvwxyz!@#$%^defghijkl 0123456789defghijklmnopqrstuvwxyz!@#$%^defghijklmno 0123456789defghijklmnopqrstuvwxyz!@#$%^defghijklmnopqr 0123456789defghijklmnopqrstuvwxyz!@#$%^defghijklmnopqrstu 0123456789defghijklmnopqrstuvwxyz!@#$%^defghijklmnopqrstuvwx 0123456789defghijklmnopqrstuvwxyz!@#$%^defghijklmnopqrstuvwxyz 0123456789defghijklmnopqrstuvwxyz!@#$%^defghijklmnopqrstuvwxyz!@# 0123456789defghijklmnopqrstuvwxyz!@#$%^defghijklmnopqrstuvwxyz!@#$%^ 0123456789defghijklmnopqrstuvwxyz!@#$%^defghijklmnopqrstuvwxyz!@#$%^de 

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!