Question: SPECIFICATIONS: Create a C+t class called a Headline that can store up to and including 50 characters as a C string (a char array) and



![// PRIVATE member data char 5[51]; int index; public: // PUBLIC member](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f70b8ff196a_38366f70b8f89aab.jpg)

SPECIFICATIONS: Create a C+t class called a "Headline" that can store up to and including 50 characters as a C string (a char array) and whose definition is prototyped exactly as: class Headline \{ private: // PRIVATE member data char 5[51]; int index; public: // PUBLIC member functions Headline ( ); // default constructor Headline(const char *, int); // parameter constructor int setIndex(int); int setArray (const char *); int addToHeadline(const char *); const char* getArray ( ); wheadline ( ); // destructor \}; A Headline 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 Headline object would store the string: "Necessity is the mother of all inventions..." and set its index to 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 50 characters of the string 'sParam' are copied into the Headline's string 's' and its starting index would be set to ' n ' but only if ' n ' is within the range to 49 inclusive. If ' n ' is outside that range, then the Headline's starting index is set to . So for example, if the string 'sParam' was: "Hello world!", and ' n ' was 6 , then the Headline object would store the string: 012345678901 "Hello world!" and would begin displaying the string starting at index 6 A Headline object also contains the following other public: member functions: PART 3: int setIndex(int newIndex) This function changes the Headline's index to 'newIndex' but only if it is in the range of to 1 less than the length of the current Headline's string inclusive. If 'newIndex' is outside this range, then the Headline's index is not changed. The function returns 1 if the index was changed or otherwise. For example, if the Headline's string is: "Hello" (5 characters) and newIndex is: 20, then the index is NOT changed and a return value of is sent back. For example, if the Headline'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 setArray(const char *s1) This function replaces the Headline's string with 's 1 ' and updates its index to , but only if the length of ' s1 ' is less than or equal to 50 . If ' s1 ' is longer than 50 characters, then it is not copied over and the object's index is not changed. This function returns 1 if the Headline's string was changed or otherwise. PART 5 : int addToHeadline(const char *s2) This function ADDS to the Headline's string as many characters from ' 52 ' as the Headline's string can hold without exceeding 50 characters. For example if the Headline's string is currently: "Where do you want" and ' 52 ' is: " to go Today?", then the Headline's string becomes: "Where do you want to go Today?". This function does NOT update the index. The function returns 1 if the Headline was changed or 0 otherwise. NOTE: Be very careful with your solution to this function! As long as the Headline's string is less than 50 characters, then it will accept additional characters from ' 52 ', but not any more than 50 total! PART 6: const char* getArray( ) This function simply returns the address of the string being stored in the Headline 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( )). PART 7: readline( ) This function simply prints the string being stored in the Headline object from the beginning of the array (index 0), followed by a space, followed by the Headline's index (integer), followed by a newline. MAIN PROGRAM: // Your solution may ONLY use functions from the following // included C library header files. \#include stdio.h \#include // class declaration class Headline \{ private: char 5[51]; int index; public: Headline ( ); Headline(const char *, int); int setIndex (int newIndex); int setArray (const char *); int addToHeadline(const char *); const char* getArray( ); wheadline ( ); \}; int main ()\{ int i, pos; Headline c1, c2("Pieces of Eight by: STYX", 10), c3("Sup", 1); char addTostring[13][4] ={ "erc", "ali", "fra", "gil", "ist", "ice", "xpi", "ali", "doc", "iou", "s!!","@\#", "\&*A" }; printf("\%s ,c2.getArray()); c2.setIndex (6); printf("c1: \%s c2: \%s c3: %5 ", c1.getArray ( ), c2.getArray( ), c3.getArray ( )); printf("==============+=============+===================== ); // checking the setindex and getArray functions for (i=0;i7) c3.setIndex(0); if (pos) printf("\%s ", c3.getArray ()); \} // checking the setArray function and checking when attempting to overfill the Headline c1. setArray ("0123456789"); for (i=0;i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
