CPE 212 Quiz 1 Study Set
What are two methods used to indicate comments in a C++ program?
// & /* ,,, */
What type of class cannot be instantiated as an object?
Abstract
Used with pointers to objects
Arrow Operator
Which of the following operations are allowable aggregate operations on structures as a whole? a. Input/output (cin,court) b. Assignment c. Arithmetic d. Function returning value e. Comparison
Assignment & Function returning value
Where do virtual functions have to be declared?
Base Class
Used when an object is no longer needed
Destructor
For the C++ code segment shown, answer the below question: int num, sum = 100; float average; cout << "Enter in the value for num: "; cin >> num; try { if (num < 0) throw int(num); else if (num != 0) average = float(sum) / num; else throw string("Divide by zero error"); } catch (string errmsg) { cout << errmsg << endl; return 1; } catch (int value) { cout << "Cannot make an average with " << value << endl; return 1; } cout << "The average is " << average << endl; What is the output if the value entered for num is 0?
Divide by zero error
Used with object names to directly access members
Dot Operator
T or F? A class is perfect for POD structures.
False
T or F? All members of a structure must be the same DataType.
False
T or F? Constructors can be inherited from derived classes.
False
T or F? Linux has a built-in undo command.
False
T or F? Logical operators cannot take relational expressions as operands.
False
T or F? Member functions applied to an object cannot alter attributes by default.
False
T or F? The function parameters and their datatype are the same for virtual function in the derived class and the base class.
False
T or F? The makefile format is as follows: target: dependencies spaces commands
False
T or F? Virtual functions can be static.
False
T or F? When a continue statement is executed, the loop in which it occurs is exited.
False
What are the two main types of loops mentioned in class in the text?
Flag-Controlled & Count-Controlled
What is the full name of the gdb tool?
GNU debugger
Creates a branching structure where multiple derived classes inherit from a single base class
Hierarchical
A variable that is incremented each time a loop body is executed.
Iteration Counter
Used to process all components one at a time
Iterator
The period of time during program execution when an identifier has memory allocated to it.
Lifetime
An expression made up of logical values and operations that evaluates to a logical value of true or false.
Logical Expression
Forms a chain where a derived class inherits from another derived class, creating multiple levels of inheritance
Multilevel
A more complex pattern where one derived class inherits from multiple base classes
Multiple
Used to view the state of an object
Observer
Value parameters (passing by value) are used if a parameters data flow is ______.
One-way, into the function
The hierarchical relationship between classes with inheritance makes it easier to what? (Select all that apply). a. Organize and structure code logically b. Avoid redundant code c. Model real-world relationships d. Create duplicate code
Organize and structure code logically & Avoid redundant code & Model real-world relationships
Which of the following are valid access modifiers? Select all that apply. a. Public b. Private c. Protected d. Preserved
Public & Private & Protected
What is the output of the following code fragment? enum numbers {ONE=1, TWO, THREE, FOUR, FIVE}; int beta = 5; do { switch (beta) { case FIVE : case FOUR : cout << 'R'; break; case TWO : case THREE : cout << 'O'; break; case ONE : cout << 'L'; } beta--; } while (beta >= 0); cout << 'X';
RROOLX
Used to access static members or define member functions
Scope Resolution
The simplest form where one derived class inherits from a single base class
Single
What is contained in the variable str2 after the following code segment is executed? string str1 = "This-is-the-last-exam!"; string str2; str2 = string1.substr(str1.find('T'), 4);
This
Used to change the state of an object
Transformer
T or F? A class serves as a blueprint for creating objects by defining the attributes and functions that an object will have.
True
T or F? A function must be declared first before being called by other codes.
True
T or F? Constructors do not have a return type.
True
T or F? If a source file is modified, the corresponding object code file must be recompiled and relinked so the changes appear in the executable.
True
T or F? Linux is case sensitive.
True
T or F? The C++ compiler finds syntactic errors in a program.
True
T or F? The expression name.middleName would be used to access the middleName member of the structure variable name.
True
T or F? The prototype of virtual functions should be the same in the base as well as the derived class.
True
T or F? The statement cin.ignore(100,'\n'); skips characters on the standard input stream until the newline character is encountered or 100 characters have been skipped whichever occurs first.
True
T or F? Through inheritance, a derived class can override existing base class methods.
True
T or F? Type coercion is the implicit conversion of one data type to another.
True
T or F? Value parameters receive a copy of an arguments value.
True
T or F? You can set as many breakpoints as you want using gdb.
True
Reference parameters (passing by reference) are used if a parameters data flow is______.
Two-way, into and out of the function
A location in memory, referenced by an identifier, which contains a data value that can be changed.
Variable
What command is used to change your directory in Linux?
cd
Early binding refers to ______-time polymorphism.
compile
What command is used to list the contents of a directory in Linux?
ls
What utility program helps you compile, link, and maintain your program?
make
What command is used to remove an empty directory in Linux?
rmdir
Late binding refers to ______-time polymorphism.
run
What is the name of the header file required for using with strings?
string
What is the output for the following program? Place the answer in the grid provided. Notes: Pay attention to the index values used with the arrays and the loop order. #include <iostream> using namespace std; const int ROWS = 3; const int COLS = 4; typedef int IntArray[ROWS][COLS]; void init_array (IntArray); void print_array (const IntArray); int main() { IntArray my_array; init_array(my_array); print_array(my_array); return 0; } void init_array (IntArray my_array) { int row, col; for (row = 0; row < ROWS; row++) for (col = 0; col < COLS ; col++) my_array[row][col] = row + col } void print_array (const IntArray my_array) { int row, col; for (col = 0; col < COLS; col++) { for (row = 0; row < ROWS; row++) { cout << my_array[row][col]; } cout << endl; } }
0 1 2 1 2 3 2 3 4 3 4 5
Which of the following one is not an identifier in C++? a. x321 b. 0x321 c. x321_ d. _x321
0x321 (cannot begin w/ a digit)
string str1 = "CPE211□is□easy"; string str2 = "Second□line"; string str3; string::size_type num, Position; What is the output of the following program fragment listed below? Position = str1.find("e"); cout << Position;
10
string str1 = "CPE211□is□easy"; string str2 = "Second□line"; string str3; string::size_type num, Position; What is the output of the following program fragment listed below? num = str2.size(); court << num;
11
Write down the output of the code shown on the side. #include <iostream> using namespace std; void fun(int* a, int* b){ int* k; k=a; a=b; b=k; }; int main(){ int a=2004,b=9; int *x=&a *y=&b; fun(x,y); cout<<a<<""<<b<<endl; return 0; }
2004 9
What is the value output for sum in the following code segment? Note: the comment is correct. int sum = 0; int j = 1; do{ if(j%4 != 0) sum = sum + j; j++; }while(j < 8); cout << sum;
24
When the following code executes, how many iterations of the loop are performed? int numer = 1; bool notDone = false; do { number=number*2; notDone = (number <= 9); }while (notDone) ;
4
What is the output of the following code segment? The ASCII code of z is 122. #include <iostream> using namespace std; int main(){ char c = 'z'; cout << c-25; return 0; }
97
For the C++ code segment shown, answer the below question: int num, sum = 100; float average; cout << "Enter in the value for num: "; cin >> num; try { if (num < 0) throw int(num); else if (num != 0) average = float(sum) / num; else throw string("Divide by zero error"); } catch (string errmsg) { cout << errmsg << endl; return 1; } catch (int value) { cout << "Cannot make an average with " << value << endl; return 1; } cout << "The average is " << average << endl; What is the output if the value entered for num is -10?
Cannot make an average with -10
Used to create and initialize an object
Constructor
What is automatically called when an object is created?
Constructor
Which of the following statement is incorrect? a. Constructor can be inherited. b. Virtual function cannot be inherited. c. The derived class can inherit from multiple base classes. d. A friend function can access protected and private members of the class.
Constructor can be inherited.
What type of loop is shown below? int i = 0; while (i < 10) { cout << i; i = i+1; }
Count-Controlled
A loop that executes a specified number of times.
Count-Controlled Loop
How is a destructor declared?
~
string str1 = "CPE211□is□easy"; string str2 = "Second□line"; string str3; string::size_type num, Position; What is the output of the following program fragment listed below? str3 = str1.substr(6,10); cout << str3;
□is□easy□□
