Question: CPS 1 1 9 2 Computer Programming II Programming Assignment # 3 Max Points: 4 0 Objective: The objective of this exercise is to gain

CPS1192 Computer Programming II
Programming Assignment #3
Max Points: 40
Objective: The objective of this exercise is to gain experience with:
Pointers and Memory
Fill in answers to all of the questions. For some of the questions you can simply copy-paste appropriate text from the terminal/output window into this document. You may discuss the questions with your instructor.
Use IDE (preferably Microsoft Visual Studio) for this Programming Assignment
Name:
Part #1: Pointers and Pointer Arithmetic
[15 points]
What type of data does a pointer store? [1 point]
What information tells us the amount by which a pointer will increment? [1 point]
What will cout << ptr <<*ptr << endl; print? What is the difference between ptr and *ptr in that line of code? [4 point]
What is the output from the following statement: [2 point]
int primes[]={2,3,5,7,11}; int *ptr = primes;
ptr +=2;
cout <<*ptr << endl;
The output written to cout is:
What is the output from the following statement: [2 point]
int odds[]={1,3,5,7,11,13};
int *ptr = &odds[2];
cout <<*(--ptr)<< endl;
The output written to cout is:
What is the output from the following statement: [2 point]
int odds[]={1,3,5,7,11,13};
int *ptr = &odds[2];
if(*ptr ==5){
cout <<*(ptr--)<< endl;
} else{
cout <<*(++ptr)<< endl;
}
The output written to cout is:
What is the output from the following statement: [3 point]
int odds[]={1,3,5,7,11,13};
int primes[]={2,3,5,7,11};
int *ptr1= &odds[3];
int *ptr2= &primes[3];
if( ptr1== ptr2){
cout <<*(--ptr1)<< endl;
} else{
cout <<*ptr1<< endl;
}
The output written to cout is:
Part #2: Code Analysis
[18 points]
What input would make lead the program (myProgram1) to output Pass?[5 points]
What will the program print? [5 points]
What will the program print? [8 points]
Part #3: Using Pointers to Iterate Loops
[7 points]
Program: In this lab, the goal is to write a program that utilizes points to traverse an array of numbers specified by a user. The program will get a set of numbers from standard input. It should use pointers to insert the numbers into the array and then use pointers to traverse the array in reverse while printing the memory address and the factors of the number located at that memory location to which it points. A sample output is provided. The memory address and the even/odd should be comma separated and printed to standard output.
The program will:
Read one command-line argument: the number of elements in the array [1 point]
Example, the following command would ask the user for 5 numbers:
./PA35
Insert the numbers entered by the user into an integer array using pointers. [2 points]
Traverse the list in reverse using pointers. [2 points]
Print the value at the memory address to which it points and then print the factors of the value at the memory address to which it points (sample output below).[2 points]
SAMPLE OUTPUT:
NOTE: Operating on the array without using pointers will NOT receive partial credit.
Submit to D2L
The document must be submitted as a PDF
The code must be submitted *.cpp

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!