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++ (9th 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_forwardWrite a function in C language that takes your student number as a value and adds each digit of your student number into 2 different dynamic arrays according to whether they are odd or even (one array for the odd digits and another one for the even digits), and displays the odd and even values in the dynamic arrays separately. Example: Input: Student Number : 25698574 Output: Result: 7595 4862arrow_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 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_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_forwardIn C Programming: Write a function inputAllCourses() which receives an array of course pointers and the array’s size, then allows the user to input all courses in the array by calling inputCourse()arrow_forwardFunctions with 2D Arrays in Java Write a function named displayElements that takes a two-dimensional array, the size of its rows and columns, then prints every element of a two-dimensional array. Separate every row by a new line and every column by a space. In the main function, call the displayElements function and pass in the required parameters. Output 1 2 3 4 5 6 7 8 9arrow_forward
- Write a C++ program to prompt user for a file name and read the data containing information for a course, store and process the data, display a menu and allow user to pick an operation to perform continue till user decides to quit, and at the end print a final report shown below. Details: Set the array size to 50, but there could be less or more students info in the file, manage the list according the actual data elements. Develop a struct named Student to represent a student’s data: (Minimum the following data members need to be included), more is OK. Name (First, Last) ID Scores (An array to store test scores) Quiz (score for 1 quiz) Grade Average Write all the necessary utility functions to process the Student struct (readStudent, printStudent, processStudent,…) You may update and use the struct definition and utility functions developed for Programming assignment 5 or develop a new one. Develop any additional functions to process a list of students as necessary (Such as…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