Question: In this project, the students will finish three functions that are described in Programming Project 4 (on page 536) and Programming Project 6 (on page
In this project, the students will finish three functions that are described in Programming Project 4 (on page 536) and Programming Project 6 (on page 358). The student will also implement the main function and a print function to test these three functions. Please notice, there is a video notes for the solution of Project 6. However, your main function shall have more test than what in video notes.
The student may start with the attached code. Please rename the file as YourNameProg1.cpp. Turn in the file via the "Browse My Computer" link below (You need to click on Proj 1 link above first).
___
(Project 4) Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the preceding character, and so on, until the entire string is reversed. Write a main program to test your function on various strings of both even and odd length.
___
(Project 6) - One problem with dynamic arrays is that once the array is created using the new operator, the size cannot be changed. For example, you might want to add or delete entries from the array as you can with a vector. This project asks you to create functions that use dynamic arrays to emulate the behavior of a vector. First, write a program that creates a dynamic array of five strings. Store five names of your choice into the dynamic array. Next, complete the following two functions:
string* addEntry(string *dynamicArray, int &size, string newEntry); This function should create a new dynamic array one element larger than dynamicArray, copy all elements from dynamicArray into the new array, add the new entry onto the end of the new array, increment size, delete dynamicArray, and return the new dynamic array. string* deleteEntry(string *dynamicArray, int &size, string entryToDelete); This function should search dynamicArray for entryToDelete. If not found, the request should be ignored and the unmodified dynamicArray returned. If found, create a new dynamic array one element smaller than dynamicArray. Copy all elements except entryToDelete into the new array, delete dynamicArray, decrement size, and return the new dynamic array. Test your functions by adding and deleting several names to the array while outputting the contents of the array. You will have to assign the array returned by addEntry or deleteEntry back to the dynamic array variable in your main function.
___ /* This program requires the student to write 3 functions described in * Program project 4 (Page 535) and Program Project 6 (Page 536). * The student also need to add a print function to print out an array. * The student may watch video notes on MyProgrammingLab to get the idea * on how to write the main function and three of these four functions * * Author: Your Name * Version: The date */ #include #include #include using namespace std; void reverse(char* front, char* rear); // Precondition: The front and rear are pointing to the front // and rear of a C-string, respectively // Postcondition: The C-string is reversed string* addEntry(string* dynamiccArray, int& size, string newEntry); // Precondition: dynamicArray point to a array of strings with give size, // newEntry is a string // Postcondition: A new dynamic array is created, which is one larger than // dynamicArray All elements from dynamicArray are copied to // new array, the new entry is added to new array, the size // is increased, the dynamicArray is deleted, new dynamic // array is returned. string* deleteEntry(string* dynamicArray, int& size, string entryToDelete); // Precondition: dynamicArray point to a array of strings with give size, // newEntry is a string // Postcondition: The function should search dynamicArray for entryToDelete. // If not found, the request should be ignored and the // unmodified dynamicArray returned. If found, create a new // dynamic array one element smaller than dynamicArray. Copy // all element except entryToDelete into the new array, delete // dynamicArray, decrement size, and return the new dynamic // array void print(const string* dynamicArray, int size); // Precondition: dynamicArray point to a array of strings with give size, // Postcondition: The elements in dynamic array will be print out. One // element per line forllowed by its index int main() { // write code to test reverse function. // make sure that you test it on at least two strings // one string has even length, another string has odd length // write code to test add entry and delete entry function // you may watch video notes to get idea for this part return 0; } void reverse(char* front, char* rear) { // you implement this. Please read Programming Project 4 on page 535 } string* addEntry(string* dynamicArray, int& size, string newEntry) { // you implement this. Please read Programming Project 6 on page 536 // you may watch video notes to get the idea } string* deleteEntry(string* dynamicArray, int& size, string entryToDelete) { // you implement this. Please read Programming Project 6 on page 536 // you may watch video notes to get the idea } void print(const string* dynamicArray, int size) { // you implement this. // you may watch video notes to get the idea }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
