C++ The following code tells the compiler to reserve enough memory for a pair of integers, an array of 500 double precision numbers, and a string (c-string) containing 11 characters (actually 10 chars + the null terminator). const int MAX_LENGTH = 11; int number; double list[500]; char instring[MAX_LENGTH]; In many situations such declarations are exactly what the programmer needs. However, many times a programmer knows an array is needed, but has no idea exactly how large it needs to be. Instead of reserving as much memory as you believe you will ever need, you are better off waiting until run-time and dynamically allocating the array with the exact amount of memory actually needed. In C++ the “new” operator can be used to accomplish this. In fact, the statement list = new double[listSize]; allocates enough memory for an array containing exactly listSize doubles and assigns list to point to the array. Instructions: Open a new Visual Studio project. Open a new C++ source file. Write a short program to allocate an array dynamically, enter values into the array, and print out the array contents. Code to get you started is shown below. Fill in the blanks below before starting to type in the program. Use an array size between 5 and 10 elements. You are free to make up the exact input. Attach the source code and output for the data you have made up as the first page(s) behind this instruction packet. Sample Code: Fill in blanks, add code as needed, etc. #include

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
C++ C++ The following code tells the compiler to reserve enough memory for a pair of integers, an array of 500 double precision numbers, and a string (c-string) containing 11 characters (actually 10 chars + the null terminator). const int MAX_LENGTH = 11; int number; double list[500]; char instring[MAX_LENGTH]; In many situations such declarations are exactly what the programmer needs. However, many times a programmer knows an array is needed, but has no idea exactly how large it needs to be. Instead of reserving as much memory as you believe you will ever need, you are better off waiting until run-time and dynamically allocating the array with the exact amount of memory actually needed. In C++ the “new” operator can be used to accomplish this. In fact, the statement list = new double[listSize]; allocates enough memory for an array containing exactly listSize doubles and assigns list to point to the array. Instructions: Open a new Visual Studio project. Open a new C++ source file. Write a short program to allocate an array dynamically, enter values into the array, and print out the array contents. Code to get you started is shown below. Fill in the blanks below before starting to type in the program. Use an array size between 5 and 10 elements. You are free to make up the exact input. Attach the source code and output for the data you have made up as the first page(s) behind this instruction packet. Sample Code: Fill in blanks, add code as needed, etc. #include ___________________ using namespace std; void main ( ) { int listsize; // Storage for input size of the list double *list; // Pointer to dynamically allocated array. // Get the size of the array. cout << “Enter the array size: “; cin >> _______________ // Allocate an array of the specified size. ____________________________________________________ // Read in the array elements. cout << “Enter the array elements: “; for (int j=0; j < listsize; j++ ) cin >> _______________________; // Output the array elements. cout << “The array contains: “; for (int j=0; j < listsize; j++ ) cout >> _______________________; // Deallocate the memory used to store the string. __________________________________   Lab Task 2 – Dynamic Strings (An exercise in handling dynamically allocated strings) Textbook Reference: • pp. 522-526 The previous method also works well when the need is for a string whose length is not known at compile time. Instructions: Open a new Visual Studio project. Open a new C++ source file. Write a short program to allocate a string dynamically, asking the user how long the string needs to be. It will then allocate just that amount of memory. Complete the code below by filling in the missing C++ code. As before, you are free to make up the exact input. Attach clearly labeled source code and output as the next page(s) in your turn-in document. Sample Code: Fill in blanks, add code as needed, etc. #include ___________________ using namespace std; void main ( ) { char _________________; // Pointer to a c-string int length; cout << endl; << “Enter the number of characters in the string: “; cin >> length; // Allocate memory for the string. Remember to allow // space for the string delimeter. ____________________________________________________ // Read in and echo the string. cout << “Enter the string (no blanks allowed): “; cin >> _______________________; cout << “Input String: << _________________ << endl; // Deallocate the memory used to store the string. __________________________________ Lab Task 3 – Most Frequent Character (An opening exercise in processing C-Strings) Textbook Reference: • pp. 554-578 Write a function that accepts a pointer to a C-String as its argument. The function should return the character that appears most frequently in the string along with the number of times it appears. For example, if the input is “Hello Dolly” the output will be: l appears 4 times. You may assume a single letter will appear more times than any other in each input string. Ignore case in counting letters (i.e. D and d should be treated as if they are the same character). Do not consider blank spaces. You will probably want to use the getline function to read in the string. Test the program (you will need to create a main to call the function) and attach source code and output for the following strings as the last part of your turn-in document. Remember to always label each task with its task #, and attach them in the order produced. Hello Dolly This is the day the lord hath made Happy Days Are Here Again When Irish I’s Are Smiling
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY