Presentation is loading. Please wait.

Presentation is loading. Please wait.

True or false A variable of type char can hold the value 301. ( F )

Similar presentations


Presentation on theme: "True or false A variable of type char can hold the value 301. ( F )"— Presentation transcript:

1 True or false A variable of type char can hold the value 301. ( F )
In an assignment statement, the value on the left of the equal sign is always equal to the value on the right. It’s perfectly all right to use variables of different data types in the same arithmetic expression. The increment expression in a for loop can decrement the loop variable - Relational operators have a higher precedence than arithmetic operators. ( F ) ( F ) ( T ) ( T ) ( F )

2 True or false A structure and enumerator use similar syntax.
A structure definition creates space in memory for a variable. You can assign one structure variable to another, provided they are of the same type. In C++ count and COUNT are two different identifiers. In C++ each statement must end with semicolon ( F ) ( F ) ( T ) ( T ) ( T )

3 Complete A function name must be followed by ________. ( )
A function body is delimited by ________ A C++ instruction that tells the computer to do something is called a ________. The header file that must be included with your program when using setw is ________ The expression 11%3 evaluates to ________. ( ) { } statement iomanip 2

4 Complete The increment operator increases the value of a variable by ________. Let var1=20 the output of the statement “cout << var1--;” will be ________ and the output of the statement “cout << ++var1;” will be ________. An else always matches the _________ “ if ”, unless the “ if ” is _________. Executing the continue operator from within a loop causes control to go to ________. 1 20 20 last Connected with its else The tope of the loop

5 Complete The closing brace of a structure is followed by a __________.
The first three enumerators of an enum type are normally represented by the values _________, _________, and _________. ;

6 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.

7 Choose the correct answer
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.

8 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.

9 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.

10 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.

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

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

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

14 3 -Create a calculator program that contains four-function
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.

15 #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;

16 mins, and secs. Call this structure time.
4- Write a structure specification that includes three variables—all of type int—called hrs, mins, and secs. Call this structure time.

17

18

19

20

21

22


Download ppt "True or false A variable of type char can hold the value 301. ( F )"

Similar presentations


Ads by Google