Computer Science 202 Midterm (chapters 9-12)
When a structure is passed ________ to a function, its members are not copied. A) by value B) by reference C) Neither of these
B) by reference
ofstream, ifstream, and fstream are: A) string arrays B) data types C) header files D) libraries E) None of these
B) data types
True/False: A pointer can be used as a function argument, giving the function access to the original argument.
True
True/False: It is possible for a structure to contain as a member a pointer to its own structure type.
True
True/False: The itoa function is similar to atoi, but it works in reverse.
True
True/False: An alternative to using the open member function is to use the file stream object declaration itself to open the file. Example: fstream DataFile("names.dat", ios::in | ios::out);
True
True/False: By being able to pass arrays as arguments, you can write your own functions for processing C-strings.
True
True/False: C++ 11 introduces a function named to_string that converts a numeric value to a string object.
True
True/False: File output may be formatted the same way as console screen output.
True
True/False: If a file already exists, you can open it with the flags ios::in | ios::out to preserve its contents.
True
True/False: In C++ 11, if you want to retrieve a strongly typed enumerator's underlying integer value, you must use a cast operator.
True
True/False: In C++ 11, you can use smart pointers to dynamically allocate memory and not worry about deleting the memory when you are finished using it.
True
True/False: It is legal to subtract a pointer variable from another pointer variable.
True
True/False: Structure variables may be passed as arguments to functions.
True
True/False: The C++ library provides functions for converting a string representation of a number to a numeric data type, and vice-versa.
True
True/False: The expression s->m; indicates that s is a structure pointer and m is a structure member.
True
True/False: The ios::out flag causes the file's existing contents to be deleted if the file already exists.
True
True/False: The structure pointer operator is used to dereference a pointer to a structure, not a pointer that is a member of a structure.
True
True/False: When a programmer creates an abstract data type, he or she can decide what values are acceptable for the data type, as well as what operations may be performed on the data type.
True
True/False: When you use a strongly typed enumerator in C++ 11, you must prefix the enumerator with th
True
True/False: You cannot directly assign an integer value to an enum variable.
True
The ________ and ________ operators can be used to increment or decrement a pointer variable. A) ++, -- B) addition, subtraction C) modulus, division D) All of these E) None of these
A) ++, --
This describes only the general characteristics of an object. A) abstraction B) detailed specification C) initiation D) initialization E) None of these
A) Abstraction
The ________ marker is the character that marks the end of a file, and is automatically written when the file is closed. A) End of File (EOF) B) Data Read Stop (DRS) C) No More Data (NMD) D) Data Stream Close (DSC) E) None of these
A) End of File (EOF)
What is true about the following statement? out.open("values.dat", ios::app); A) If the file already exists, its contents are preserved and all output is written to the end of the file. B) If the file exists, it can be opened but not modified. C) If the file exists, it should be replaced with a new copy of values.dat. D) None of these
A) If the file already exists, its contents are preserved and all output is written to the end of the file.
If a is a structure variable and p, a pointer, is a member of the structure, what will the following statement do? cout << *a.p; A) Output the dereferenced value pointed to by p. B) Output the address stored in p. C) Result in a compiler error. D) Output the value stored in a. E) None of these
A) Output the dereferenced value pointed to by p.
Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr; A) The value stored in the variable whose address is contained in ptr. B) The address of the variable stored in ptr. C) The string "*ptr". D) The address of the variable whose address is stored in ptr. E) None of these
A) The value stored in the variable whose address is contained in ptr.
This is the escape sequence representing the null terminator. A) \0 B) \n C) nullptr D) \t E) None of these
A) \0
The ________, also known as the address operator, returns the memory address of a variable. A) ampersand ( & ) B) asterisk ( * ) C) percent sign (%) D) exclamation point ( ! ) E) None of these
A) ampersand (&)
Look at the following statement: sum += *array++; This statement ________. A) assigns the dereferenced pointer's value, then increments the pointer's address B) will always result in a compiler error C) increments the dereferenced pointer's value by one, then assigns that value D) is illegal in C++ E) None of these
A) assigns the dereferenced pointer's value, then increments the pointer's address
When a file is opened, the file stream object's "read position" is ________. A) at the beginning of the file at the end of the file B) nonexistent, until the programmer declares it C) in the middle of the file D) None of these
A) at the beginning of the file at the end of the file
A structure ________ contain members of the same data type. A) can B) shouldn't C) cannot D) None of these
A) can
Use the delete operator only on pointers that were ________. A) created with the new operator B) never used C) dereferenced inappropriately D) not correctly initialized E) None of these
A) created with the new operator
The C-string company[12] can hold ________. A) eleven characters and the null terminator B) twelve characters C) twelve characters and the null terminator D) thirteen characters E) None of the above
A) eleven characters and the null terminator
Passing a structure as a constant reference parameter to a function ________. A) guarantees not to result in changes to the structure's members B) will always change the structure's members C) can potentially result in changes to the structure's members D) All of these E) None of these
A) guarantees not to result in changes to the structure's members
The statement: int *ptr = nullptr; has the same meaning as ________. A) int* ptr = nullptr; B) int ptr* = nullptr; C) int ptr = nullptr; D) *int ptr = nullptr; E) None of these
A) int* ptr = nullptr;
This function will return true if its argument is a printable character other than a digit, letter, or space. A) ispunct B) isprint C) ischar D) isnotdls E) None of these
A) ispunct
This data type can be used to create files and write information to them but cannot be used to read information from them. A) ofstream B) ifstream C) outstream D) afstream E) None of these
A) ofstream
Look at the following statement: int *ptr = nullptr; In this statement, what does the word int mean? A) ptr is a pointer variable that will store the address of an integer variable. B) The variable named *ptr will store an asterisk and an integer value. C) The variable named *ptr will store an integer value. D) All of these E) None of these
A) ptr is a pointer variable that will store the address of an integer variable.
Look at the following code: int numbers[ ] = {0, 1, 2, 3, 4 }; int *ptr = numbers; ptr++; After this code executes, which of the following statements is true? A) ptr will hold the address of numbers[1]. B) ptr will hold the address of numbers[0]. C) ptr will hold the address of the 2nd byte within the element numbers[0]. D) This code will not compile.
A) ptr will hold the address of numbers[1].
This term means non-sequentially accessing information in a file. A) random access B) incremented access C) linear access D) protected access E) None of these
A) random access
The name of the structure is referred to as its ________. A) tag B) argument C) parameter D) data type E) None of these
A) tag
Look at the following statement. bookList[2].publisher[3] = 't'; This statement ________. A) will store the character 't' in the fourth element of the publisher member of booklist[2] B) will ultimately result in a runtime error C) is illegal in C++ D) will change the publisher's name of the second book in bookList to 't' E) None of these
A) will store the character 't' in the fourth element of the publisher member of booklist[2]
Which of the following statements is not valid C++ code? - float num1 = &ptr2; - int ptr = int *num1; - int ptr = &num1; - All of these are valid. - All of these are invalid.
All of these are invalid
What does the following statement do? double *num2; A) Declares and initializes an pointer variable named num2. B) Declares a pointer variable named num2. C) Initializes a variable named *num2. D) Declares a double variable named num2. E) None of these
B) Declares a pointer variable named num2.
When you work with a dereferenced pointer, you are actually working with ________. A) a copy of the value pointed to by the pointer variable B) the actual value of the variable whose address is stored in the pointer variable C) a variable whose memory has been allocated D) All of these E) None of these
B) The actual value of the variable whose address is stored in the pointer variable
A pointer variable may be initialized with ________. A) any non-zero integer value B) a valid address in the computer's memory C) an address less than 0 D) A and C only E) None of these
B) a valid address in the computer's memory
The following statement: int *ptr = new int; A) results in a compiler error B) assigns an address to the variable named ptr C) assigns an integer less than 32767 to the variable named ptr D) creates a new pointer named int E) None of these
B) assigns an address to the variable named ptr
This function converts a C-string to an integer and returns the integer value. A) strint B) atoi C) atoint D) strtoint E) None of these
B) atoi
Which of the following assigns a value to the hourlyWage member of employee[2]? A) employee[2]->hourlyWage = 50.00; B) employee[2].hourlyWage = 100.00; C) employee2.hourlyWage = 7.50; D) hourlyWage[2].employee = 29.75 E) None of these
B) employee[2].hourlyWage = 100.00;
A declaration for an enumerated type begins with the ________ key word. A) enumerated B) enum C) enum_type D) ENUM
B) enum
All stream objects have ________, which indicate the condition of the stream. A) condition statements B) error state bits C) markers D) intrinsic error messages E) None of these
B) error state bits
Look at the following declaration. enum Tree { OAK, MAPLE, PINE }; What is the value of the following relational expression? OAK > PINE A) true B) false C) This is an error. You cannot compare enumerators with relational operators.
B) false
This state bit can be tested to see if the end of an input stream is encountered. A) ios::failbit B) ios::eofbit C) ios::badbit D) ios::eof E) None of these
B) ios::eofbit
This state bit is set when an attempted operation has failed. A) ios::badbit B) ios::failbit C) ios::goodbit D) ios::hardfail E) None of these
B) ios::failbit
To determine whether a character entered is a letter of the alphabet, use this function. A) fromkeyboard B) isalpha C) alphaok D) isdigit E) None of these
B) isalpha
To test whether a character is a printable character, use this function. A) isprintable B) isprint C) isoktoprint D) isprintok E) None of these
B) isprint
Not all arithmetic operations may be performed on pointers. For example, you cannot ________ or ________ a pointer. A) increment, decrement B) multiply, divide C) +=, -= D) add, subtract E) None of these
B) multiply, divide
Outside of a C++ program, a file is identified by its ________. Inside a C++ program, a file is identified by a(n) ________. A) file name, file number B) name, file stream object C) file number, file name D) name, address E) None of these
B) name, file stream object
This member function writes a single character to a file. A) get B) put C) write D) insert E) None of these
B) put
A library function that can find one C- string inside another is: A) strsearch B) strstr C) strfind D) strcmp E) None of these
B) strstr
To change a lower case character to an upper case character, use this function. A) itoa B) toupper C) atoi D) ltou E) None of these
B) toupper
The null terminator stands for this ASCII code. A) 57 B) 100 C) 0 D) 1000 E) None of these
C) 0
After the following statement executes, what value is stored in the variable num? num = atoi("1000"); A) "1000" B) 999 (1000 minus 1 for the null terminator) C) 1000 D) "thousand" E) None of these
C) 1000
A practical application of this function is to allow a user to enter a response of 'y' or 'Y' to a prompt. A) toupper B) tolower C) A or B D) ignorecase E) None of these
C) A or B
In order, the three-step process of using a file in a C++ program involves: A) Name the file, open the file, delete the file B) Create the file contents, close the file, name the file C) Open the file, read/write/save data, close the file D) Insert a disk, open a file, remove the disk E) None of these
C) Open the file, read/write/save data, close the file
If you are using an older compiler that does not support the C++ 11 standard, you should initialize pointers with ________. A) a nonzero value B) the null terminator '\0' C) the integer 0, or the value NULL D) All of these E) None of these
C) The integer 0, or the value NULL
Which statement converts the string "10" to the integer value 10? A) atoi("ten") B) itoa("ten") C) atoi("10") D) itoa(10) E) None of these
C) atoi("10")
Which of the following statements opens the file 'info.txt' for both input and output? A) dataFile.open("info.txt", input || output); B) dataFile.open("info.txt", ios::in , ios::out); C) dataFile.open("info.txt", ios::in | ios::out); D) dataFile.open("info.txt", ios::in && ios::out);
C) dataFile.open("info.txt", ios::in | ios::out);
If 'Circle' is a structure, the statement: Circle *pcirc = nullptr; A) initializes a null pointer with the value of the Circle pointer B) declares an empty structure variable called *pcirc C) declares a structure pointer called 'pcirc' initialized with a null pointer D) is illegal in C++ E) None of these
C) declares a structure pointer called
This data type can be used to create files, read data from them, and write data to them. A) iftream B) ofstream C) fstream D) stream E) None of these
C) fstream
To test whether a character is a numeric digit character, use this function. A) isnumber B) notAlpha C) isdigit D) isnumeric E) None of these
C) isdigit
Closing a file causes any unsaved information still held in the file buffer to be ________. A) retained in the buffer for safekeeping B) duplicated C) saved to the file D) deleted E) None of these
C) saved to the file
A structure pointer contains ________. A) the dereferenced address of a structure tag B) the address of a structure tag C) the address of a structure variable D) the name and address of the structure tag E) None of these
C) the address of a structure variable
Look at the following statement if (!isdigit(var1)) The expression being tested by this statement will evaluate to true if var1 is: A) a symbol such as $ or & B) 9 C) an alphabetic character D both A and C E) None of these
D both A and C
"Whitespace" encompasses which of the following? A) newline B) tab C) space D) All of these E) None of these
D) All of these
Which of the following is an example of a C++ primitive data type? A) unsigned char B) long double C) unsigned short int D) All of these E) None of these
D) All of these
A pointer variable is designed to store ________. A) only floating-point values B) an integer C) any legal C++ value D) a memory address E) None of these
D) a memory address
Which statement displays the address of the variable num1? A) cout << *num1; B) cout << num1; C) cin >> &num1; D) cout << &num1; E) None of these
D) cout << &num1;
Which of the following statements outputs the value of the gpa member of element 1 of the student array? A) cout << student1.gpa; B) cout << firstStudent.gpa; C) cout << student1->gpa; D) cout << student[1].gpa; E) None of these
D) cout << student[1].gpa
Data stored here disappears once the program stops running or the computer is powered down. A) on a CD B) on the disk drive C) on a backup tape D) in RAM E) None of these
D) in RAM
What is the output of the following statement? cout << tolower(toupper('Z')) << endl; A) a lower case z followed by an upper case Z B) upper case Z C) a compiler error D) lower case z E) None of these
D) lower case z
In C++, a C-string is a sequence of characters stored in consecutive memory, terminated by a ________. A) period B) semicolon C) space D) null character E) None of these
D) null character
The following statement: cin >> *num3; A) stores the keyboard input into the pointer called num3 B) stores the keyboard input into the variable num3 C) is illegal in C++ D) stores the keyboard input into the variable pointed to by num3 E) None of these
D) stores the keyboard input into the variable pointed to by num3
This function accepts a pointer to a C-string as an argument, and it returns the length of the C-string (not including the null terminator). A) numchar B) strlength C) countstring D) strlen E) None of these
D) strlen
This function accepts pointers to two C-strings and an integer argument, which indicates how many characters to copy from the second C-string to the first. A) strintcpy B) copystring C) strcpy D) strncpy E) None of these
D) strncpy
Look at the following declaration. enum Tree { OAK, MAPLE, PINE }; In memory, what value will the MAPLE enumerator be stored as? A) 'M' B) "MAPLE" C) 2 D) 1.0 E) 1
E) 1
What will the following code output? int *numbers = new int[5]; for (int i = 0; i <= 4; i++) *(numbers + i) = i; cout << numbers[2] << endl; A) Five memory addresses B) 1 C) 3 D) 0 E) 2
E) 2
This data type can be used to create files and read information from them into memory. A) ifstream B) istream C) ofstream D) instream E) None of these
E) None of these
When you pass a pointer as an argument to a function, you must ________. A) dereference the pointer variable in the function prototype B) declare the pointer variable again in the function call C) use the #include <func_ptr.h> statement D) not dereference the pointer in the function's body E) None of these
E) None of these
Look at the following structure declaration. struct Circle { double centerX; double centerY; double radius; }; Assume that circle1 and circle2 are variables of the Circle type, and their members have been initialized. True/False: The following if statement correctly determines whether the two variables' members contain the same data: if (circle1 == circle2)
False
True/False: A function cannot modify the members of a structure.
False
True/False: The C++ compiler performs strict array bounds checking when it encounters an array of characters.
False
True/False: The ampersand (&) is used to dereference a pointer variable in C++.
False
True/False: The setprecision manipulator cannot be used to format data written to a file.
False
True/False: To write to a file, you use the file_write() function.
False
True/False: When used by itself, the ios::app flag causes the file's existing contents to be deleted if the file already exists.
False
True/False: When you store data in a variable, it is automatically saved in a file.
False
True/False: With pointer variables you can access, but you cannot modify, data in other variables.
False
This function concatenates the contents of one C-string with another C-string. A) stradd B) strappend C) strcat D) strcopy E) None of these
c) strcat