Question
Program You do not have to write an entire program for this assignment. A driver program, assign1.cpp is provided for this assignment. The purpose of
Program
You do not have to write an entire program for this assignment. A driver program, assign1.cpp is provided for this assignment. The purpose of a driver program is to test other pieces that you code. You do not need to write the driver program yourself. Following the instructions at the beginning of the assignment will copy the program into your assignment directory so that you can edit and modify it.
The code for the driver program is shown below:
/********************************************************************* FUNCTION: This program tests functions for manipulating C strings. *********************************************************************/ #include#include #include using std::cin; using std::cout; using std::endl; // Add your function prototypes here int main() { const int WORDSIZE = 15; char words[][WORDSIZE] = {"cattywampus", "collywobbles", "Lickety Split", "Kerfuffle", "Lollygag", ""}; char word[WORDSIZE]; // Test the copy function cout << "Copy \"cattywampus\", should see \"cattywampus\". "; copy(word, words[0], sizeof(word) - 1); cout << word << endl << endl; // Test the limit on the copy function cout << "Copy \"Supercalifragilisticexpialidocious\", should see \"Super\". "; copy(word, "Supercalifragilisticexpialidocious", 5); cout << word << endl << endl; // Test the replaceCopy function cout << "Replace 'l' in \"collywobbles\" with 'b', should see \"cobbywobbbes\". "; replaceCopy(word, words[1], 'l', 'b', sizeof(word) - 1); cout << word << endl << endl; // Test the limit on the replaceCopy function cout << "Replace 's' in \"Supercalifragilistic\" with 'd', should see \"duper\". "; replaceCopy(word, "Supercalifragilistic", 'S', 'd', 5); cout << word << endl << endl; // Test the caseChangeCopy function cout << "Case change \"Lickety Split\", should see \"lICKETY sPLIT\". "; caseChangeCopy(word, words[2], sizeof(word) - 1); cout << word << endl << endl; // Test the limit on the caseChangeCopy function cout << "Case change \"Supercalifragilistic\", should see \"sUPER\". "; caseChangeCopy(word, "Supercalifragilistic", 5); cout << word << endl << endl; // Test the reverseCopy function cout << "Reverse \"Kerfuffle\", should see \"elffufreK\". "; reverseCopy(word, words[3], sizeof(word) - 1); cout << word << endl << endl; // Test the limit on the reverseCopy function cout << "Reverse \"triskaidekaphobia\", should see \"ohpakediaksirt\". "; reverseCopy(word, "triskaidekaphobia", sizeof(word) - 1);; cout << word << endl << endl; cout << "Reverse \"Lollygag\", change case, and replace 'G' with 'Z', should see \"ZAZYLLOl\". "; replaceCopy(caseChangeCopy(reverseCopy(word, words[4], sizeof(word) - 1), word, sizeof(word) - 1), word, 'G', 'Z', sizeof(word) - 1); cout << word << endl << endl; cout << "Enter your entire name: "; read(words[5], sizeof(words[5])); cout << words[5] << endl << endl; cout << "Reverse your name and change case. "; cout << caseChangeCopy(reverseCopy(word, words[5], sizeof(word) - 1), word, sizeof(word) - 1) << endl; return 0; } // Add your function definitions here
Write the following functions and add them to assign1.cpp:
char* copy(char* destination, const char* source, size_t num)
Copy the first num characters of a string from the address specified by source to that specified by destination. Note that source and destination are both pointers. Return a pointer to the start of the copied string.
char* reverseCopy(char* destination, const char* source, size_t num)
Copy the first num characters of a string from the address specified by source to that specified by destination, reversing the order of the characters. Return a pointer to the start of the copied string.
char* caseChangeCopy(char* destination, const char* source, size_t num)
Copy the first num characters of a string in which the case of each lowercase character is shifted to uppercase (and uppercase to lowercase), from the address specified by source to that specified by destination. Return a pointer to the start of the copied string.
You can use the character functions found in the C standard library header file
char* replaceCopy(char* destination, const char* source, char target, char replace, size_t num)
Copy the first num characters of a string in which each instance of a "target" character is replaced by the "replace" character, from the address specified by source to that specified by destination. Return a pointer to the start of the copied string.
void read(char* destination, int n)
Read a string of characters entered by the user at the keyboard with a length no longer than n characters (including the null character at the end of the C string) into an address specified by destination. The user should be able to type a space or tab as part of the string.
The getline() method of the istream class in the header file
Feel free to use the existing C string manipulation functions in the C standard library header file
Sample Output
A sample run of the program is shown below.
Copy "cattywampus", should see "cattywampus". cattywampus Copy "Supercalifragilisticexpialidocious", should see "Super". Super Replace 'l' in "collywobbles" with 'b', should see "cobbywobbbes". cobbywobbbes Replace 's' in "Supercalifragilistic" with 'd', should see "duper". duper Case change "Lickety Split", should see "lICKETY sPLIT". lICKETY sPLIT Case change "Supercalifragilistic", should see "sUPER". sUPER Reverse "Kerfuffle", should see "elffufreK". elffufreK Reverse "triskaidekaphobia", should see "ohpakediaksirt". ohpakediaksirt Reverse "Lollygag", change case, and replace 'G' with 'Z', should see "ZAZYLLOl". ZAZYLLOl Enter your entire name: Margie Musich Margie Musich Reverse your name and change case. HCISUm EIGRAm
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started