Sale!

CS 2401 Homework # 2 solved

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (5 votes)

(You can type your answers on the answer sheet so that it can be submitted electronically.)
Part One: (Static and automatic variables.)
1. If you have not already done so, make a directory for your CS2401 stuff
mkdir cs2401
// I’m pretty sure that most of you have already done this
2. Go into that directory
cd cs2401
3. Once you are in there make a directory for your labs and inside that one a directory for lab4.
4. Open a new file in your favorite editor, #include and put in your
using statement.
5. Type in this little function:
void pretty( ){
int x = 0;
x++;
for(int i = 0; i < x; ++i){ cout<<’*’;} cout< and the
using namespace std; – this time you will only need a main
2. Declare a pointer capable of pointing at an int. (int * ptr; )
3. Make the pointer point at a new integer. (ptr = new int; )
4. Print out the address of the new integer. (On your answer sheet write how you did this as well as the address that shows up.) (cout << ptr <
// at the top for this to work
cout<< ptr[used]; used++; if(used == capacity){ cout<<”Sorry no room left.\n”; break; } } 16. Note how many numbers you see in the output. 17. Now replace the cout and the break for a full array with a resizing which will do this: a. Set the tmpptr to a new integer array of capacity +5 size b. Copy the data from the original array to the new one using a loop or the copy function which we talked about in class c. Adjust the capacity variable so it accurately reflects the size of the new array d. Delete the original array, remembering to use the [ ]’s e. Assign ptr to tmpptr, so these pointers will both point at the newer array f. Do a cout<<”Resized\n”; to report that this was done. 18. Now run your program – what do you see? 19. Finally, comment highlighted code “cout<< ptr[used];” in question 15, and then at the end of this loop that has filled and output the array, put this a. tmpptr[2] = 0; b. Write a loop that will output all the numbers in the ptr array. 20. What do you see? 21. Submit the finished code for each of the three parts and your answer sheet to Blackboard, making sure that your name appears on both your code and the answer sheet.