Programming Fundalmentals II — Test 3

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

When a file is opened, the file stream object's "read position" is ________. A) at the end of the file B) at the beginning of the file C) nonexistent, until the programmer declares it D) in the middle of the file E) None of the above

B) at the beginning of the file

A recursive function should be designed to stop making recursive calls when it reaches its ________. A) return statement B) base case C) closing curly brace D) last parameter E) None of the above

B) base case

The member function, ________, reads a single character from a file. A) read B) get C) put D) input E) None of the above

B) get

Data stored ________ is lost when the computer is powered down. A) on CD ROM B) in RAM C) on a backup tape D) on the hard disk E) None of the above

B) in RAM

When a function A calls a function B, which in turn calls A, we have ________. A) direct recursion B) indirect recursion C) function call cycling D) perfect recursion E) None of the above

B) indirect recursion

What will the following program display? #include <iostream> using namespace std; int function(int); int main() {int x =10; cout <<function(x)<<endl; return0;} int function(int num) {if (num <=0) return 0; else return function (num - 1) +num;}

(N/A)

The state bit, ________, can be tested to see if the end of an input stream has been encountered. A) ios::eof B) ios::eofbit C) ios::failbit D) ios::badbit E) None of the above

B) ios::eofbit

A file must be ________ before data can be written to or read from it. A) closed B) opened C) declared D) initialized E) None of the above

B) opened

The ________ algorithm uses recursion to sort an array. A) shell sort B) quicksort C) binary sort D) red/black sort E) None of the above

B) quicksort

The ________ function can be used to store binary data to a file. A) binary.out B) write C) put D) dataout(binary) E) None of the above

B) write

To access files from a C++ program, you must #include ________. A) <fileaccess> B) <filestream> C) <fstream> D) <iostream> E) None of the above

C) <fstream>

A recursive function that does not correctly handle its base case may ________. A) return 0 and stop B) return FALSE and stop C) cause an infinite chain of recursive calls D) reach the NULL terminator and stop E) None of the above

C) cause an infinite chain of recursive calls

The statement dataFile.close(); ________. A) is illegal in C++ B) needs a file name argument to execute correctly C) closes a file D) is legal but risks losing valuable data E) None of the above

C) closes a file

The ________ data type can be used to connect to files and read information from them into memory. A) ofstream B) istream C) ifstream D) instream E) None of the above

C) ifstream

When used by itself, ________ causes a file's contents to be deleted if the file already exists. A) ios:app B) ios::in C) ios::out D) All of the above E) None of the above

C) ios::out

The member function ________ writes a single character to a file. A) get B) write C) put D) insert E) None of the above

C) put

A ________ function is one that calls itself A) dynamic B) static C) recursive D) data validation E) None of the above

C) recursive

The ________ may be used to write information to a file. A) cout object B) pen object C) stream insertion operator << D) fileWrite() function E) None of the above

C) stream insertion operator <<

The programmer must ensure that a recursive function does not become ________. A) a static function B) a prototyped function C) trapped in an infinite chain of recursive calls D) a dynamic function E) None of the above

C) trapped in an infinite chain of recursive calls

When the >> operator extracts information from a file, it expects to read data that are separated by ________. A) commas B) tabs C) whitespace D) semicolons E) None of the above

C) whitespace

The ________ of recursion is the number of times a recursive function calls itself. A) level B) breadth C) type D) depth E) None of the above

D) depth

The ________ member function reports when the end of a file has been found. A) end() B) stop() C) done() D) eof() E) None of the above

D) eof()

The ________ may be used to read information from a file. A) cout object B) the stream insertion operator C) file.in macro D) stream extraction operator E) None of the above

D) stream extraction operator

Recursion can be used to ________. A) compute factorials B) find the greatest common divisor of two integers (GCD) C) program things that cannot be programmed without recursion D) All of the above E) Both A and B, but not C

E) Both A and B, but not C

The base case of a recursive function ________. A) is 0 B) is 1 C) is depth / 2 D) is 1 / (depth * 3.1415) E) depends on the problem being solved

E) depends on the problem being solved

True/False: A recursive function cannot call a function other than itself.

False

True/False: Indirect recursion means that a function calls itself several times.

False

True/False: When you store data in a variable, it is automatically saved in a file.

False

True/False: Any algorithm that can be coded with recursion can also be coded using a loop

True

True/False: File output may be formatted the same way as screen output.

True

True/False: The read and write member functions of fstream objects can only work with buffers specified by pointers to char.

True

True/False: The stream member function fail()can be used to determine whether the last operation performed on a stream was successful.

True

True/False: To write to a binary file, you can use the write() member function of an ofstream object.

True

True/False: When a recursive function directly calls itself, this is known as direct recursion.

True

True/False: When you assign a name to a file, the operating system identifies the file by that name.

True

What will the following program display? #include <iostream> using namespace std; void showMe (int); int main() {int num = 0; cout << showMe(num); return 0;} void showMe(int arg) {if (arg < 10) showMe (++arg); else cout << arg << endl;}

10

The state bit ________ is set when an attempted operation has failed. A) ios::failbit B) ios::badbit C) ios::hardfail D) ios::goodbit E) None of the above

A) ios::failbit

The ________ data type can be used to create files and write information to them. A) ofstream B) ifstream C) istream D) ostream E) None of the above

A) ofstream

Closing a file causes any buffered information to be ________. A) saved to the file B) deleted C) stored in a buffer for safekeeping D) duplicated E) None of the above

A) saved to the file

The quicksort algorithm can be used to ________. A) sort lists stored in arrays B) perform binary search on arrays C) quickly sort and search arrays D) All of the above E) None of the above

A) sort lists stored in arrays


Set pelajaran terkait

Unintentional Torts (Negligence), Defenses, and Strict Liability

View Set

Hubspot Digital Marketing Certification Exam

View Set