Comp SCI 1250 - Homework and Quizzes - Chapter 4-6

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

This operator takes an operand and reverses its truth or falsehood.

!

This operator represents the logical AND.

&&

When a relational expression is false, it has the value ________.

0

What is assigned to the variable a given the statement below with the following assumptions: x = 10, y = 7, and z, a, and b are all int variables.a = x >= y;

1

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

Brackets{}

Why should a program close a file when it's finished using it?

Closing the file after using it allows fewer machine resources to be used, and allows otherprograms to access and edit the file.

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

Definition, prototype

The scope of a variable declared in a for loop's initialization expression always extends beyond the body of the loop.

False

Describe the difference between pretest loops and posttest loops

Pretest loops will only be iterated as long as their required expression is true, posttestloops will run at least once and then test to see if their expression is true for subsequentiterations.

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?

To prevent the function from editing the argument's value, store the argument as aparameter and perform calculations with the parameter. Make sure the parameter is not inreference mode.

An initialization expression may be omitted from the for loop if no initialization is required.

True

Multiple relational expressions cannot be placed into the test condition of a for loop

True

The update expression of a for loop can contain more than one statement, e.g. counter++, total+= sales.

True

Can an if statement test expressions other than relational expressions? Explain.

Yes, an if statement can test any expression if it can be read as true or false.Question 12:FalseQuestion 14:Brackets {}Question 16:default:Question 28:break statement;Question 30:

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

ampersand(&)

Input values should always be checked for:

appropriate range, reasonableness division by zero, if division is taking place

In C++ the = operator indicates:

assignment

Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression.

break

A function is executed when it is:

called

.eof()

checks to see if the file has read the last line or not, ex. while(fileObject.eof() != true) { fileObject >> data; }

.is_open()

checks to see if the file object succesfully opened, returns 1 if opened, returns 0 if not

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

closes a file

In a function header, you must furnish:

data type(s) of the parameters data type of the return value the name of function names of parameter variables

The trailing else in an if/else if statement has a similar purpose as the section of a switch statement.

default

A function ________ contains the statements that make up the function.

definition

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

document

Local variables are initialized to zero by default.

false

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

false

When an if statement is nested in the else part of another statement, as in an if/else if, the only time the inner if is executed is when the expression of the outer if is true.

false

You must furnish an argument with a function call.

false

This is a variable, usually a boolean or an integer, that signals when a condition exists.

flag

To allow file access in a program, you must #include this header file.

fstream

This is a collection of statements that performs a specific task.

function

This is a statement that causes a function to execute.

function call

To read data from a file, you define an object of this data type.

ifstream

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

integer constant/literal

Why is it critical that counter variables be properly initialized?

it is important to initialize counter variables properly because it will affect their scope. Ifa counter variable is defined outside of a loop it will have a wider scope, while if it is defined inthe loop expression it will only have a scope within the loop.

Each repetition of a loop is known as a(n) .

iteration

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

local

To write data to a file, you define an object of this data type.

ofstream

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

opened

The do-while loop is a ________ loop that is ideal in situations where you always want the loop to iterate at least once.

post-test

When the increment or decrement operator is placed after the operand (or to the operand's right), the operator is being used in mode.

postfix

This statement causes a function to end.

return

The ________ of a variable is limited to the block in which it is declared.

scope

Function prototypes are terminated with a semicolon.

true

Global variables are initialized to zero by default.

true

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

true

You may define a ________ in the initialization expression of a for loop.

variable


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

Health Care for All - Exam 2 Chapter 12

View Set

APES Unit 9, Unit Progress Check APES

View Set

Chapter 4: Network Protocols and Routing

View Set

Respiratory Disorders NCLEX 3000

View Set

Different kinds of intelligence that affect behavior in organizations

View Set

ECON 2201 CH. 11 & 12 Quizzes for Final Exam

View Set

Macroeconomics Updated Final Exam

View Set