CH2

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

7. Modify the following program so it prints two blank lines between each line of text. #include <iostream> using namespace std; int main() { cout << "Two mandolins like creatures in the"; cout << "dark"; cout << "Creating the agony of ecstasy."; cout << " - George Barker"; return 0; }

#include <iostream> int main() { cout << "Two mandolins like creatures in the\n\n\n"; cout << "dark\n\n\n"; cout << "Creating the agony of ecstasy.\n\n\n"; cout << " - George Barker\n\n\n"; return 0; }

Identify the escape sequences: \n \t \a \b \r \\ \' \"

\n Newline Causes the cursor to go to the next line for subsequent printing. \t Horizontal tab C auses the cursor to skip over to the next tab stop. \a Alarm Causes the computer to beep. \b Backspace Causes the cursor to back up, or move left one position. \r Return Causes the cursor to go to the beginning of the current line, not the next line. \\ Backslash Causes a backslash to be printed. \' Single quote C auses a single quotation mark to be printed. \" Double quote

Compilation errors resulting from illegal uses of key words, operators, punctuation, and other language elements

Syntax error

24. T F Variable names may be up to 31 characters long.

TRUE

25. T F A left brace in a C++ program should always be followed by a right brace later in the program.

TRUE

Which escape sequence cause a "backslash" to be printed?

\\ NOTE: to have this appear: /\/\ win /\/\ you need to input: "/\\/\\ win /\\/\\

Uses true or false values

bool

Can go further beyond the decimal point than float, 8 bytes, approx. 15 digits. Very precise # w/ fractional component.

double

2. How may the double variables temp, weight, and age be defined in one statement?

double temp, weight, age;

A number that can have a decimal. Single precision, 4 bytes and numbers between ±3.4E-38 and ±3.4E38. approx. 7 digits. What other data type does this data type associate with?

float double

What is the % symbol called? What are the result of the follow statements: 28 % 5 = 31 % 10 = 40 % 2 = 20 % 30 =

modulus Ex: 28 % 5 = 5 * 5 = 25 => 28 - 25 =3. therefore the remainder is 3. 3 1 0 20

12. Preprocessor directives begin with a A) # B) ! C) < D) * E) None of the above

#

5. Is the following comment written using single-line or multi-line comment symbols? /* This program was written by M. A. Codewriter*/

Multi-line comment

The program crashes...Ex: an operation attempted to divide by zero.

Runtime error

A whole number, can be signed or unsigned and associates with long

int

Associated with char, except it's composed of more than one char and uses " ".

string

The code compiles fine and runs, but the output is flawed

Logic error

22. T F A variable must be defined before it can be used.

TRUE

Identify two ways to input comments into a program.

// single_line comments /* multi_line comments */

1. How many operands does each of the following types of operators require? _______ Unary _______ Binary _______ Ternary

1 2 3

14. A group of statements, such as the contents of a function, is enclosed in A) Braces {} B) Parentheses () C) Brackets <> D) All of the above will do

A) Braces {} Note: ( ) are used in naming a function, as in int main()

4. Write assignment statements that perform the following operations with the variables a, b, and c. A) Adds 2 to a and stores the result in b . B) Multiplies b times 4 and stores the result in a . C) Divides a by 3.14 and stores the result in b . D) Subtracts 8 from b and stores the result in a . E) Stores the value 27 in a. F) Stores the character 'K' in c . G) Stores the ASCII code for 'B' in c .

A) b = a + 2; B) a = b * 4; C) b = a / 3.14; D) a = b - 8; E) a = 27; F) c = 'K'; G) c = 'B'

15. Which of the following are not valid assignment statements? (Circle all that apply.) A) total = 9; B) 72 = amount; C) profit = 129 D) letter = 'W';

B, C

6. Is the following comment written using single-line or multi-line comment symbols? // This program was written by M. A. Codewriter

Single_line

9. Every complete statement ends with a A) period B) # symbol C) semicolon D) ending brace

C

10. Which of the following statements is correct? A) #include (iostream) B) #include {iostream} C) #include <iostream> D) #include [iostream] E) All of the above

C) <iostream>

16. Which of the following are not valid cout statements? (Circle all that apply.) A) cout << "Hello World"; B) cout << "Have a nice day"; C) cout < value; D) cout << Programming is great fun;

C, D

Name the 7 data types in their respective order

int long float double char string bool

3. How may the int variables months, days, and years be defined in one statement, with months initialized to 2 and years initialized to 3?

int months = 2, days, years = 3;

There are a number of syntax errors in the following program. Locate as many as you can. */ What's wrong with this program? /* #include iostream using namespace std; int main(); } int a, b, c \\ Three integers a = 3 b = 4 c = a + b Cout < "The value of c is %d" < C; return 0; {

1) The multi-line comment: correct config is /* and */. 2) <iostream> missing less than/greater than symbols. 3) No comma after int main(). 4) The braces at the beginning and end of the function are reversed. 5) int a, b, c; is missing the semi-colon. 6) The single-line // are the wrong direction. 7) The three variable definitions require semi-colons or at least commas after a = 3, b = 4, and then a semi-colon after c = a+ b; 8) cout needs to be lower case. 9) need two less than and two greater than symbols.

Show the punctuation for: x = 3, Display results for 3 as an int, char, and string.

3 '3' "3"

17. Assume w = 5, x = 4, y = 8, and z = 2. What value will be stored in result in each of the following statements? A) result = x + y; B) result = z * 2; C) result = y / x; D) result = y − z; E) result = w % 2;

A) 12 B) 4 C) 2 D) 6 E) 1

18. How would each of the following numbers be represented in E notation? A) 3.287 × 10 6 B) −978.65 × 10 12 C) 7.65491 × 10 −3 D) −58710.23 × 10 −4

A) 3.287E6 B) -9.7865E14 C) 7.65491E-3 D) -5.871023E0

19. The negation operator is A) Unary B) Binary C) Ternary D) None of the above

A

21. When do preprocessor directives execute? A) Before the compiler compiles your program B) After the compiler compiles your program C) At the same time as the compiler compiles your program D) None of the above

A

8. What will the following programs print on the screen? A) #include <iostream> using namespace std; int main() { int freeze = 32, boil = 212; freeze = 0; boil = 100; cout << freeze << endl << boil << endl; return 0; } B) #include <iostream> using namespace std; int main() { int x = 0, y = 2; x = y * 4; cout << x << endl << y << endl; return 0; } C) #include <iostream> using namespace std; int main() { cout << "I am the incredible"; cout << "computing machine"; cout << " and I will amaze "; cout << "you."; return 0; } D) #include <iostream> using namespace std; int main() { cout << "Be careful "; cout << "This might/n be a trick "; cout << "question "; return 0; } E) #include <iostream> using namespace std; int main() { int a, x = 23; a = x % 2; cout << x << endl << a << endl; return 0; }

A) 0, 100 B) 8, 2 C) : I am the incrediblecomputing machine and I will amaze you. D): Be careful This might/n be a trick question E) 23, 1

11. Every C++ program must have a A) cout statement B) function main C) #include statement D) All of the above

B

13. The following data 72 'A' "Hello World" 2.8712 are all examples of A) Variables B) Literals or constants C) Strings D) None of the above

B

20. A(n) ___________ is like a variable, but its value is read-only and cannot be changed during the program's execution. A) secure variable B) uninitialized variable C) named constant D) locked variable

C

23. T F Variable names may begin with a number.

FALSE

26. T F You cannot initialize a named constant that is declared with the const modifier.

FALSE

A name you give a variable

Identifier


Set pelajaran terkait

好词好句 (4) good sentences for emotion

View Set

CHAPTER 63 - Management of Patients with Neurologic Trauma

View Set

Research in Health Science set I

View Set

Biology Exam 2 Practice Questions

View Set

Chapter 15: Mental and Behavioral Health

View Set

Principles of Microeconomics Exam 1 (Chap. 1-4) study guide

View Set