CS Exam 2

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

Given the following function definition fragment, for which values of myInt should the function be tested? int doSomething(int myInt) { if(myInt < 0) { //do some stuff here } return -1; }

-1, 0 and 1

When a file is opened, the file stream object's "read position" is ________.

.at the beginning of the file

Given the following function definition, void shift(int& a, int&b) { a = b; b = a; } what is the output after the following function call? int first = 0, second = 10; shift(first, second); cout << first <<" "<< second << endl;

10 10

What is the output produced by the following code fragment? int i = 3; cout << "The value of i is " << sqrt(pow(i,4.0)) << endl;

9.0

In order, the three-step process of using a file in a C++ program involves:

:Open the file, read/write/save data, close the file

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

A

If you write a function that should use call-by-reference, but forget to include the ampersand, Question options: A) the program will run with incorrect results. B) the program will not link. C)it doesn't matter. D) the program will not compile. E) the program will not run without a run-time error.

A

In the following function, what is passed to the first parameter? void f1( int& value1, int value2); int x,y; f1(x,y); A) the variable x (or its memory location) B) the value of y C) The value of x D)Nothing, it is a void function.

A

Look at the following function prototype. int myFunction(double); What is the data type of the function's return value? A) int B) double C) void D) Can't tell from the prototype

A

Which line in the following program contains the prototype 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 } A) 4 B) 6 C) 10 D) 15

A

Which of the following are valid function calls to the fabs function? Question options: A) fabs(3.5);, cout << fabs(3.5), and cin >> fabs(3.5); B) cin >> fabs(3.5); C) fabs(3.5); and cout << fabs(3.5) D) cout << fabs(3.5); E) fabs(cin >> x); F) fabs(3.5);

A

Which of the following are valid function calls to the pow function? Question options: A) pow(1.1,3.0); B) double pow(1.1,3.0); C) pow(int x, int y); D) pow(2);

A

ios::showpos is a flag that A) always displays a + in front of positive integers. B) can be used to find the absolute value of an integer. C) always displays a + in front of all integers. D) All of these.

A

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? A) char filename[21]; B) char filename[20]; C) char filename(20); D) char filename;

A) char filename[21];

Look at the following function prototype. int myFunction(double); What is the data type of the function's parameter variable? A) int B) double C) void D) Can't tell from the prototype

B

The value in this type of local variable persists between function calls. A) global B) internal C) static D) dynamic E) None of these

C

What is wrong with the following function body? void calculate(int count, float price, float& cost) { if(count < 0) cost = 0.0; else cost = count * price; return; } A) Void functions may not have a return statement B) Void functions must return a value C) Nothing D) Cannot mix reference and value parameters

C

A ________ argument is passed to a parameter when the actual argument is left out of the function call. A) false B) true C) null D) default E) None of these

D

A function is executed when it is: A) defined B) prototyped C) declared D) called E) None of these

D

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 } A) 4 B) 6 C) 10 D) 15

D

Which of the following statements opens the file info.txt for both input and output? A) dataFile.open("info.txt", ios::in && ios::out); B) dataFile.open("info.txt", ios::in , ios::out); C) dataFile.open("info.txt", input || output); D) dataFile.open("info.txt", ios::in | ios::out);

D

When overloading a function, what must be true?

The names should be the same with different number and/or types of parameters

pow function

a built-in C++ function that raises a number to a power and then returns the result as a double number (3,4) = 3^4

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 All of these

all of these

When a void function is called, it is known as

an executable statement.

to write data to a file, you define an object of this data type. a. outputFile b. ifstream c. fstream d. ofstream

b

Pre and post conditions for a function should be written (before/after) the function definition is written.

before

Testing a program with values that are close to values that will change the execution of a program is called ________.

boundary value testing

Testing a function or program using test values that are at or near the values that change the outcome of the program is known as using

boundary values

When used by itself, this access flag causes a file's contents to be deleted if the file already exists. Question options: a. ios::app b. ios::in c. ios::out d. All of these e.None of these

c

The get function reads

character values.

A type whose variables are objects is known as a ________.

class

fabs, pow, and sqrt are found in what include file?

cmath

fabs function is found in ____, and it returns the _____

cmath, absolute value

Here is the header for a function named computeValue: void computeValue(int value) Which of the following is a valid call to the function? computeValue(10) computeValue(10); void computeValue(10); void computeValue(int x);

computeValue(10);

ofstream, ifstream, and fstream are: Question options: header files libraries data types string arrays None of these

data types or string arrays

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

definition

What is the correct way to call the following function? Assume that you have two variables named intArgument(int) and floatArgument(float). void doThings(float x, int y);

doThings(floatArgument, intArgument);

Write the code to convert the value in an integer variable named count to a double.

double(count)

A ________ is a main program that only checks that functions execute correctly.

driver

The member function eof() is (true/false) when we are ready to read the end of file character.

false

The ________ describes how the function will work.

function definition

assert function

function that terminates program if a given condition is not true.

constant variables that might be used in different functions should be

global

#include <cmath> is known as an ________________.

include directive

Which of the following functions is a properly overloaded function of the following? int doSomething(int first, float second);

int doSomething(int first, int second, float third);

In order to use the stream manipulators, you must include the ________ library

iomanip

Variables that are declared inside a function are said to be ________ to that function.

local

A(n) ________ is a variable that has functions as well as data associated with it.

object

The put function outputs

one character value.

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

prototype

What is the correct way to call the following function? void setDisplay();

setDisplay();

The flag to always show the decimal point in floating numbers is ios::__________

showpoint

A ________ is a flow of characters or other data.

stream

This may be used to write information to a file. a. cout object b. pen object c.output object d. stream insertion operator e. None of these

stream insertion operator

"\n" is a __________ and '\n' is a __________.

string, character

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

stub

____ is a simplified version of a function used to test main programs.

stub

A problem-solving approach that starts with the big problem and breaks it down into smaller pieces is called ________.

top-down

converting to one type to another is called

type casting

When the function below is called, the ________ of the actual parameters is passed to the function definition. double sqrt(double value);

value


Set pelajaran terkait

NUR 112 // E5: 1-Growth and Development (Conception - Adolescence)

View Set

Financial Accounting 210 Final Review

View Set

Week 14: The Reproductive System

View Set

BS1 non-clinical and clinical Qs

View Set

Chapter 12 Reading (Versions 1 and 2)

View Set

Measles, mumps, rubella, rubeola, Parvovirus, and EBV.

View Set

Chapter 18 Fire Prevention, Detection, and Response

View Set