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)
- Write a public VB.Net subroutine that does the following: • Declare an array of integers of size larger than 5, you can determine the size. Read values from the keyboard to fill the array. Use inputbox to do this. Find the maximum value and subtract it from all elements in the array. Return the maximum value using a reference parameter. Note that this a subroutine not a functionarrow_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
- Revise 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_forwardDesign and implement a Java application for saving and operating on unique numbers in an array (the Java file name should be “Array4Uniques.java"). Its specific requirements are listed below: • It first asks for input for the size of the array, that is, the number of unique numbers to be stored on the array; • It then asks for two positive integers, min and max, to be used to define a sequence of random numbers, in the range between min and mæx inclusive; • The application will now keep generating a random number in the range defined above, if the random number is unique (that is not on the array by now), store this random number to the array. This process will continue until the array is full. • Hint: you may đefine a boolean variable alreacyOnArray for testing whether the newly generated random is already on the array. • At the end, print out the unique numbers on the array and the total number of random numbers generated for the whole process. • Use the following testing samples (2…arrow_forwardIn C: Create a program that allocates an array of integers frees them, and then tries to print the value of one of the array elements. Now, try to free a value that is not created by malloc (e.g., a pointer in the middle of the array you allocated above). What happens? Do you need gdb or valgrind to find this type of problem?arrow_forward
- Add a main function which takes any number (including 0) of command line arguments. It createsa new array whose entries are the results of calling make_reverse below on the given arguments. It thenprints the words of the new array, one per line. Finally, it frees any allocated memory. Add a Makefile so that typing make compiles the program into the executable reverse.exec, andtyping make test runs 3 tests. Typing make clean should remove any generated files. Program: #include <stdio.h> char * make_reverse(char * word){ int i, len=0; char temp; while(word[len]){ len++; } for(i=0; i<len/2; ++i){ temp = word[i]; word[i]=word[len-i-1]; word[len-i-1]=temp; } return word; }arrow_forward1. Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate? A. X contains an array of ten int values. B. x contains an array of ten objects of the Circle type. C. x contains a reference to an array and each element in the array can hold a reference to a Circle object. D. x contains a reference to an array and each element in the array can hold a Circle object. 2. Suppose s1 and s2 are two strings. Which of the following statements or expressions are incorrect? (3 A. int i 51.length(): B. boolean b =51.compareTo(s2); C. String s3 = s1 + 52; D. s1.charAt(0) = '5'; E. char c s1[0]; F. char c s1.charAt(s1.length0):arrow_forwardConsider a Dynamic Array declared inside the code using int* z = new int[10]; . How we will free the memory after we are done with the z array?arrow_forward
- Use C++arrow_forwardFor this assignment you are requested to write a program for the following scenario: • Build a program for a market, in the market we have items and each contains of three values (Item Name, Item Price, Item Expire Date). • The item values comes from a file each specification of the item is separated by (: ). • Must put the products that comes form the file into an array of object. • The program must check each product expire date if there is any products that expires in one month should notify the user as the output. • The expire checker process must be done on the array of object not directly from the file. NOTE: you can add only the month of the expiration date instead of adding full date (coffee:5000:August) and you can enter April as current month and then check the expiration.arrow_forwardWrite a program to check whether a given word is a palindrome by using pointers A palindrome is a word that is the same when spelled from the front and from the back. For example, Kayak, Level, Racecar, Radar, Rotator Create 2 char arrays and 2 corresponding pointers to the arrays Initialize array1 to the word Copy array1 backwards to array2 Compare array1 and array2, if they are the same, the word is a palindrome Modify the pseudocode below to produce the sample output. char word[5]= "kayak"; char reverseWord[5]; char *f = word; char *b = reverseWord; for () *(b_from_start) = *(f_from_end); Copy word to reverseWord but starting from the back for() Compare word and reverseWord if same palindrome; Sample: word word_reverse word k word_reverse k а a e a k Palindrome? Yes e a Palindrome? Noarrow_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