True or false 1. A variable of type char can hold the value 301. 2. In an assignment statement, the...

Preview:

Citation preview

True or false 1. A variable of type char can hold the value

301.

2. In an assignment statement, the value on the

left of the equal sign is always equal to the

value on the right.

3. It’s perfectly all right to use variables of

different data types in the same arithmetic

expression.

4. The increment expression in a for loop can

decrement the loop variable

5. - Relational operators have a higher

precedence than arithmetic operators.

( F )

( F )

( T )

( T )

( F )

True or false 6. A structure and enumerator use similar

syntax.

7. A structure definition creates space in

memory for a variable.

8. You can assign one structure variable to

another, provided they are of the same type.

9. In C++ count and COUNT are two different

identifiers.

10. In C++ each statement must end with

semicolon

( F )

( F )

( T )

( T )

( T )

Complete

1. A function name must be followed by

________.

2. A function body is delimited by ________

3. A C++ instruction that tells the computer to

do something is called a ________.

4. The header file that must be included with

your program when using setw is ________

5. The expression 11%3 evaluates to ________.

( )

{ }

statement

2

iomanip

6. The increment operator increases the value of a

variable by ________.

7. Let var1=20 the output of the statement “cout <<

var1--;” will be ________ and the output of the

statement “cout << ++var1;” will be ________.

8. An else always matches the _________ “ if ”, unless the

“ if ” is _________.

9. Executing the continue operator from within a loop

causes control to go to ________.

Complete

1

20

20

last

Connected with its else

The tope of the loop

10. The closing brace of a structure is followed by a

__________.

11.The first three enumerators of an enum type are

normally represented by the values _________,

_________, and _________.

Complete

;

Choose the correct answer

1. Dividing a program into functions

a. is the key to object-oriented programming.

b. may reduce the size of the program.

c. makes the program run faster.

d. all of the above

2- An expression

a. usually evaluates to a numerical value.

b. indicates the emotional state of the program.

c. always occurs outside a function.

d. cannot be part of a statement.

3- The statements that display on the screen the character ‘x’ is

a. cout<<x; b. cout<<’x’; c. cout>>”x”; d. cout<<’x’

4- A relational operator

a. assigns one operand to another.

b. yields a Boolean result.

c. logically combines two operands.

d. none of the above.

Choose the correct answer

Choose the correct answer

5- A variable defined within a block is visible

a. from the point of definition onward in the program.

b. from the point of definition onward in the function.

c. from the point of definition onward in the block.

d. throughout the function.

6- The library function exit() causes an exit from

a. the loop in which it occurs.

b. the block in which it occurs.

c. the function in which it occurs.

d. the program in which it occurs.

Choose the correct answer

7- The && and || operators

a. compare two numeric values.

b. combine two numeric values.

c. compare two Boolean values.

d. combine two Boolean values.

8- The break statement causes an exit

a. only from the innermost loop.

b. only from the innermost switch.

c. from all loops and switches.

d. from the innermost loop or switch.

Choose the correct answer

9- A structure brings together a group of

a. items of the same data type and variables.

b. related data items.

c. integers with user-defined names.

d. all of the above.

10- When accessing a structure member, the identifier to

the left of the dot operator is the name of

a. a structure member.

b. a structure tag.

c. a structure variable.

d. the keyword struct.

Write a program

1- Write a program that generates the following output:102019Use an integer constant for the 10, an arithmetic assignment operator to generate the 20, and a decrement operator to generate the 19.

#include <iostream>using namespace std;int main(){int var = 10;cout << var << endl; // var is 10var *= 2; // var becomes 20cout << var- - << endl; // displays var, then decrements itcout << var << endl; // var is 19return 0;}

2- Write a for loop that displays the numbers from 100 to 110.

3 -Create a calculator program that contains four-function. The program should ask the user to enter a number, an operator, and another number. (Use floating point.) It should then carry out the specified arithmetical operation: adding, subtracting, multiplying, or dividing the two entered numbers. Use a switch statement to select the operation. Finally, display the result.When it finishes the calculation, the program should ask whether the user wants to do another calculation. The response can be ‘y’ or ‘n’. If the response ‘n’ the program will terminate otherwise the program will repeat itself.

#include <iostream>using namespace std;int main(){double n1, n2, ans;char oper, ch;do {cout << “\nEnter first number, operator, second number: “;cin >> n1 >> oper >> n2;switch(oper){case ‘+’: ans = n1 + n2; break;case ‘-’: ans = n1 - n2; break;case ‘*’: ans = n1 * n2; break;case ‘/’: ans = n1 / n2; break;default: ans = 0;}cout << “Answer = “ << ans;cout << “\nDo another (Enter ‘y’ or ‘n’)? “;cin >> ch;} while( ch != ‘n’ );return 0;}

4- Write a structure specification that includes three variables—all of type int—called hrs,

mins, and secs. Call this structure time.

Recommended