Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that performs the following tasks. 1)Declare an int variable roo

ID: 3826112 • Letter: W

Question

Write a program that performs the following tasks.

1)Declare an int variable room and assign an integer value 12 to it. Declare a pointer variable roomptr that points to room. Write statements using address-of operator and dereferencing operator to output the address and the value of room, the address and the value of roomptr , and the value pointed to by roomptr . Observe the output.

2)Declare an int array arrayA with five elements, and initialize the elements to the odd integers from 1 to 9. Declare an int array arrayB with five elements, and initialize the elements to the even integers from 2 to 10.

3)Declare a pointer variable ptrA that points to arrayA. Declare a pointer ptrB variable that points to arrayB

4)Use a for statement to output the value of each element of arrayA using pointer offset notation combined with each element of arrayB using pointer offset notation to print out the contents of both arrays in ascending order.  

5)Use a for statement to output the value of each element of arrayA using array subscript notation combined with each element of arrayB using array subscript notation to print out the contents of both arrays in ascending order.  

6)Write statements to increment each element of arrayA by 10 using pointer variable ptrA.

7)Use a function addTen to complete task 6 on arrayB. The function addTen uses a pointer variable as one of the formal parameters.

Explanation / Answer

Hi, I have answered first 4 questions.

please repost others in separate post.

Please let me know in case of any issue in first 4.

1)Declare an int variable room and assign an integer value 12 to it. Declare a pointer variable roomptr that points to room. Write statements using address-of operator and dereferencing operator to output the address and the value of room, the address and the value of roomptr , and the value pointed to by roomptr . Observe the output.

int room = 12;

int *roomptr = &room;

cout<<"Address: "<<roomptr<<", Value : "<<*roomptr<<endl;

2)Declare an int array arrayA with five elements, and initialize the elements to the odd integers from 1 to 9.
Declare an int array arrayB with five elements, and initialize the elements to the even integers from 2 to 10.

int arrayA[5] = {1,3,5,7,9};
int arrayB[5] = {2,4,6,8,10};

3)Declare a pointer variable ptrA that points to arrayA. Declare a pointer ptrB variable that points to arrayB

int *ptrA = arrayA;
int *ptrB = arrayB;

4)Use a for statement to output the value of each element of arrayA using pointer offset notation combined with each element of arrayB using pointer offset notation to print out the contents of both arrays in ascending order.
  
   for(int i=0; i<5; i++){
       cout<<*(ptrA+i)<<endl;
       cout<<*(ptrB+i)<<endl;
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote