1336 Final Review

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Reference variables are defined like regular variables, except there is a(n) ________ in front of the name

&

Write the output for this code: #include <iostream> using namespace std ; int main () { long x, y, z; x = y = z = 4 ; x += 2 ; y -= 1 ; z ·*= 3 ; cout << x << " " << y << " " << z << endl ; return 0;

6 3 12

What value will be stored in the variable t after each of the following statements executes? A) t = (12 > 1); B) t = (5 == (3 * 2)); C) t = (5 == 5);

A) 1 B) 0 C) 1

What will the following segment of code output if the value 11 is entered at the keyboard? int number; cin >> number; if (number > 0) cout << "C++"; else cout << "Soccer"; cout << " is "; cout << "fun" << endl; A) C++ is fun B) Soccer is fun C) C++ D) C++fun

A) C++ is fun

What does this statement do? cout << 15 % 2.0 ; A) Error B) print 1 C) print 1.0 D) print 0.3 E) None of these

A) Error (Modulus requires both operands to be integers )

These are data items whose values do not change while the program is running. A) Literals B) Variables C) Comments D) Integers E) None of the above

A) Literals

What happens with this code after the user types 40 then Enter, then Enter? #include <iostream> using namespace std; int main() { int w; cout << "Enter room's width: "; cin >> w; cout << Room's width is << w << ", "; cout << "Hit enter to countinue:" cin >> w; cout << "Exiting program" << endl; return 0 } A) Prints "Room's width is 40, Hit enter to continue: " - cin ignores enter B) Error C) Prints "Room's width is 40, Hit enter to continue: ", then prints "Exiting program" without a pause D) None of these

A) Prints "Room's width is 40, Hit enter to continue: " - cin ignores enter

The purpose of a memory address is: A) To identify the location of a byte in memory B) To prevent multitasking C) To obtain an algorithm D) To improve the effectiveness of high-level languages E) None of the above

A) To identify the location of a byte in memory

A function ________ contains the statements that make up the function. * A) definition B) prototype C) call D) parameter list

A) definition

Which statement is equivalent to the following? number /= 2; A) number = number / 2; B) number / 2; C) number = 2; D) None of these

A) number = number / 2;

What does this code do? char num = '8'; cout << num; A) prints 8 - The ASCII code of the character '8' is stored in memory. When cout is executed, the ASCII code is translated into its corresponding character because num is a char B) prints ASCII code of character '8' C) prints '8' D) none of these

A) prints 8 - The ASCII code of the character '8' is stored in memory. When cout is executed, the ASCII code is translated into its corresponding character because num is a char

What is the difference between an argument and a parameter variable?

An argument is a value passed to a function. A parameter variable is a variable local to the function which receives the argument. The argument's value is copied into the parameter variable

What is the value stored at x, given the statements: int x; x = 3 / static_cast(4.5 + 6.4); A) .3 B) 0 C) 0.275229 D) 3.3

B) 0

In the following C++ statement, what operator will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2 ; A) 6 - 3 B) 3 * 2 C) 2 + 7 D) 10/2

B) 3 * 2

What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0; A) 2.0 B) 4.0 C) 1.5 D) 6.0

B) 4.0

What does this code print? cout << 15/2; A) 7.5 B) 7 C) It depends D) None of these

B) 7

What is printed by this code? #include <iostream> using namespace std; int main() { int myInt1 = 1, myInt2 = 8; myInt2 = myInt1 = 7; cout << myInt2; return 0; } A) Nothing is printed, error B) 7 C) 8

B) 7

Which of the following are not valid assignment statements? A) total = 9 B) 72 = amount C) profit = 129 D) letter = 'W'

B) 72 = amount and C) profit = 129

Assume a program has the following variable definitions: int a, b = 2; float c = 4. 2; and the following statement: a = b • c; What value will be stored in a? A) 8.4 B) 8 C) 0 D) None of the above

B) 8

What is the value of myDouble after line 7 is executed? 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int myInt; 6 double myDouble; 7 myDouble = myInt = 17/2; 8 return 0; 9 } A) Nothing is executed, error B) 8.0 C) 8.5

B) 8.0

A set of well-defined steps for performing a task or solving a problem is known as a(n): A) Hierarchy B) Algorithm C) Central Processing Unit D) Encoded instruction E) None of the above

B) Algorithm

Which of the following best describes an operator? A) An operator is a rule that must be followed when constructing a program. B) An operator allows you to perform operations on one or more pieces of data. C) An operator marks the beginning or ending of a statement, or is used to separate items in a list. D) An operator is a word that has a special meaning. E) An operator is a symbolic name that refers to a variable.

B) An operator allows you to perform operations on one or more pieces of data.

Words that have a special meaning and may be used only for their intended purpose are known as: A) Programmer Defined Words B) Key Words C) Syntax D) None of the above

B) Key Words

What happens with this program? #include <iostream> using namespace std; int main() { int d = 1, e = 34; if (d < e) { int d = 10; cout << d << '*'; } cout << d << '*'; return 0; } A) Print 1*1* B) Print 10*1* C) Error D) None of these

B) Print 10*1*

In a C++ program, two slash marks ( // ) indicate: A) The end of a statement B) The beginning of a comment C) The end of the program D) The beginning of a block of code E) None of the above

B) The beginning of a comment

What will the following code display? int number = 7; cout << "The number is " << "number" ; A) The number is 7 B) The number is number C) The number is7 D) The number is 0

B) The number is number

Programmer-defined names of memory locations that may hold data are: A) Operators B) Variables C) Syntax D) Operands E) None of the above

B) Variables

Of the following, which is not a valid C++ identifier? A) June1997 B) _employee_number$ C) ___department D) _XXXXXX E) All of the above are valid identifiers.

B) _employee_number$

What will the following code segment output after the user enters 0 at the keyboard? int x = -1; cout << "Enter a 0 or a 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl; A) No output, error B) false C) x D) true

B) false

Assume input value is valid if and only if it is between 0 and 100 inclusive. Which of the following code correctly determines the input is invalid and print an error message? A) if (input < 0 && input > 100) cout << "Invalid input"; B) if (!(input >= 0 && input <= 100)) cout << "Invalid input"; C) if (input >= 0 || input <= 100) cout << "Invalid input"; D) None of these

B) if (!(input >= 0 && input <= 100)) cout << "Invalid input";

The following data are all examples of 72 'A' "Hello World " 2.8712 A) variables B) literals or constants C) strings D) None of the above

B) literals or constants

Assume that a program has the following C++ string class definition: string name; Which of the following statements correctly assigns a string literal to the string? A) name = Jane; B) name = "Jane"; C) name = 'Jane'; D) name = (Jane);

B) name = "Jane";

What does this code do? int num = '8'; cout << num; A) prints 8 B) prints ASCII code of character '8' - The ASCII code of the character '8' is stored in memory. When cout is executed, the ASCII code is read as a number because num is an int C) prints '8' D) none of these

B) prints ASCII code of character '8' - The ASCII code of the character '8' is stored in memory. When cout is executed, the ASCII code is read as a number because num is an int

A function ________ eliminates the need to place a function definition before all calls to the function. A) header B) prototype C) argument D) parameter

B) prototype

When a relational expression is false, it has the value ________. A) one B) zero C) Not a number D) None of these

B) zero

What is output by the following code segment? int num = 4; int total = 0; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout << total << endl; A) 0 B) 3 C) 13 D) 28

C) 13 (break is left out, so program falls through the remaining statements of the switch)

Assuming you are using a system with 1-byte characters, how many bytes of memory will the following C- string occupy? "William" A) 7 B) 14 C) 8 D) 1

C) 8 (A C-string is always ends with a null terminator)

Data types that can hold numbers with a fractional part are A) Integer data types B) Real data types C) Floating point data types D) Long data types E) None of the above

C) Floating point data types

A(n) ________ is a set of instructions that the computer follows to solve a problem. A) Compiler B) Linker C) Program D) Operator E) None of the above

C) Program

The statements written by the programmer are called: A) Syntax B) Object code C) Source code D) Runtime libraries E) None of the above

C) Source code

Relational operators allow you to ________ numbers. A) add B) multiply C) compare D) None of these

C) compare

Which statement will read an entire line of input into the following string object? string address; A) cin << address; B) getline(address); C) getline(cin, address); D) cin.get(address);

C) getline(cin, address);

This stream manipulator causes the field to be left-justified with padding spaces printed to the right. A) left_justify B) left_pad C) left D) None of these

C) left

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) named constant

What happens with this code? #include <iostream> using namespace std; int main() { int myNum; double myDouble = 5.6; myNum = myDouble; cout << myNum; return 0; } A) Error B) print 5.6 C) print 5 D) print 5.0

C) print 5

A variable's ________ is the part of the program where you can use the variable. A) data type B) value C) scope D) reach E) None of the above

C) scope

What is assigned to the variable a in the statement below if x = 10, y = 7, and z, a, and b are all int variables. a = x >= y; A) 10 B) 7 C) The string "x >= y" D) 1

D) 1 (the relational operator has higher precedence than the assignment)

This operator is used in C++ to represent equality. A) = B) >< C) !! D) ==

D) ==

An Integrated Development Environment (IDE) typically allows one to: A) Write a program B) Compile a program C) Debug a program D) All of the above E) None of the above

D) All of the above

What happens with this code? #include <iostream> using namespace std; int main() { cout << 10 + 5*'a'; return 0; } A) Error B) Prints 10aaaaa C) Prints 10+aaaaa D) None of these

D) None of these - According to the type coercion rules, the char 'a' is automatically converted to an int, whose value is the ASCII code of 'a'

What is the output of the following code segment? int x = 5; if (x = 2) cout << "This is true!" << endl; else cout << "This is false!" << endl; cout << "This is all!" << endl; A) This is true! B) This is false! This is all! C) This is true! This is false! D) This is true! This is all!

D) This is true! This is all! (Do not rely on the indentations)

What happens with this program? #include <iostream> using namespace std; int main() { int num = 2, i = 1, j = 2, k = 3; switch (num) { case i: cout << "Hello"; case j: cout << "Hi"; case k: cout << "Bye"; } return 0; } A) outputs Hello B) outputs Hi C) outputs HelloHiBye D) error

D) error - Reason: variables cannot be used after "case"

Either a function's __________ or its ________ must precede all calls to the function.

Definition or prototype

This operator in C++ allows you to identify how many bytes of storage on your computer system an integer data value requires. A) len B) bytes C) f(x) D) int E) sizeof

E) sizeof

After these statements are executed, the value of t is 5 int t; t = 5 > 11; (T/F)

False

Function headers are terminated with a semicolon (T/F)

False

In a function prototype, the names of the parameter variables may be left out (T/F)

False

It is not possible for a function to have some parameters with default arguments and some without (T/F)

False

The = operator and the == operator perform the same operation when used in a Boolean expression (T/F)

False

The exit function can only be called from main (T/F)

False

The if statement regards an expression with the value 0 as ___________.

False

x below is equal to 2.5 double x; x = static_cast(5/2); (T/F)

False

When a function terminates, it always branches back to main, regardless of where it was called from (T/F)

False - Since any function can call another function, the called function will branch back to the calling function, which is not necessarily the main function

The value of a relational expression is 0 if the expression is __________ or 1 is the expression is _________.

False, True

If you are writing a function that accepts an argument and you want to make sure the function cannot change the value of the argument, what do you do?

If the argument is passed by value, nothing needs to be done, the function cannot access the argument. If the argument is passed by reference, the parameter should be defined with the const key word

The expression that is tested by a switch statement must have a(n) _________ value.

Integer

The expression following a case statement must be a(n) ________ ________.

Integer Constant

How would a static local variable be useful?

It would enable a function to retain a value between function calls. For example, it can keep track of the number of times the function has been called

Where do you define parameter variables?

Parameters are defined inside the parens of a function header (parameter list)

Give an example where passing an argument by reference would be useful

Refer to the Exo with the convert coordinates

An expression using the greater-than, less-than, greater-than-or-equal-to, less-than-or-equal-to, equal-to, or not-equal-to is called a(n) __________ expression.

Relational

Why do local variables lose their values between calls to the function in which they are defined?

They lose their values because they are destroyed when the function ends

A stub is a dummy function that is called instead of the actual function it represents (T/F)

True

If other functions are defined before main, the program still starts executing at function main (T/F)

True

Initialization of static local variables only happens once, regardless of how many times the function in which they are defined is called (T/F)

True

The if statement regards an expression with a nonzero value as ________.

True

The scope of a parameter is limited to the function that uses it (T/F)

True

When a function with default arguments is called and an argument is left out, all arguments that come after it must be left out as well (T/F)

True

When typing in your source code into the computer, you must be very careful since C++ is case sensitive. (T/F)

True

A relational expression is either _________ or __________.

True, False

In an if/else statement, the if part executes its statement or block if the expression is ___________, and the else part executes its statement or block if the expression is __________.

True, False

If a function doesn't return a value, the word _______ will appear as its return type.

Void

How do you return a value from a function?

With the return statement

Can an if statement test expressions other than relational expressions?

Yes. The if statement can test any value that yields a Boolean value (true or false) or a numeric value. When testing a numeric expression, a nonzero numeric value is considered true, and the value 0 is considered false

For an if statement to conditionally execute a group of statements, the statements must be enclosed in a set of ___________.

braces (block of code)

A program will "fall through" a case section if it is missing the __________ statement.

break

What happens with this code after the user types 40 then Enter? #include <iostream> using namespace std; int main() { int w; cout << "Enter room's width: "; cin >> w; cout << Room's width is << w << ", "; cout << "Hit enter to countinue:" cin.get(); cout << "Exiting program" << endl; return 0 } A) Prints "Room's width is 40, Hit any key to continue:", then pauses B) Error C) Prints "Room's width is 40, Hit any key to continue:", then prints "Exiting program" without a pause D) None of these

c) Prints "Room's width is 40, Hit any key to continue:", then prints "Exiting program" without a pause (cin.get reads the left over newline from the previous cin)

The value of a default argument must be a(n) _________

constant

___________ arguments are passed to parameters automatically if no argument is provided in the function call

default

Write a multiple assignment statement that can be used instead of the following group of assignment statements: east = 1 ; west = 1 ; north = 1 ; south = 1 ;

east = west = north = south = 1

_________ variables are defined outside all functions and are accessible to any function within their scope

global

When a function uses a mixture of parameters with and without default arguments, the parameters with default arguments must be defined __________

last

A(n) _______ variable is defined inside a function and is not accessible outside the function

local

If a function has a local variable with the same name as a global variable, only the ________ variable can be seen by the function

local

When used as parameters, ________ variables allow a function to access the parameters original argument

reference

The _______ statement causes a function to end immediately

return

_________ local variables retain their value between function calls

static

Assume qty and salesReps are both integers. Use a type cast expression to rewrite the following statement so it will no longer perform integer division. unitsEach = qty / salesReps;

unitsEach = static_cast(qty) / salesRep;

When only a copy of an argument is passed to a function, it is said to be passed by ________

value

Unless you explicitly initialize global variables, they are automatically initialized to _________

zero


संबंधित स्टडी सेट्स

Chapter 5: Intra-Entity Assets Transactions (Equity Method)

View Set

Abeka themes in literature appendix quiz d

View Set

Chapter 35: Key Pediatric Nursing Interventions

View Set

Government unit 4 quiz 3: Voting

View Set

Lecture 14: Adrenal Medulla Hormones

View Set

2-4 New Netherlands and Pennsylvania

View Set

Thyroid Anatomy, Physiology and Embryology of the Thyroid Gland.

View Set

Chapter 1 - The Basics of Nutrition

View Set

Psychology : 5. ABNORMAL AND GROUP BEHAVIOR

View Set

Concepts of Emergency and Disaster Preparedness Key Points Ch. 10 Iggy Book

View Set

AZ Microsoft Word LinkedIn Skill Assessment

View Set