Concept explainers
Pointer in C++:
A pointer is a variable whose value will be another variable’s address. Generally, a pointer variable is declared as follows:
type *var-name;
Here, “type” is the pointer’s base type and “var-name” is the pointer variable name. The asterisk is used to designate a variable as a pointer.
The delete operator:
The delete operator is used to destruct the object that is created with new by deallocating the memory associated with the object.
The syntax of delete operator is as follows:
[] delete cast-expression
[] delete[] cast-expression
In the above statement, the “cast-expression” argument must be a pointer to a block of memory previously allocated for an object created with the new operator.
Given code:
The following code is used to create a dynamic array.
int *entry; //Initialise pointer
entry = new int[10]; //create a dynamic array
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Problem Solving with C++ (9th Edition)
- in c++arrow_forwardWrite a program that reads an unknown number of integers (int16_t) from the keyboard, terminated when the value (-10000) is given, and stores these into a dynamically sized array. The array should be initialised with a size to hold 10 values, and should increase in size by steps of 10 values whenever the array needs to be resized. (Note that the array should always have capacity to hold another value, for example, when it is holding 10 values the array size should be 20; the next step size up). Once it reads -10000, the program should print how many numbers it read in the format Numbers read = , then exit. The program must free() the array before exiting (but after printing the how many numbers have been read). You can use scanf("%hd", &number) to read a 16 bit integer. Note: because of the way we test this, you must not call realloc() if you just read in -10000; be efficient! For example: Input 1 2 3 4 5 -10000 Result _TESTALLOC: (calloc) Add block 0, total memblks 20 _TESTALLOC:…arrow_forwardCreate two Arrays A with 10 unsorted integer elements and B with 10 unsorted floatelements. Find the largest element in A and B and then sum both of them calling afunction SumAB() by reference. Sort A and B and then call another function StichAB()to merge B with A. Be careful about memory leakage.arrow_forward
- 3. Write a class for the city database using unordered lists. Each database record contains the name of the city (a string of arbitrary length) and the coordinates of the city expressed as integer x and y coordinates. Your database should allow records to be inserted, deleted by name, and searched by name or coordinate. Implement the database using an array-based list. Develop a simple test (as the main function) Run your program and present the results of the test.arrow_forwardThis exercise give you practice working with a two-dimensional array. the Example 7.14 on two-dimensional arrays, recall that I loaded the array using an Initializer list. Modify Example 7.14. Instead of using an initializer list to load the array, create 2 functions: loadArray – function “loadArray“ will have 1 parameter which will be the grade array. The function will allow the user to enter 12 quiz grades (3 for each student), store each quiz grade in the appropriate element of the grade array, and return an int representing the number of quizzes entered (12). “loadArray” will use nested loops to prompt the user to enter the 12 grades. It will count each grade entered and return the number of quizzes entered. loadFromFile – function “loadFromFile” will have 1 parameter which will be the grade array. The function will return an int representing the number of quizzes read(12). “loadFromFile” will use nested loops to read the values from the file and store each quiz grade in the…arrow_forwardWrite a C++ program by using classes to delete duplicate elements from an array?After duplicate elements removal, sort the array in ascending order. After sorting the array, copy all sorted elements of the array1 into the array 2, then multiply values in array 1 and array2 and store it in array3.Further, you are not allowed to use for loop. You can use while loop, user define functions and multi level inheritance.arrow_forward
- 9.Please Implement quicksort in a JAVA programming language. The first version will use the first element of the array as the pivot. Please help me with a Java code , It needs to take the input from a file of 100 data elements. Can someone please help me with this coding problem. I have the data set file , but I cannot upload it in here. Kindly help me with the code. ...arrow_forwardUse C++arrow_forwardImplement an interleave function which combines two integer arrays into a new dynamic array. The term interleave means to alternatively insert the values of two arrays into a single array. For example, given these two arrays as input: Array A: 95 92 27 98 76 Array B: 40 96 This function will return the following dynamic array: 95 40 92 96 27 98 76 The algorithm should work with arrays of same or different size. All array indexing must be done using pointer arithmetic. int* interleave (int *a, int *b int s1, int s2) {arrow_forward
- 7. Write a program that will create a dynamically created 1D array of length n (given by the user) and store first n odd numbers in it. Try printing the size of the array using size of() function. Are you satisfied with the result of size of() function? If no, explain why? need the solve in c++arrow_forward2. Fill in the for-loop below with the correct parameters to make room for the new value. saved Let's say that you have to write a function to insert an element into an ordered array. It takes an array A, a size, an index and a value. The value needs to be inserted at Aſindex] without losing values that are already in the array. // Assume that the index is found to be within array bounds and there is room to insert. for (int i = ?; ?; ?) { A[i]=A[i-1]; } A[index]=value; size++; O 0; i 0; - O size; i> index; -- O size-1; i>= index; i--arrow_forwardWrite a program that declares/intializes two arrays as described in main() and has two functions. main() - The size of both arrays is 5. The first array has elements of type double. The values are for distance measurements. Choose a descriptive name for this array.The second array will have the unit of measure. Choose a descriptive name for this array. Initialize the first 4 elements using an initialization list with the values "mi", "mi", "km", "km". Assign a new value to the first element of the second array: "km"Assign a value to the last element of the second array: "mi" Use a loop with statement that ask the user to type in all of the values for the temperatures and assign them to the first array. Function calls in main() -- you might want to write the definitions first (or at least read about them) before coming back to main() to write the calls. call the function that prints the measurements along with the unit of measure.Call the function that can count the number of…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