Starting Out with C++: From Control Structures through Objects, Brief Version (8th Edition)
8th Edition
ISBN: 9780134037325
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 16, Problem 25RQE
Write a function that dynamically allocates a block of memory and returns a char pointer to the block. The function should take an integer argument that is the amount of memory to be allocated. If the new operator cannot allocate the memory, the function should return a null pointer.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(a)
Determine whether the following variable declaration is valid
int INT;
A Valid
B Invalid
(b)
Determine whether the following variable declaration is valid.
int *ptr;
A Valid
B Invalid
(c)
Which of the following statement about pointer is TRUE?
A. A pointer variable is a variable used tostore an address
B.A pointer holds the data, rather thanwhere to find the data
C.The unary operator & is used to find anobject's value
D.The unary operator * is used to find an object's address
In C programming:
Write a function printAllCourses() which receives an array of course pointers and the array’s size, then prints all courses in the array by calling printCourseRow()
6. Write a swap function, that swaps the values of two variables in main, but usepointers instead of reference parameters.7. Write a function that takes an array of ints and its size as arguments. It shouldcreate a new array that is the same size as the argument. It should set the values inthe new array by adding 10 to each element in the original array. The functionshould return a pointer to the new array. (Make sure you use dynamic memoryallocation)
can i get answers for this two sub parts. thanks
Chapter 16 Solutions
Starting Out with C++: From Control Structures through Objects, Brief Version (8th Edition)
Ch. 16.1 - Prob. 16.1CPCh. 16.1 - Prob. 16.2CPCh. 16.1 - Prob. 16.3CPCh. 16.1 - Prob. 16.4CPCh. 16.1 - Prob. 16.5CPCh. 16.3 - Prob. 16.6CPCh. 16.3 - The following function accepts an i nt argument...Ch. 16.3 - Prob. 16.8CPCh. 16.3 - Prob. 16.9CPCh. 16.4 - Prob. 16.10CP
Ch. 16.4 - Prob. 16.11CPCh. 16 - Prob. 1RQECh. 16 - Prob. 2RQECh. 16 - Prob. 3RQECh. 16 - Prob. 4RQECh. 16 - What is unwinding the stack?Ch. 16 - What happens if an exception is thrown by a classs...Ch. 16 - How do you prevent a program from halting when the...Ch. 16 - Why is it more convenient to write a function...Ch. 16 - Why must you be careful when writing a function...Ch. 16 - Prob. 10RQECh. 16 - Prob. 11RQECh. 16 - Prob. 12RQECh. 16 - The line containing a throw statement is known as...Ch. 16 - Prob. 14RQECh. 16 - Prob. 15RQECh. 16 - Prob. 16RQECh. 16 - The beginning of a template is marked by a(n)...Ch. 16 - Prob. 18RQECh. 16 - Prob. 19RQECh. 16 - Prob. 20RQECh. 16 - Prob. 21RQECh. 16 - _____________ are pointer-like objects used to...Ch. 16 - Prob. 23RQECh. 16 - Write a function that searches a numeric array for...Ch. 16 - Write a function that dynamically allocates a...Ch. 16 - Make the function you wrote in Question 17 a...Ch. 16 - Write a template for a function that displays the...Ch. 16 - Prob. 28RQECh. 16 - Prob. 29RQECh. 16 - Prob. 30RQECh. 16 - Prob. 31RQECh. 16 - Prob. 32RQECh. 16 - Prob. 33RQECh. 16 - Prob. 34RQECh. 16 - T F All type parameters defined in a function...Ch. 16 - Prob. 36RQECh. 16 - T F A class object passed to a function template...Ch. 16 - Prob. 38RQECh. 16 - Prob. 39RQECh. 16 - Prob. 40RQECh. 16 - Prob. 41RQECh. 16 - T F A class template may not be derived from...Ch. 16 - T F A class template may not be used as a base...Ch. 16 - Prob. 44RQECh. 16 - Prob. 45RQECh. 16 - Prob. 46RQECh. 16 - Prob. 47RQECh. 16 - try { quotient = divide(num1, num2); } cout The...Ch. 16 - template class T T square(T number) { return T T;...Ch. 16 - template class T int square(int number) { return...Ch. 16 - Prob. 51RQECh. 16 - Assume the following definition appears in a...Ch. 16 - Assume the following statement appears in a...Ch. 16 - Prob. 1PCCh. 16 - Prob. 2PCCh. 16 - Prob. 3PCCh. 16 - Prob. 4PCCh. 16 - Prob. 5PCCh. 16 - IntArray Class Exception Chapter 14 presented an...Ch. 16 - TestScores Class Write a class named TestScores....Ch. 16 - Prob. 9PCCh. 16 - SortableVector Class Template Write a class...Ch. 16 - Inheritance Modification Assuming you have...Ch. 16 - Prob. 12PCCh. 16 - Prob. 13PCCh. 16 - 14. Test Scores vector
Modify Programming...Ch. 16 - Prob. 15PCCh. 16 - Prob. 16PCCh. 16 - Prob. 17PC
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What do you call a program that translates a high-level language program into a separate machine language progr...
Starting out with Visual C# (4th Edition)
Drives License Exam The local drivers license office has asked you to design a program that grades the written ...
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
What is a router?
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
Finish the program that takes a word as a command-line argument and looks up the word to see whether it is in t...
Programming in C
Explain why the rapid delivery and deployment of new systems is often more important to businesses than the det...
Software Engineering (10th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 1. Write a function called void swap with two parameters, which will receive the addressof x and y as pointer. The function should swap the value of x and y only if x is larger thany. Print the value of x and y after the function call. 2. Write a function called double getAverage(int *array, int SIZE), whereit accept the array as pointer, and return the average of the array. Print the returnedvalue from this function. Always use *array rather than subscript to access the arrayvalue.arrow_forwardWhich function does not return the pointer correctly?The code below calls the getline member function of cin to read a line of characters from cin into an array of characters up to a certain limit specified as the second parameter of the call.Your job is to find out if the pointer returned from the function can still be used by the caller of the function to access the memory that is pointed to by the pointer.char *getName() { char buf[80]; cout << "Enter your name: "; cin.getline(buf, 80); return buf;}char *getName() { char buf[80]; cout << "Enter your name: "; cin.getline(buf, 80); return buf;}char *getName() { char *buf = new char[80]; cout << "Enter your name: ";cin.getline(buf, 80); return buf;}None of thesechar getName(char buf, int size) { **cout << "Enter your name: ";cin.getline(buf, size);return buf;}arrow_forwardWrite a statement that declares a prototype for a function divide that takes four arguments and returns no value. The first two arguments are of type int. The last two arguments arguments are pointers to int that are set by the function to the quotient and remainder of dividing the first argument by the second argument. The function does not return a value.arrow_forward
- Implement a function writeEmpToFile that takes two arguments: a struct Employee pointer and a FILE *. It should write each field in order as an appropriate type. Note that you will probably want to write a length of the name before you write the characters of the name. By doing this, when you write the load function below, you can read the length of the string and use it to malloc a buffer of the proper size to hold the name. Because of the embedded name pointer, you CAN NOT write the Employee struct as a single struct. You will need to write it out field by field. You will want to write this as a binary file, not as a text file. Implement a SAVE command in your main loop that will save all the employees out to a file. The SAVE command should ask for a file name, similar to the way your FIND command asked for a name. Below is the work I have done so far that is required from the image but I have not been able to finish it and I need assistance with making the final changes that…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_forwardWrite a program that initialize an array of pointers with some DNA sequences. Create a non returning function named reverseDNA that takes a single pointer to char parameter. The function should reverse each DNA sequences passed to it. Use this function in main to display all the reversed sequences The program contains the following main steps *first u hv to intialize an array of pointers with dna sequences And then a non returning void function is supposed to be created that takes a single pointer to char parameter And then the function should reverse all the dna sequence of array of pointers from main and then display all of themarrow_forward
- Write a program that initialize an array of pointers with some DNA sequences. Create a non returning function named reverseDNA that takes a single pointer to char parameter. The function should reverse each DNA sequences passed to it. Use this function in main to display all the reversed sequences The program contains the following main steps *first u hv to intialize an array of pointers with dna sequences And then a non returning void function is supposed to be created that takes a single pointer to char parameter And then the function should reverse all the dna sequence of array of pointers from main and then display all of them. Write the program in carrow_forwardWrite a function which takes two arguments: a) A NULL-terminated array of pointer to function, and b) a char *. Each function in the array of function parameter takes the string as its argument and returns a string. The returned strings from the function calls should be copied (create a copy of the string) into an array of pointer to char (NULL terminated!) which YOUR function returns. Make the returned array of pointer EXACTLY the right size (count first, then allocate). Use indices to traverse the array of function pointers and the constructed array of pointers to char.arrow_forwardIn C programming: Write a function printCourse() which receives a course pointer and prints all its fields, 1 field per line, using the following conditions:• The labels (“Department”, “Course Number”, …) are left aligned• The values are right aligned• Course numbers must have leading zeroesarrow_forward
- Pointers are by default passed by value in a function. Group of answer choices True False ================= Given the below code segment, which of the following would allow you to deallocate all memory allocated to the pointer numbers? int* numbers = new int[5]; Group of answer choices delete[] numbers; delete numbers; delete[5] numbers; None of these ========== Consider the following code: int arr[][4] = { {1, 2, 3, 4}, {7, 8, 9, 10} }; cout << arr[1] << endl; What will be the output? Group of answer choices 1 7 Address of 1 Address of 7 Compilation error: Second [] bracket missing with arrarrow_forwardIn C Programming: Write a function printCourseRow() which receives a course pointer and prints all its fields as a single row. Use proper formatting so that when we print 2 or more courses as rows, the same members align below each other. Test the function, but don’t include the testing code in your homework.Upload a screenshot of a sample output.arrow_forwardChoose if each of the following is true or false:Dynamically binding data to virtual functions is limited to pointers and references.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License