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

1. Using C/C++, declare three integer variables (e.g. A, B, C) in main0 assign t

ID: 3823162 • Letter: 1

Question

1. Using C/C++, declare three integer variables (e.g. A, B, C) in main0 assign thell and values from standard input (cin). Then, call a function swap10 to swap their values through pointers (e.g. A, B, Care 4, 5, and 6, after calling swap0, A has B's value 5, B has C's value 6, and Chas A's value 4), and output A, B, and C; finally, define another function swap2 to swap A, B, c one more time using references Note: to swap A, B, C by pointers; the swap function needs to have three pointer arguments which are initialized with the address of A, B, C defined above. 2. Using C/C++, define an integer pointer in main0, and use this pointer to dynamically allocate an integer array with 50 elements; assign the array with random numbers in range 10, 9991. Then, pass the array as parameter(s) to a function prime count() which counts the number of the integers that are prime, and prints those integers, after the function call, print the "counter" result. finally, use delete to deallocate the array memories. Note that you need to define a Boolean function prime0 which tells whether an integer is prime or not. This function will be called and used by prime count0 to tell whether the numbers in the array are prime or not 3. edo of 1 and 2 by using separate header and source files: declaring the functions in header files, and implementing functions in source files. Note: in this homework, you need to find a classmate to form a team and use the pair programming approach to help each enhance programming skills: for each program one will write the program (driver and the other will verify whether the coding is correct not that you need to take turns to write and verify (e.g. in program 1, person A writes the code and person B checks it, in program 2, person B writes the code and person A checks it. Please state clearly in the comments who coded and who checked and tested in each program.

Explanation / Answer

1.

Input
a = 14
b = 45
c = 12

Processing
a = a + b + c;
a = 14 + 45 + 12 = 71;
a = 71;

b = a – b – c;
b = 71 – 45 – 12 = 14
b = 14;

c = a – b -c;
c = 71 – 14 – 12;
c = 45;

a = a – b – c;
a = 71 – 14 – 45 = 12;
a = 12;

Output
a = 12;
b = 14;
c = 45;

2.

This program performs addition of two numbers using pointers. In our program we have two two integer variables x, y and two pointer variables p and q. Firstly we assign the addresses of x and y to p and q respectively and then assign the sum of x and y to variable sum. Note that & is address of operator and * is value at address operator.