Quiz_Practice_3_ANSWERS

pdf

School

Dartmouth College *

*We aren’t endorsed by this school

Course

MISC

Subject

Computer Science

Date

Nov 24, 2024

Type

pdf

Pages

7

Uploaded by ProfWildcatMaster683

Report
Computing III: Quiz Study Guide 3 Name___________________________________ SHORT ANSWER. Write the word or phrase that best completes each statement or answers the question. 1) "\n" is a ________ and '\n' is a ________. 1) 2) The ________ function puts one character back into the input stream. 2) 3) If class A is derived from class B, then B is a ________ of A. 3) 4) open is a ________ function of the ofstream and ifstream class. 4) 5) The manipulator used to change the number of decimal places displayed is ________. 5) 6) A ________ is a flow of characters or other data. 6) 7) A value that can be turned on or off is called a ________. 7) 8) Which command reads one character even if that character is a blank space? 8) 9) The member function eof( ) is (true/false) when we are ready to read the end of file character. 9) 10) When passing a stream to a function, it must always be pass - by - ________. 10) 11) The flag to always show the decimal point in floating numbers is ios:: ________ 11) 12) In the following function declaration, the istream object cin is called a ________. void output(istream& in = cin); 12) 13) A type whose variables are objects is known as a ________. 13) 14) The flag to display floating point numbers in non - scientific notation is ios:: ________ 14) 15) All data is input and output as ________ data. 15) MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 16) In order to use the stream manipulators, you must include the ________ library 16) A) cstdlib B) manip C) iomanip D) fstream 17) Which of the following is not used when using files for input and output? 17) A) ensuring that the stream opened B) opening the file stream C) prompting for file data D) closing the stream 1
18) In order to read data from a file correctly you 18) A) should prompt the user for the data you are looking for. B) do not need to know the kind of data in the file. C) must know the kind of data in the file. D) A and C 19) Which of the following function declarations will accept either cout or a file stream object as its argument? 19) A) void output( ostream &outFile); B) void output( fstream &outFile); C) void output( ofstream &outFile); D) void output( iostream &outFile); 20) Which of the following is the correct way to determine if a file stream named inFile opened correctly? 20) A) if( inFile.open( ) ) B) if( inFile.opened( ) ) C) if( inFile.fail( ) ) D) if( inFile.failed( ) ) 21) The get function reads 21) A) one float value. B) one character value. C) one integer value. D) one double value. 22) The ifstream class is derived from the 22) A) istream class. B) ofstream class. C) iomanip class. D) none of the above 23) A function that is associated with an object is called a ________ function. 23) A) output B) member C) instantiated D) input 24) If the user types in the characters 10, and your program reads them into an integer variable, what is the value stored into that integer? 24) A) 0 B) 10 C) 1 D) none of the above 25) Which of the following loop condition statements will read all the data in the file assuming that each record in the file is two integer values, and you will read the first one into a variable named intOne, and the other into intTwo? 25) A) while(inFile >> intOne >> intTwo) B) while(inFile) C) while(inFile << intOne << intTwo) D) while(inFile(intOne, intTwo)) E) A and B 26) The command outFile.precision(2); 26) A) truncates all floating point variables to 2 decimal places. B) displays all floating point values sent to outFile with 2 decimal places. C) set all output streams in your program to display 2 decimal places. D) displays integers as floating point numbers. 27) Which of the following is the correct way to close a file stream named outFile? 27) A) outFile.close( ); B) outFile.close("project.txt"); C) outFile.close; D) close(outFile); 2
28) We have a file that has a name in it, but the name is written one character per line. We need to write this name to the screen without newlines in it. What is wrong with the following code? ifstream fileIn; fileIn.open("file.txt"); char ch; fileIn.get(ch); while(!fileIn.eof( )) { cout.put(ch); fileIn.get(ch); } 28) A) eof is not a member of an ifstream object. B) Nothing is wrong. C) cannot use put with cout D) Our output has new lines in it. 29) When is the external name of the file used in the program? 29) A) only when reading from the file B) never C) any time you read or write to the file D) when opening the file stream 30) If a file did not open correctly, you should 30) A) display an error message and take some suitable action such as exit. B) display an error message and continue on. C) exit the program immediately. D) continue on anyway. 31) Which function returns true if the character argument is a letter? 31) A) isspace B) isdigit C) isalpha D) islower 32) 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? 32) A) char filename(20); B) char filename; C) char filename[20]; D) char filename[21]; 33) After a stream is opened, before it is used for input and output, it should be 33) A) declared. B) checked to see if it opened correctly. C) closed. D) none of the above 34) The member function setf stands for 34) A) set the format. B) set the file name. C) set the flags. D) nothing. 35) Which include directive is necessary for file IO? 35) A) #include < iomanip > B) #include < fstream > C) #include < fileIO > D) #include < cstdlib > 36) To open an output file and add to the end of the data already in the file you would write ________. 36) A) outFile.append("project.txt"); B) outFile.open("project.txt", ios::app); C) outFile.open("project.txt"); D) outFile.open("project.txt", append); 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
37) The command outFile.width(10) is used to 37) A) display the next value in at least 10 characters. B) always use 10 characters to display the output. C) set the filename of outFile to 10 characters. D) change the number of characters in the output. 38) Which statement correctly opens an input stream named in_file and attaches it to a file name project.txt? 38) A) in_file.open("project.txt"); B) in_file.open(project.txt); C) in_file = project.txt; D) in_file = "project.txt"; 39) Which of the following function declarations will correctly pass an output stream to the function? 39) A) void display( ofstream& out); B) void display( ofstream out); C) void display( ostream& out); D) void display( ostream out); E) A and C 40) What is the output of the following code? char ch = 'G'; cout << tolower(ch) << endl; 40) A) g B) the integer value of 'G' C) the integer value of 'g' D) G 41) The put function outputs 41) A) one integer value. B) one character value. C) one float value. D) one double value. 42) What is wrong with the following code? while( ! fileIn.eof( ) ) { fileIn >> value; fileout << value; } 42) A) We have written past the end of the output file. B) We have read past the end of the input file and output one garbage value. C) nothing D) A and B 43) If the name of the input file was in a variable named filename, which of the following is the correct way to open the input stream named inFile and associate it with this file? 43) A) inFile = "filename"; B) inFile = filename; C) inFile.open(filename); D) inFile.open("filename"); 44) ios::showpos is a flag that 44) A) can be used to find the absolute value of an integer. B) always displays a + in front of positive integers. C) always displays a + in front of all integers. D) all of the above 4
45) A(n) ________ is a variable that has functions as well as data associated with it. 45) A) float B) class C) int D) object TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false. 46) You may use a read (extraction) as a boolean expression in an if or while statement. 46) 47) Streams may be passed to a function. 47) 48) The formatting options that were discussed for cout do not work for output file streams. 48) 49) The ofstream class is derived from the ostream class. 49) 50) Using directives can be placed either directly after the include directives, or at the beginning of each function definition. 50) 51) '\n' is two characters. 51) 52) You must use a width statement (or an equivalent version in iomanip) before each variable that you want output in a certain width. 52) 53) If you use the width command, it stays in effect for all values that are sent to the stream. 53) 54) Two different objects of the same class have a different set of member functions. 54) 55) You may not have more than one input and one output stream open at any one time. 55) 5
Answer Key Testname: HW3 1) string, character 2) putback 3) parent 4) member 5) setprecision 6) stream 7) flag 8) get 9) false 10) reference 11) showpoint 12) default argument 13) class 14) fixed 15) character 16) C 17) C 18) C 19) A 20) C 21) B 22) A 23) B 24) B 25) A 26) B 27) A 28) D 29) D 30) A 31) C 32) D 33) B 34) C 35) B 36) B 37) A 38) A 39) E 40) C 41) B 42) B 43) C 44) B 45) D 46) TRUE 47) TRUE 48) FALSE 49) TRUE 50) TRUE 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Answer Key Testname: HW3 51) FALSE 52) TRUE 53) FALSE 54) FALSE 55) FALSE 7