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)
- Following is the partition function for quicksort, where we have used the leftmost number as a pivot. Assume that our array, ARR = {14, 8, 7, 38, 22, 15, 9}, which is 7 in size. What will be the array ARR after we apply "partition(A, 0, 6)"* 9, 15, 22, 38, 7, 8, 14 7, 8, 9, 14, 15, 22, 38 9, 8, 14, 7, 22, 15, 38 9, 8, 7, 14, 22, 15, 38 7, 9, 15, 22, 38, 14, 6 38, 22, 15, 14, 9, 8, 7arrow_forwardQuestion This 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…arrow_forwardin c++arrow_forward
- Write 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_forwardDesign and implement a service that simulates PHP loops. Each of the three loop variants should be encapsulated in an object. The service can be controlled via a parameter and execute three different simulations. The result is returned as JSON. The input is an array consisting of the letters $characters = [A-Z]. -The For loop should store all even letters in an array.-The Foreach loop simulation is to create a backward sorted array by For loop, i.e. [Z-A] .-The While loop should write all characters into an array until the desired character is found. Interface:-GET Parameter String: loopType ( possible values: REVERSE, EVEN, UNTIL )-GET parameter String: until (up to which character) Output:JSON Object: {loopName: <string>, result: <array> }arrow_forwardUsing JAVA, write a method that swaps two rows of a two-dimensional array. The row indices to be swapped are passed as parameters to the method (Assume row indices are valid indices). Write a test program to demonstrate correct operation of the method.arrow_forward
- Create 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_forwardUsing the provided MinHeap implementation & helper functions, build two sorted arrays as follows: Option 1:Given an unsorted array, build a sorted array in ascending order utilizing a minheap. Hint: this one is quite easy.. Load a minheap with your unsorted array. From there you can get the min element from the minheap & build your sorted array. Option 2:Given your unsorted array loaded into a maxheap.. Using this max-heap, in which the root node contains the largest element, build a sorted array in ascending order. To achieve this you’ll ‘Float’ the max to the front and build the sorted list from the back. The basic idea is to sort in place. - Every time the algorithm polls from the heap, the heaps size shrinks by one. - Hence, the next place at the end of the array is not part of the heap anymore. - At this index the n-th smallest number is placed. Final Solution should look like: Array to be sorted by MinHeap: [5, 3, 17, 10, 84, 19, 6, 22,…arrow_forwardUsing C++ Implement the ordered version of removeElement in the window below. Your function should validate inputs and remove the element in the given position by moving all of the other elements down. // removeElement preserves the order of the remaining elements in the array.// @param: char array that is ordered in some way.// @param: int numElems is the number of elements// @param: int position of the element being removed// @returns true if the element is removed, false otherwise.// be careful to use reference parameters where necessary!arrow_forward
- Person receives text (string) messages on his/her phone. Message memory of a phone is very limited. A buffer is provided for storing messages when phone memory gets full. Message from buffer is loaded into phone memory when space is available. Messages are moved from buffer to phone in such a way that first received message is viewed first on screen. Implement buffer only using array. question solved in data structurearrow_forwardInstructions Redo Programming Exercise 6 of Chapter 8 using dynamic arrays. The instructions have been posted for your convenience. The history teacher at your school needs help in grading a True/False test. The students’ IDs and test answers are stored in a file. The first entry in the file contains answers to the test in the form: TFFTFFTTTTFFTFTFTFTT Every other entry in the file is the student ID, followed by a blank, followed by the student’s responses. For example, the entry: ABC54301 TFTFTFTT TFTFTFFTTFT indicates that the student ID is ABC54301 and the answer to question 1 is True, the answer to question 2 is False, and so on. This student did not answer question 9 (note the empty space). The exam has 20 questions, and the class has more than 150 students. Each correct answer is awarded two points, each wrong answer gets one point deducted, and no answer gets zero points. Write a program that processes the test data. The output should be the student’s ID, followed by the…arrow_forwardInstructions Redo Programming Exercise 6 of Chapter 8 using dynamic arrays. The instructions have been posted for your convenience. The history teacher at your school needs help in grading a True/False test. The students’ IDs and test answers are stored in a file. The first entry in the file contains answers to the test in the form: TFFTFFTTTTFFTFTFTFTT Every other entry in the file is the student ID, followed by a blank, followed by the student’s responses. For example, the entry: ABC54301 TFTFTFTT TFTFTFFTTFT indicates that the student ID is ABC54301 and the answer to question 1 is True, the answer to question 2 is False, and so on. This student did not answer question 9 (note the empty space). The exam has 20 questions, and the class has more than 150 students. Each correct answer is awarded two points, each wrong answer gets one point deducted, and no answer gets zero points. Write a program that processes the test data. The output should be the student’s ID, followed by the…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