Programming

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

What is the output of the following code fragment? int x=0; { int x=13; cout << x <<","; } cout << x << endl;

13,0

What is the value of x after the following statements? int x; x = 15/4;

3

Given the following code, what is the final value of i? int i; for(i = 0; i <= 4; i++) { cout << i << endl; }

5

Given the following enumerated data type definition, what is the value of SAT? enum myType{SUN,MON,TUE,WED,THUR,FRI,SAT,NumDays};

6

Given the following enumerated data type definition, what is the value of SAT? enum myType{SUN=3,MON=1,TUE=3,WED,THUR,FRI,SAT,NumDays};

7

The precondition(s) for a function describe:

What must be true before the function executes

Which command reads one character even if that character is a blank space?

get

Reserved or key words can be used as identifier names.

false

Variables defined inside a set of braces are said to be _______ to that block of code

local

A function that is associated with an object is called a _________ function.

member

In order to read data from a file you

must know the kind of data in the file

Which of the following is the correct way to close a file stream named outFile?

outFile.close();

To open an output file and add to the end of the data already in the file you would write

outFile.open("project.txt", ios::app);

The _______ function puts one character back into the input stream.

putback

The get function

reads one character value

Which of the following is not a valid identifier?

return

What is wrong with the following for loop? for(int i = 0; i < 10; i--) { cout << "Hello\n"; }

infinite loop

Which of the following are valid case statements in a switch?

case 1:

The postcondition of a functions

tells what will be true after the function executes

A loop that iterates one too many or one too few times is said to be off by one.

True

A simplified main program used to test functions is called

a driver

The put function

outputs one character value

A boolean expression is an expression that can be thought of as being true or false.

true

A break statement in a switch ends the switch statement.

true

A loop that iterates one too many or one too few times is said to be off by one.

true

In a function with call-by-reference parameters, any changes to the formal parameters will change the actual arguments passed to the function.

true

The following is legal in a void function return;

true

What is the output of the following code? float value; value = 33.5; cout << "value" << endl;

value

A function that does not return a value is known as a ________ function.

void

An array parameter is indicated using empty brackets in the parameter list such as

void fillUp(int a[ ], int size);

The integer 0 is considered true

False

A semicolon by itself is a valid C++ statement.

True

Which loop runs at least once?

do-while

A _________ is a variable that as function as well as data associated with it.

object

Which include directive is necessary for file IO?

#include<fstream>

What is the correct way to write the condition y < x < z?

((y < x) && (x < z))

Which of the following is an example of a boolean expression?

(hours > 40)

What is the output of the following (when embedded in a complete program)? for(int count = 1; count < ; count++) cout << (3 * count) << " " ;

3 6 9 12 15

What is the value of x after the following statements? int x; x = 0; x = x + 30;

30

Which of the following are member functions of an object? Select all that apply

.close .setf

Which of the following comments would be the best post-condition for this swap function void swap( int& left, int&right);

//Postcondition: the values of left and right are exchanged

How many times is "Hi" printed to the screen for(int i = 0; i < 14; i++) cout <<"Hi\n";

14

Testing your program should be done

As each function is developed

Computer memory consists of numbered locations called bytes

A byte's number is its address

When a void function is called, it is known as

An executable statement

If an array is declared as: int a[6]; and an integer is declared as: int i = 7;

Executing the statement a[i] = 238; causes... The computer to calculate the address of the illegal a[7] (This address could be where some other variable is stored) The value 238 is stored at the address calculated for a[7] No warning is given!

A compound statement that contains variable declarations is called an iteration.

False

In a function with call-by-reference parameters, the values of the actual arguments are passed to the function.

False

Why do we need arrays

Imagine keeping track of 5 test scores, or 100, or 1000 in memory How would you name all the variables? How would you process each of the variables?

To assign a value to an indexed variable, use the assignment operator: int n = 2; score[n + 1] = 99

In this example, variable score[3] is assigned 99

The variables making up the array are referred to as

Indexed variables Subscripted variables Elements of the array

Example: int children[3] = { 2, 12, 1 };

Is equivalent to: int children[3]; children[0] = 2; children[1] = 12; children[2] = 1;

What is the purpose of declaring a variable const?

Its value cannot be changed by the program like a variable

Which of the following is true for a void function?

Nothing is retured

Which of the following is not used when using files for input and output

Prompting for file data

What is the purpose of short-circuit evaluation?

Tells the compiler if leftmost subexpression is true, the rest of the expression is not evaluated

The number of indexed variables in an array is the declared size, or size, of the array

The largest index is one less than the size The first index value is zero

If you write a function that should use call-by-reference, but forget to include the ampersand

The program will run with incorrect results

What is the output of the following code? cout << "This is a \\" << endl;

This is a \

It is legal to declare more than one variable in a single statement.

True

The body of a while loop may never execute

True

The code following the default case is executed if none of the other cases are matched in a switch statement

True

When is the external name of the file used in the program?

When opening the file stream

Call-by-reference should be used

When the function needs to change the value of one or more arguments

You should make a parameter a reference parameter if:

You need the function to change the value of the argument passed to the function

Which line of code allows the program to create a new line?

\n

Which of the following are true

a function can call another function

A simplified version of a function which is used to test the main program is called

a stub

If a function needs to modify more than one variable, it must

be a call by reference function

A section of code enclosed by braces which contains variable declarations is called a __________.

block

If function fillUp is declared in this way: void fillUp(int a[ ], int size); and array score is declared this way: int score[5], numberOfScores

fillUp is called in this way: fillUp(score, numberOfScores);

To open a file with a user supplied name, you would need to store the name in a variable. If the file name was to have no more than 20 characters in it, which would be an appropriate declaration of the file name variable?

char filename[21];

After a stream is opened, before it is used for input and output, it should be

checked to see if it opened correctly

The stream that is used for input from the keyboard is called

cin

Which of the following lines correctly reads a value from the keyboard and stores it in the variable named myFloat?

cin >> myFloat;

The stream that is used for output to the screen is called

cout

If a file did not open correctly, you should

display an error message and take some suitable action such as exit

Which of the following is a legal call to the displayOutput function? void displayOutput(int total);

displayOutput(myTotal);

Which loop structure always executes at least once?

do-while

Loops are used when we need our program to make a choice between two or more things.

false

Which of the following is the correct way to determine if a file stream named inFile opened correctly?

if( inFile.fail() )

In the following code fragment, which is the class? ifStream inStream; ofStream outStream; inStream.open("infile.dat"); if (inStream.fail()) { cout << "Input file opening failed.\n" exit(1) }

ifStream

In the following code fragment, which is the object? ifStream inStream; ofStream outStream; inStream.open("infile.dat"); if (inStream.fail()) { cout << "Input file opening failed.\n" exit(1) }

inStream

Which statement correctly opens an input stream named in_file and attaches it to a file name project.txt?

in_file.open("project.txt");

Which of the following declares three integer variables named number1,number2, and number3

int number1, number2, number 3;

Executing one or more statements one or more times is known as:

iteration

What is the output of the following code fragment if x is 15? if(x < 20) if(x <10) cout << "less than 10 "; else cout << "large\n";

large

In an array declaration, [ ]'s enclose the size of the array such as this array of 5 integers: int score [5];

score[3] is one of the indexed variables The value in the [ ]'s can be any expression that evaluates to one of the integers 0 to (size -1)

Call-by-reference parameters pass...

the actual argument


Set pelajaran terkait

Social Media Communications Test

View Set

What is the decimal format of the following binary IP address? cisco chapter 4

View Set