MECH 45: MIDTERM 1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

A line comment begins with _________ character(s)

// , two forward slashes

The result of 14 % 2 is ______.

0

What is the output of the following code: int x = 5; int y = 8; if (x != 5) { y = 7; x = x + y; } else { y = 4; x = x - y; } cout << x;

1

What is the output of the following code: int r = 3, s = 2, t = 4; if ((r == 4) || !(s < t)) r = r - 1; else r = r * 2; r = r + t; cout << r;

10

(20.0 - 2.0) / (6.0 + 3.0)

2.0

20.0 - 2.0 / (6.0 + 3.0)

2.0

20 - 2 / 6 + 3

23

3.0 + 4.0 * 6.0

27.0

What is the value of the following arithmetic expression if the variables have these values: p=5, s=20, x=6; Expression: p + 3 * x - s

3

What will the result of the following expression be, if amount = 1; m = 50; n = 10; p = 5? 18 / p

3

What is the value of z after the following code executes: float x, y, z; x =9.0; y = 16.0; z= sqrt ( x + y);

5.0

After executing the following statements, what is the final value of a? a = 2 + 3 * 4;b = 16;if (a < b)a = a / 2;elsea = a * 2;

7

What is the value of p after the following code executes: int p = 3, q = 5; if ((p > q) || (p != 4)) p = p + 1; else p = p - 1; p = p * 2;

8

Which of the following is not a relational operator:

=

The operator used with the cin object is ________.

>>, extraction operator

int main( ) { char marCode; cout << "Enter a marital code: "; cin >> marCode; if (marCode == 'M' || marCode == 'm') cout << "\nIndividual is married."; else if (marCode == 'S' || marCode == 's') cout << "\nIndividual is single."; else if (marCode == 'D' || marCode == 'd') cout << "\nIndividual is divorced."; else if (marCode == 'W' || marCode == 'w') cout << "\nIndividual is widowed."; else cout << "\nAn invalid code was entered."; cout << endl; return 0; } What is printed when value entered is 'A'?

An invalid code was entered.

>> is used for output.

FALSE

A block of C++ statements contains only one terminating semicolon.

FALSE

In C++ addition is always evaluated before subtraction.

FALSE

It is best to use very short identifiers.

FALSE

The computer will carry out the instructions that follow the symbol //

FALSE

The function floor (x) rounds its argument x to the nearest integer.

FALSE

When the ++ operator appears before a variable, it is called a postfix increment operator.

FALSE

"pear" != "pears"

TRUE

A C++ statement cannot extend over more than one line.

TRUE

A condition can be either true or false.

TRUE

A condition is true when it evaluates to an integer value of 1 and false when it evaluates to an integer value of 0.

TRUE

A program must have a main function.

TRUE

An identifier must start with a letter or an underscore.

TRUE

Dividing an integer by another integer always yields an integer result.

TRUE

Every C++ statement within a function body must be terminated by a semicolon.

TRUE

In the statement: cout << "Hello!"; "Hello!" is called a string literal.

TRUE

It is good program style to put spaces between words and symbols.

TRUE

The cin object accepts a stream of data from the standard output device.

TRUE

The statement 2 + 7 = total; is invalid.

TRUE

This is a valid statement: bool maybe = (6 = = 7);

TRUE

The symbols, ++, is known as the ______________ operator.

increment

What is the output of the following code: char ch = 'c'; if (ch > 'g') cout << "high"; else if (ch < 'm') cout << "low"; else cout << "middle";

low

The purpose of the parentheses after a function name is to provide a funnel through which data can be ____.

passed to the function

Which of the following would be the best variable name choice for a pay rate of a student?

payRate

Which of the following are valid function calls to the pow()function?

pow(1.1,3.0);

What will be printed by the following statement if the value of the select is 'Q': switch (select) { case 'Q' : case 'q': cout << "quit "; case 'R': case 'r': cout << "redo "; break; case 'P': case 'p': cout << "play "; default: cout << "other "; }

quit

Rewrite as C++ expression x = (a - b)(a + b)

x=(a-b)*(a+b);

Rewrite as C++ expression y = 3((a - b)(a + b)) - x

y=3*((a-b)*(a+b))-x;


Set pelajaran terkait

Sociology Chapter 15 Communities, the Environment, and Health

View Set

History Alive: Grade 5 - Chapter 13

View Set

Experimental psy chapters 12 and 13

View Set

Child Care With Alteration in Intracranial Regulation/Neurologic Disorder

View Set

U2: La familia (avanzada-advanced)

View Set

Health Promotion and Maintenance 2

View Set

Legal and Ethical Issues -- test bank

View Set

Cardiovascular System: The Heart

View Set