$30
P a g e | 1
CMPSC 122 – Intermediate Programming
Assignment #1
Total Points: 100
Question 1 (25 points)
Write a function that returns True if one number evenly divides another and false otherwise. Do
not use any local variables.
Question 2 (25 points)
Write a function with the following header:
int reverse (int number)
that takes an integer value and returns the number with its digits reversed. For example, given the number
7631, the function should return the number 1367.
Question 3 (25 points)
Write a program that uses a nested for loop to print the following output:
Question 4 (25 points)
Suppose we have in the main function of a program two double pointers with valid addresses stored in them.
The purpose of the program is to swap the contents of these pointers using a function call swapPointers. Write
the swapPointers function so the program below works properly. It is your choice whether the arguments of
swapPointers are passed by value or by reference.
P a g e | 2
int main()
{
double a = 77.7;
double b = 25.3;
double* p = &a;
double* q = &b;
cout << "content of p: " << p << endl;
cout << "content of q: " << q << endl;
swapPointers( , );
cout << "content of p: " << p << endl;
cout << "content of q: " << q << endl;
return 0;
}
Output:
content of p: 0xff969b08
content of q: 0xff969b00
content of p: 0xff969b00
content of q: 0xff969b08
What to hand in
Submit your project electronically through Angel. Please hand in the following:
C++ source file (.cpp file) that you implemented for Questions 1, 2, 3, 4
Please follow the documentation rules (adding comments) that are described on the syllabus