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++ (10th Edition)
- 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_forwardRevise the following Course class implementation in the following c++ code When adding a new student to the course, if the array capacity is exceeded, increase the array size by creating a new larger array and copying the contents of the current array to it. Implement the dropStudent function. Add a new function named clear() that removes all students from the course. Implement the destructor and copy constructor to perform a deep copy in the class. Write a test program that creates a course, adds three students, removes one, and displays the students in the course.arrow_forward
- Write 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_forwardUse C++arrow_forwardIn this assignment, you will decide how to keep the inventory in the text file. Then your program must read the inventory from the file into the array. Each product must have a record in the file with the name, regular price, and type. There are several options for storing records in the file. For example, • each value takes one line in the file (i.e., three lines for one product). Then you must take care of correct handling of the ends of the lines; • all values are in one line that can be read as a string. Then you must handle the parsing of the string; • all values are in one line separated by a delimiter. Then you must handle a line with delimiters. Assume that the inventory does not have more than 100 products. But the actual number is known only after the reading of the file. Once you can read data from the file into the array, you must add a new property to the product class – a static variable that holds the number of products in the inventory. Its value must grow as reading…arrow_forward
- Write the code of dynamic array with the name of ‘A’ and you will get the size of array from user and also get the values of array from the user and display that values on screen. TRY TO ADD COMMENTS IN THE CODE TOOarrow_forwardExercise 2: We are tasked to write a program that shows some information about 12 persons: first name, last name and telephone number. To do this, we have to create 3 arrays and fill them by the information wanted (first name, last name, phone number) respectively. In order to do some changes on this information, we can create a counter to specify the index of the information we want to change or to update; each index is referred to the each one of the people that we need to save their information.arrow_forward7. 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_forward
- 2. 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 Java code that read 8 positive integers from the user and store them in an array. Theprogram should ensure that the numbers of the array are positive. If not, the program will keepasking user to enter positive values. Then, it finds the position (or index) of the maximum andminimum values in the array, and swap them (move the max element to the position of the min,and move the min element to the position of the max). Then it calculates the median of theelements of this array (for this step an ascending order sort should be done before calculating themedian). Then run the code again for integer array of size Loop and conditionals should be usedarrow_forwardPlease answer the below question for operating system using shell script. write a program in bash that has a user_defined function array_sum that takes each element of array as argument andcalculates their sum. At each step the sum will printed and then the final sum will be printed. For example:Input Array:[2 3 7 9]Output: 2 5 12 21final sum: 21arrow_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