CSCI 240 Final Exam

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

List two differences between a function prototype and a function header:

1. function prototype requires a semi-colon 2. function header requires argument names

Consider the following: int x; double n1 = 5, n2 = 2; x = n1/n2; What value is in x?

2

What values are contained in array ar? int ar[10] = { 2, 4, 6, 8, 10 };

2 4 6 8 10 0 0 0 0 0

What will the following loop display? int k; for( k = 2; k < 4; k++ ); cout << k

4

What symbol is the input operator?

>>

True/False A function that uses call by reference (or reference arguments) can make direct changes to variables that were declared outside of the function.

True

True/False It is legal and acceptable to have two local variables in two different functions with the same name and the same datatype.

True

True/False strcmp( str1, str2); The value 0 is returned if str1 and str2 are equal

True

Making a variable perform like a variable of a different data type is known as

Typecasting

The null terminator is represented as a character literal of

\0

Which of the following is a condition that will test if the value in the integer variable num is even? a. (num % 2) == 0 b. (num / 2) == 0 c. (num % 2) == 1 d. (num / 2) == 1 e. none of the above

a. (num % 2) == 0

A function prototype does not have to __________. a. include argument names b. end with a semi-colon c. agree with the function header d. match with all calls of the function

a. include argument names

Prototype statements are placed before int main(). a. true b. false

a. true

The :: operator is used to associate a method with a specific class. a. true b. false

a. true

The statement int main() means that main is a function that takes no arguments, and returns an integer. a. true b. false

a. true

The class X contains two data members: an integer called xVal and a float called xPerc. Which of the following is NOT a valid prototype for the class definition for X? a. void X( int, float ); b. void setxVal( int ); c. float getxPerc(); d. X( int, float ); e. void printX();

a. void X( int, float );

Which of the following is a program control instruction? a. while b. = (the assignment statement) c. cout d. #define

a. while

Complete the following sentence: the unsubscripted name of an array is the ______________________

address of the array

We call the pieces of information that are passed to a function, which it then uses to do its task a/an ____________

argument

Suppose we want to store the value 1.5 into a double variable d. Which of the following would not work? a. d = 3.0/2; b. d = 1.5; c. d = 3/2; d. d = 1 + 0.5; e. all of the above will work

c. d = 3/2

Which of the following is the correct definition for a variable called dblRef that can hold a reference to the double variable dblNum? a. double dblRef = dblNum; b. double *dblRef = &dblNum; c. double &dblRef = dblNum; d. double &dblRef;

c. double &dblRef = dblNum;

Which of the following "chunks" of C++ code will print the contents of an array called ar that has been defined to hold 25 integer values and has been initialized with 25 integer values? int i; a. cout << ar[]; b. for( i = 0; i == 25; i++ ) cout << ar[i] << " "; c. for( i = 0; i < 25; i++ ) cout << ar[i] << " "; d. for( i = 0; i < 25; i++ ); cout << ar[i] << " ";

c. for( i = 0; i < 25; i++ ) cout << ar[i] << " ";

If the logic of your program at some point requires you to do one thing or another, which instruction would you use to implement this decision? a. while b. for c. if..else d. sequence e. cin

c. if..else

A function calling statement must supply arguments that a. match the function header in number b. match the function header in number and order c. match the function header in number, order, and data type d. match the function header in number, order, data type, and names e. match the function header in number, names, and data type

c. match the function header in number, order, and data type

An instance of a class is known as a/an __________. a. variable b. method c. object d. thing

c. object

What are the three basic control structures used in programming? a. int, double, string b. while, do..while, for c. sequence, decision, repetition d. input, output, and calculation

c. sequence, decision, repetition

When the body of a function begins to execute what is true of its arguments? a. they must be declared as local variables in the function b. they must be initialized by the function before they are used c. they already have values provided by the calling function and are ready to be used d. the arguments must be #defined

c. they already have values provided by the calling function and are ready to be used.

Write one statement to display the first 3 letters of your first name, one per line.

cout << "S" << endl << "i" << endl << "m"; === or === cout << "S\ni\nm";

Write a statement to display a double in a field 10 characters wide using two decimal places.

cout << setiosflags(ios::fixed) << setprecision(2) << setw(10) << doubleNum;

The various string functions that were discussed in lecture (strcpy, strcmp, etc...) are contained in the _______ library.

cstring

Rank the order in which arithmetic statements are evaluated (place numbers 1, 2, ... in the space provided. If a rule is given that is not a correct rule, do not place a number next to it. a. exponentiation b. addition and subtraction, left to right c. addition and subtraction, right to left d. sub-expressions in parenthesis e. multiplication and division, left to right f. multiplication and division, right to left

d. (1) sub-expressions in parenthesis e. (2) multiplication and division, left to right b. (3) addition and subtraction, left to right

What will be displayed by the following code? int main() { int num[5] = { 2, 4, 6, 8, 10 }; int i; fn(num); for( i = 0; i < 5; i++ ) cout << num[i] << ' '; return 0; } int fn( int n[] ) { n[3] = n[3] + 1; } a. The code will not display anything b. 2 4 6 8 10 c. 2 4 7 8 10 d. 2 4 6 9 10 e. There is not enough information provided to determine what will be displayed.

d. 2 4 6 9 10

Which of the following is not a legal variable name? a. _something b. aVariable c. float2string d. 2manyLetters e. x

d. 2manyLetters

Which of the following (a-c) is a control structure? a. sequence structure b. repetition structure c. decision structure d. all of the above are control structures e. none of the above are control structures

d. all of the above are control structures

Which numeric data type has the largest range? a. int b. char c. float d. double

d. double

Consider the following code fragment carefully, then answer the question: how many times will the cout statement execute: for (i = 0; i < 5; i++); cout << i; a. 5 times b. 4 times c. 6 times d. 0 times e. 1 time

e. 1 time

Which of the following statements (a-d) about Table is true? float Table[] = { 0.9, 0.8, 0.7, 0.6 }; a. The definition for Table will cause an error because there is no value specified inside of the square brackets b. Table[1] contains the value 0.9 c. There are actually 5 values stored in Table - the four listed and a null terminator as the fifth element d. The definition for Table will cause an error because an array cannot be initialized when it is created e. All of the statement (a-d) are false

e. All of the statement (a-d) are false

Which of the following statements (a-d) are true if the following lines of code are executed? int G = 17; int &H = G; a. H is now an alternate name for G b. Adding 1 to H will change the value of G to 18 c. Subtracting 5 from G and printing H will display the value 12 d. The condition H == G will give a true result e. All of the statements (a-d) are true

e. All of the statements (a-d) are true

Which of the following statements (a-d) about classes is true? a. A class can contain both data members and methods b. The members of a class may be private or public c. The name of the constructor is always the same as the name of the class d. The class definition contains prototype statements for the methods e. All of the statements (a-d) are true.

e. All of the statements (a-d) are true.

How does a function report its answer back to its calling (or boss) function? a. by altering or storing the result into one of the variables passed as an argument b. by altering or storing the result directly into the calling variable c. by couting the result to the screen d. by asking the user via an input function e. by executing a return statement with the answer

e. by executing a return statement with the answer

The null terminator is __________. a. used to advance to a new line when executing a cout statement b. represented as '\0' c. used to end a valid string d. a movie starring Arnold Schwarzenegger e. All of the statements (a-d) are correct f. Only statements b and c are correct

f. Only statements b and c are correct.

In an if/else statement, the code that follows the else statement is executed if the condition is:

false

True/False int array[]; // is a valid array declaration

false

True/False The constructor has a return type of void on the prototype and header.

false

void fn( double &, double & ); double var1, var2; What is one possible calling statement for the fn function, using var1 and var2?

fn( var1, var2 );

A function is to a standard C++ program as a _______ is to an object oriented program.

method

int buildAr( int [] ); int numVals; int array[50]; Using numVals and array, what will the calling statement for the buildAr function look like?

numVals = buildAr( array );

The strlen function returns the

number of characters in a string

An instance of a class is known as a/an

object

The keyword _______ makes data members and methods accessible outside of a class.

public

The two types of access methods that were discussed in class are______ and ______ methods

set and get

What is the instruction that will copy the string str1 into string str2?

strcpy( str2, str1 );

The unsubscripted name of an array is

the address of the array

A function prototype is placed before int main().

true

Will the following loop condition be evaluated to true or false? while( 240 )

true

If a function does not return anything, then the return type on the function prototype and function header is _____

void

What symbol in C++ is used to express a logical "or"?

||

A function may return _____ or _______ result(s). It may take _________ to __________ arguments.

0 or 1; 0 to many

The subscripts of an array that has been declared to hold 30 values ranges from _____ to _____.

0 to 29.

Complete the following sentence: If you declare an array to hold N values, legal subscripts run from _______ to _____________.

0 to N - 1.

What symbol in C++ is used to express a logical "and"?

&&

double x = 3.1415, y = 9.8765; // line 1 double &ref = x; // line 2 ref = y; // line 3 what does line 3 do?

Assign 9.8765 to x

What is wrong with this declaration? char &ref;

It must be associated with a character variable.

Suppose you have a point on a plane represented by the variables ptX and ptY (its x and y coordinates). Suppose you also have a rectangle, whose upper left corner is represented by the variables left and top, and whose bottom right corner is represented by the variables right and bot. Using the standard graphics coordinate system, in which y increases from top to bottom and x increases from left to right, which of the following conditions will test if the point is outside the rectangle? a. (ptX < left && ptX > right && ptY > bot && ptY < top) b. (ptX < left || ptX > right || ptY > bot || ptY < top) c. (ptX > left && ptX < right && ptY < bot && ptY > top) d. (ptX < left || ptX > right || ptY < bot || ptY > top) e. none of the above

b. (ptX < left || ptX > right || ptY > bot || ptY < top)

If x contains the value 3 before the following instruction is executed, what is the value of x after the instruction: x *= 5; is executed? a. 5 b. 15 c. the value is unknown d. the statement is illegal

b. 15

What will be displayed by the following code? int main() { int num = 3; fn(num); cout << num; return 0; } int fn( int n ) { n++; } a. The code will not display anything b. 3 c. 4 d. 5 e. There is not enough information provided to determine what will be displayed.

b. 3

What will be displayed by the following code? int main() { int num = 3; fn(num); cout << num; return 0; } void fn( int n ) { n++; } a. The code will not display anything b. 3 c. 4 d. 5 e. There is not enough information provided to determine what will be displayed.

b. 3

A loop exit condition must a. be the last instruction in the body of the loop b. evaluate to true or false c. be the first instruction in the body of the loop d. not use compound conditions

b. evaluate to true or false

A variable called score is declared in main(). main() calls a function UpdateScore to update the score. UpdateScore also has a variable called score. When a value is added to score in UpdateScore, the value of score in main() is also changed. a. true b. false

b. false

The following is a valid array definition. int ar[]; a. true b. false

b. false

The function header and the calling statement must contain the name and the data type of the arguments. a. true b. false

b. false

Which of the following appear in a function header? a. the function name, return type, and argument types b. the function name, return type, argument types and argument names c. the function name, return type, and argument names d. the function name and the supplied arguments

b. the function name, return type, and argument types and argument names

Function prototypes are located ________________

before int main().

What is the subscript of the last element in the array Table if it is defined as follows? float Table[30]; a. 30 b. 31 c. 29 d. 0 e. none of the above

c. 29

Which of the following string functions will ALWAYS produce a valid string after execution? a. strcpy b. strcat c. Both of the functions (a-b) will produce a valid string

c. Both of the functions (a-b) will produce a valid string

The force of gravitational attraction, F, of two bodies is given by a formula in which a constant, G, is multiplied by the product of the two masses (m1 and m2). This is then divided by the square of the distance, d, between the two bodies. Assuming these variables are declared, and have proper initial values where necessary, which of the following C++ statements correctly expresses this formula? a. F = = G*m1*m2/d^2; b. F = G*m1*m2/d*d; c. F = G*m1*m2/(d*d); d. a or c is correct e. b or c is correct

c. F = G*m1*m2/(d*d);

What is wrong with the following definition for a C-style symbolic constant called PI? #define PI = 3.24159 a. The actual value of the mathematical constant pi is not 3.24159 b. There should be a semi-colon at the end of the line c. There should not be an equal sign d. The name PI is a reserved word and therefore cannot be used e. There is nothing wrong with the definition

c. There should not be an equal sign

How many times will the following while loop print "hello"? int i = 1; while( i <= 10 ) cout << "hello" a. 10 b. 8 c. an infinite number of times d. 0

c. an infinite number of times

If a string will need room for 25 characters, how should it be defined so that it will be a valid string? a. char str[25]; b. char str[24]; c. char str[26]; d. char str[];

c. char str[26];


Ensembles d'études connexes

ITN 100 Chapter 8 & 9 Study Guide

View Set

Anatomy & Physiology Final Review

View Set

POLITICAL IDEOLOGY, PARTIES, AND INTEREST GROUPS

View Set

Revenue Strategies HFT 3463 Review

View Set

Chapter 9: Health Insurance Basics

View Set