## Description

Module 3 Checkpoint Exercise

Instructions:

For checkpoint 3.1 – 3.5, please type your answer right after the question in this Word document and submit the file on Moodle. For checkpoint 3.6 – 3.9, please complete them on the corresponding activities on Moodle.

Checkpoint 3.1

What is the screen output when each of the following C++ statements is performed? Assume x = 4 and y = 6. You should write “no screen output” if no output is displayed for the statement.

a) cout << y; Ans: 6

b) cout << x – y; Ans: -2

c) cout << “y”; Ans: y

d) cout << “x = ” << x; Ans: x = 4

e) cout << x * y << ” = ” << y * x; Ans: 24 = 24

f) p = x – y Ans: no screen output

g) // cout << “x – y = ” << x – y; Ans: no screen output

Checkpoint 3.2

Given the algebraic equation 𝑦 = 𝑎𝑥3 − 12, which of the following are correct statements for this equation? a) y = a * x * x * x -12;

b) y = a * x * (x – 12);

c) y = a * (x * x) * (x -12);

d) y = a * x * (x * x) – 12;

e) y = a * ( x * x * x ) -12;

Ans: (a), (d), (e) are correct for this question

Checkpoint 3.3

What is the value of x after each statement is performed?

a) x = 6 + 3 * 7 / 1 – 2; Ans: 25

b) x = 3 % 3 + 3 * 2 – 2 / 2; Ans: 5

Checkpoint 3.4

If x = 5, y = 6, z = 7, evaluate each of the following statements, if possible. If it is not possible, state the reason. a) (x + z) % y Ans: 0

b) (x % y) % z Ans: 5

c) (x * z) % y Ans: 5

Checkpoint 3.5

What is printed by the following program? Suppose the input is: 20 25

#include <iostream> const int NUM = 10; const double X = 20.5; int main()

{ int a, b; double p; char grade; a = 23; cout << “a = ” << a << endl; cout << “Enter two integers: “; cin >> a >> b; cout << endl; cout << “The numbers you entered are ” << a << ” and ” << b << endl; p = X + 2 * a – b; cout << “p = ” << p << endl; grade = ‘B’;

cout << “Your grade is ” << grade << endl; a = 2 * NUM + p;

cout << “The value of a = ” << a << endl; return 0;

}

Ans: a = 23

Enter two integers: 20 25

The numbers you entered are 20 and 25 p = 35.5

Your grade is B

The value of a = 55

The following is printed out on the screen in sequential order:

– The current value of a (which is 23 followed by a newline)

– The statement “Enter two integers”

– A new line after you input the two numbers

– The numbers you input as a and b with the statement “The numbers you entered are 20 and 25” followed by a newline

-The value of p as calculated according to the formula p = 35.5 (and a newline)

-The statement “Your grade is B” (and a newline)

-The updated value of a according to the formula a = 55

Checkpoint 3.6 – 3.9

Refer to corresponding Moodle activities for details.

## Reviews

There are no reviews yet.