Exam 2 Ch 4,5,&6 COSC (1436)

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of the following is evaluated first, given the expression: A && B I I C && !D

!D

To allow file access in a program, you must use ________ in the header file.

#include fstream

What is the output of the following segment of code if the value 4 is input by the user? int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 0: total = total + 6; default: total = total + 4; } cout << total << end1;

13

After the following code executes, what is the value of my_value if the user enters 0? cin >> my value; if (my_ value > 5) my_ value = my_value + 5; else if (my_value > 2) my_value = my_value +10; else my_value = my_value + 15;

15

Given the following function: void calc (int a, int&b) { int c; c = a + 2; a = a + 3; b + c +a; } etc...

163

How many times will the followinf loop display "Looping!"? for (int i = 20; i > 0; i--) cout << "Looping!" << end1;

20

What will the following code display? #include <iostream> using namespace std; void doSomething(int&); int main() { int x = 2; cout << x << end1; doSomething (x); cout << x << end1; } ect...

200

How many times will the following loop display "Looping again!"? for (int i = 0; i <= 20; i++) cout << "looping again!" << end1;

21

What will the following code display? Int x = 0; for (int count = 0; count < 3; count++) X += count; Cout << x << endl;

3

What will the following code display? Int number = 6; Int x = 0; X = number--; Cout << x << endl;

6

What will the following code display? #include <iostream> using namesoace std; int getValue(int) int main() { int x = 2; cout << getValue (x) << end1; } etc...

7

Which value can be entered to cause the following code segment to display the message "That number is acceptable." Int number; Cin >> number; If (number > 10 && number < 100) Cout << " That number is acceptable. \n"; Else Cout << "That number is not acceptable. \n";

99

The _______ is an equality operator

==

The two important parts of a while loop are the expression that is tested for a true or false value and

A statement or block that is required as long as the expression is true.

Input values should always be checked for:

Appropriate range, reasonableness, division by 0. All of the above

A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function.

Argument, parameter

A statement that causes a loop to terminate early is

Break

It is good programming practice to ________ your functions by writing comments that describe what they do.

Document

EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit() function is called.

EXIT_SUCCESS

A function's return data type must be the same as the function's parameters.

False

After the following code excutes, what is the output if user enters 0? int x = -1; cout << "Enter a 0 or 1; "; cin >> x; if (c( cout << "true" << end1; elase cout << "false" << end1;

False

The condition that is tested by a while loop must be enclosed in parentheses and terminated with a semicolon.

False

The conditional operator takes two operands (T/F).

False

The default section is required in a switch statement (T/F)?

False

The following code correctly determines whether x contains a value in the range of 0 through 100, inclusive (T/F). if (x > 0 && <= 100)

False

The increment and decrement operators can be used in mathematical expressions; however, they cannot be used in relational expressions.

False

You may nest while and do-while loops but you may not nest for loops.

False

You must always furnish an argument with a function call.

False

A variable, usually a bool or an int, that signals when a condition exists is known as a(n)

Flag

The ________ loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.

For

What is the output of the following code segment if the user enters 23? int number; cout << "Enter a number; "; cin >> number; if (number > 0) cout << "Hi, there!" << end1; else cout << "Good-bye," << end1

Hi, there!

This operator represents the logical OR:

I I

This means to increase a value

Increment

In a for statement, this expression is executed only once:

Initialization

Which line in the following program will cause a compiler error? #include <iostream> using namesppace std; int main () { int number = 5 if (number >= 0 && <= 100) cout << "passed. /n"; return 0; }

Line 6

A loop that is inside another loo[ is called a(n)

Nested loop

A file must be ________ before data can be written to or read from it.

Opened

When the increment operator precedes its operand, as ++num, the expression is in ________ mode.

Prefix

This operator increments the value of its operand and then uses the value in context.

Prefix increment

A function ________ eliminates the need to place a function definition before all calls to the function.

Prototype

This statement uses the value of a variable or expression to determine where the program will branch to.

Switch

A parameter is a special purpose variable that is declared inside the parentheses of a function definition.

True

A static variable that is defined within a function is initialized only once, the first time it is called.

True

An expression that has any value other than 0 is considered true by an if statement (T/F).

True

An output file is a file that data is written to.

True

As a rule of style, when writing an if statement you should indent the conditionally- executed statements (T/F).

True

Both of the following if statement perform the same operation. 1. if (sales > 10000) commissionRate = 0.15; 2. if (sales > 10000) commissionRate = 0.15; (T/F)

True

Global variables are initialized to zero by default.

True

If the expression on the left side of the following is false, the expression on the right side will not be checked (T/F). (a > = b) && (c == d)

True

It is not considered good programming practice to declare all your variables globally.

True

The update expression of a for loop can contain more than one statement, for example:for(i = 5; i <= 10; i++, total+= sales)

True

You may use the exit() function to terminate a program, regardless of which control mechanism is executing.

True

string objects have a member function named c_str that returns the contents of the object formatted as a null-terminated C-string.

True

What is the output of the following code segment if the user enters 90 for the score? cout << "Enter your test score: "; cin >> test_ score; if (test_ score < 60) cout << "You failed the test " << end1; if (test_score > 60) cout << "you passed the test, " else cout << "You need to study harder nect time, " << end1;

You passed the test

Given that x = 2, y = 1, and z = 0, what will the following cout statement display? cout << "answer = " << (x || !y && z) << endl;

answer = 1

Assuming dataFile is a file stream object, the following statement:dataFile.close();

closes a file

If you intend to place a block of statements within an if statement, you must place __________ around the block.

curly braces { }

What is the value of the following expression? true && false

false

A collection of statements that performs a specific task is a(n)

function

If a function does NOT have a prototype, default arguments may be specified in the ________.

function header

To write read data from a file, you define an object of the ________ data type.

ifstream

Something within a while loop must eventually cause the condition to become false or a(n) ________ results.

infinite loop

When a program lets the user know that an invalid choice has been made, this is known as:

input validation

Which line in the following program contains the header for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

line 11

Which line in the following program contains a call to the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

line 7

This type of variable is defined inside a function and is NOT accessible outside the function.

local

If you place a semicolon after the test expression in a while loop, it is assumed to be a(n)

null statement

A function can have no parameters, one parameter, or many parameters and can return ________ value(s).

only one

If a function is called more than once in a program, the values stored in the function's local variables do NOT ________ between function calls.

persist

A while loop is a (n)____ loop.

pre-test

When used as parameters, these types of variables allow a function to access the parameter's original argument:

reference

Given the following code segment, what is the output? int x = 1, y = 1. z = 1; y = y + x; x = x + y cout << "result = " << (x< y ? y : x) << end1;

result = 3

This statement causes a function to end.

return

The value in this type of variable persists between function calls.

static

This is a dummy function that is called instead of the actual function it represents.

stub


Kaugnay na mga set ng pag-aaral

*Psychology Experience Psychology Ch. 5 and 2 others

View Set

Ch 9 Prep U Questions, Ch. 9, Chapter 9: Teaching and Counseling

View Set

Cellular Respiration/ Fermentation Questions

View Set

What is the fundamental problem in economics?

View Set