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
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.
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Starting Out with Python (3rd Edition)
C++ How to Program (10th Edition)
Programming in C
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- please fastarrow_forwardIn a C++ program, you need to store the ID's and GPS's for 25 students. 1. Define 2 arrays that may be used in parallel to store the ID's and GPS's. 2. Write a loop to print the ID and GPA arrays in columns, with column headings. Put the information for each student on its own line.arrow_forwardIn this assignment you are to use pointers to manipulate dynamically created arrays. An array's name is basically a pointer to the fisrt element of the array. Dynamic arrays are created using pointer syntax, but can subsequently use array syntax, which is the best practice approach. Instructions (main.cpp) Inside main.cpp implement the following functions: int makeArray (const int size); This function dynamically allocates an int array of the specified size. • size the size of the dynamically allocated array. • returns - a dynamically allocated integer array of size elements. void initializeArray (int * array, const int size, const int initValue); This function initializes an array of size elements with the initValue. array-The array whose elements are to be initialized. size the size of the array. initValue the value with which to initialize each element. int duplicateArray (const int const sourceArray, const int size); This function duplicates an array of size elements. When copying…arrow_forward
- In this assignment you are to use pointers to manipulate dynamically created arrays. An array's name is basically a pointer to the fisrt element of the array. Dynamic arrays are created using pointer syntax, but can subsequently use array syntax, which is the best practice approach. Instructions (main.cpp) Inside main.cpp implement the following functions: int makeArray (const int size); This function dynamically allocates an int array of the specified size. • size the size of the dynamically allocated array. • returns - a dynamically allocated integer array of size elements. void initializeArray (int * array, const int size, const int initValue); This function initializes an array of size elements with the initValue. array The array whose elements are to be initialized. size the size of the array. initValue the value with which to initialize each element. int duplicateArray (const int const sourceArray, const int size); This function duplicates an array of size elements. When copying…arrow_forwardIn C++Monkey Business A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 × 5 array, where each row represents a different monkey, and each column represents a different day of the week. The program should first have the user input the data for each monkey. Then, it should create a report that includes the following information: Average amount of food eaten per day by the whole family of monkeys. The least amount of food eaten during the week by any one monkey. The greatest amount of food eaten during the week by any one monkey. Write functions: average() least() greatest() main()arrow_forwardWrite a C++ Program Create 4 arrays of type integer having the size of 11 and assign values to only 2 arrays using forloop.• Once values are assigned to 2 arrays then you have to copy the values/elementfrom both arrays and assign/paste those values to the third and fourth array.• After assigning values to the third and fourth array from the first and second array. Displayelements/values of array3 and array4. • Array2 elements/values will be copied to array4.In the end the array 3 and array4 will have the same elements/values as array1 and array2.arrow_forward
- In C++ programming Language using Visual Studio(Not Visual Studio Code) Suppose you have a vector of integer data, say { 1, 5, 4, 2, 3 }The data may eventually need to be transformed into some other form, say by sorting the data values for instanceThis would turn the vector into { 1, 2, 3, 4, 5 }Or say I wanted to take the original vector { 1, 5, 4, 2, 3 } and remove all the even numbers from itThis would turn the vector into { 1, 5, 3 }So in general terms, we start with an input vector, and it somehow gets transformed into its transformed vectorThe options really are almost limitless, but we will keep things simple for this checkpoint assignmentWe will be developing a base/derived class relationship that can perform custom transformations of data at runtimeYour submission must follow OOP best practices that incorporates topics in Gaddis' textbook chapters 13 through 15 { 1, 5, 4, 2, 3 } ==========(SORT)==========> { 1, 2, 3, 4, 5 }{ 1, 5, 4, 2, 3 } ======(REMOVE EVENS)======>…arrow_forwardProgramming in C language. AskForNumbers Declare an integer array lacally with the size of 200. Create a program that asks the user how many numbers the have. Use your getChoice() function from before. Make sure it does not exceed 200 as the locally declared array has the size of 200. Use a for loop and ask the user to enter each value that must be stored in the array. Use a second loop to display each number, and also determine the average of all values in the array. After the for loop, display the average of all numbers. This program will let you enter a list of numbers into an array. It will then display all of the numbers, and finally display the average of all numbers. How many numbers would you like to enter?5 Please enter a number:22 Please enter a number:33 Please enter a number:44 Please enter a number:55 Please enter a number:66 Number Number 2 is 33 Number 3 is 44 Number 4 is 55 Number 5 is 66 The average is 44 is 22arrow_forwardA c++ program is needed to store and manage the records of all the students in a particular class. Each record should consist of the student’s name, ID consists of program code and student number, 5 coursework marks, and an examination mark.Write a c++ program that creates an array of struct to keep 10 student’s records. Your program should allow user to input data and store them into a file. The program then reads from the file to calculate the final mark for every student, and display the student’s name, id, and final mark in a tabular format. The final mark is calculated as 60% from the average coursework marks (not including the lowest) and 40% from the examination mark. The output is also stored into a file.Use functions to calculate the final mark for a student and to display all the students’ information. Identify the suitable parameters and return value for each function.arrow_forward
- Use C++arrow_forwardC++ languagearrow_forwardin C++: SummaryJason, Samantha, Ravi, Sheila, and Ankit are preparing for an upcoming marathon. Each day of the week, they run a certain number of miles and write them into a notebook. At the end of the week, they would like to know the number of miles run each day and average miles run each day.InstructionsWrite a program to help them analyze their data. Your program must contain parallel arrays: an array to store the names of the runners and a two-dimensional array of five rows and seven columns to store the number of miles run by each runner each day. Furthermore, your program must contain at least the following functions: a function to read and store the runners’ names and the numbers of miles run each day; a function to calculate the average number of miles run each day; and a function to output the results. (You may assume that the input data is stored in a file and each line of data is in the following form: runnerName milesDay1 milesDay2 milesDay3 milesDay4 milesDay5 milesDay6…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education