Comsc 200 Final
1. A destructor receives no parameters. 2. A destructor does not return a value. D-) 1. False2. True C-) 1. True2. False B-) 1. False2. False A-) 1. True2. True
A.
A destructor receives no parameters. A destructor does not return a value. C-) 1. True2. False D-) 1. False2. True A-) 1. True2. True B-) 1. False2. False
A.
Which of the options below is equivalent to this->y? C-) (&this).y A-) *(this.y) D-) &(this.y) B-) (*this).y
B.
The & operator is used to dereference a pointer The * operator is the address operator A. 1. False 2. True B. 1. True 2. True C. 1. False 2. False D. 1. True 2. False
C.
Another name for a get function in a class is what? A.Destructor B. Mutator C. Constructor D.Accessor
D.
Which of the options below will print out all of the values in the array (1, 2, 3, 4 and 5)? const int SIZE = 5; int arr [5] = {1, 2, 3, 4, 5} A. int STAR ptr = &arr; for(int i=0; i<SIZE; i++) { cout<<STARptr<<endl; ptr++; } B. int STAR ptr = &arr; for(int i=0; i<SIZE; i++) { cout<<STARptr<<endl; (STARptr)++; } C. int STAR ptr = arr; for(int i=0; i<SIZE; i++) { cout<<STARptr<<endl; (STARptr)++; } D. int STARptr = arr; for(int i=0; i<SIZE; i++) { cout<<STARptr<<endl; ptr++; }
D.
double val = 55.2; double STAR ptr = &val; For which of the options below will BOTH cout statements print out the ADDRESS of val? A.cout<<STARptr<<endl; cout<<&val<<endl; B. cout<<STARptr<<endl; cout<<STARval<<endl; C.cout<<ptr<<endl; cout<<*val<<endl; D. cout<<ptr<<endl; cout<<&val<<endl;
D.
int x=5, STARptr = nullptr; ptr = &x; ptr = 100; // Store 100 in x cout << x << endl; What is/are the error(s) in the code shown above? A. Line 2 should be STARptr = &x; Line 3 should be STARptr = 100; B. Line 2 should be STARptr = *x; Line 3 should be STARptr = 100; C. Line 2 should be STARptr = &x; D. Line 3 should be STARptr = 100;
D.
return Coord(C1.x + C2.x, C1.y + C2.y); The above is an implementation of: 1. Operator _ 2. As a _ function A-) 1.. += 2.. Member C-) 1.. + 2.. Member D-) 1.. + 2.. Friend B-) 1.. += 2.. Friend
D.
When working with primitive types (such as integers), the + operator has higher precedence than the ^ operator. For example: int main() { int a, b=1, c=2, d=3; a = b^c+d; } In the above program, the expression c+d will be evaluated first. Suppose the Coord class has implemented operator^ to do exponentiation as follows: Coord Coord::operator^(const Coord &c){ return Coord(pow(x, c.x), pow(y, c.y));} int main() { Coord C1(1, 1), C2(1, 1), C3(1, 1); cout<< C3+2^C1^2+C2 <<endl; } What is the output of this program? A-) (4, 4) B-) (6, 6) D-) (27, 27) C-) (10, 10)
D.
Suppose there is a class named Computer that is supposed to overload the >> operator. Which of the options below is the correct prototype for the overloaded >> operator? A-) istream& operator>>(const istream &input, const Computer &comp); C-) istream& operator>>(const istream &input, Computer &comp); D-) istream& operator>>(istream &input, const Computer &comp); B-) istream& operator>>(istream &input, Computer &comp);
B.
1. Composition is referred to as a "is-a" relationship. 2. Suppose we have defined a class named Student. One of the member variables in the Student class is for the student's firstname, of type String. This is an example of composition. A. 1. True 2. True B. 1. False 2. False C. 1. False 2. True D. 1. True 2. False
C.
1. Composition is referred to as a "is-a" relationship. 2. Suppose we have defined a class named Student. One of the member variables in the Student class is for the student's firstname, of type String. This is an example of composition. A. 1. True 2. False B. 1. True 2. True C.1. False 2. True D.1. False 2. False
C.
1. If a copy constructor is not written out in a class, then a default copy constructor is provided. 2. If an overloaded assignment operator is not written out in a class, then a default overloaded assignment operator is provided. A.1. False 2. False B.1. False 2. True C. 1. True 2. True D.1. True 2. False
C.
1. Static member variables in a class can be accessed in non-static const member functions. 2. Non-static member variables in a class can be accessed in static member functions. A. 1. False 2. True B. 1. False 2. False C. 1. True 2. False D. 1. True 2. True
C.
All of the following options below can have default arguments EXCEPT: A.Public member function B. Constructor C. Destructor D. Private member function
C.
Both the + operator and += operator are overloaded in the Coord class. The Coord class has two private member variables, x and y, which both represent coordinates. One possible way to implement the += operator is to have it call the + operator function and the = operator function. This is possible because if C1 and C2 are both Coord objects, the statement C1+=C2 is equivalent to C1=C1+C2. The body of the operator+= function would then look like this: *this = *this + c; return *this; And if the application program has the following code: int main() { Coord C1(1, 2), C2(3, 4); C1+=C2; } Initially, C1.x=1, C1.y=2, C2.x=3, and C2.y=4. After executing the C1+=C2 statement, C1.x=4 and C1.y=6. Which of the options below is the correct prototype for the operator+= function in the Coord class? A.Coord& Coord::operator+=(Coord &c) B. Coord* Coord::operator+=( const Coord &c ) C. Coord& Coord::operator+=( const Coord &c ) D. Coord* Coord::operator+=(Coord &c)
C.
In a UML diagram, which of the options below 1) Describes a function that can be accessed anywhere - both inside of the class and outside of the class (such as in main) and 2) Returns an integer? A. -some_name(some_value: int) B. +some_name(some_value: int) C. +some_name(): int D. -some_name(): int
C.
Suppose a program has a Car class: class Car { private: string model; }; Which of the options below is considered a dangerous reference return? D-) string* set_model(string); B-) Car* set_model(string); C-) string& set_model(string); A-) Car& set_model(string);
C.
Suppose a program has the following Circle class: class Circle: { private: double radius; }; Which of the following is the correct explicit usage of the this pointer? B-) void set_radius(double radius) { radius = *this->radius ; } C-) void set_radius(double radius) { this->radius = radius; } D-) void set_radius(double radius) { *this->radius = radius; } A-) void set_radius(double radius) { radius = this->radius; }
C.
Suppose a program has the following Course class: class Course { private: string instructor; string textbook; }: And suppose there is only going to be ONE constructor for this class to handle all initializations. Which of the following options below is the correct prototype for the constructor of this class? A.Course(string = "", string = "", string = ""); B. Course(); C.Course(string = "", string = ""); D.Course(string = "");
C.
Suppose a program has the following Date class: class Date { private: int day; int month; int year; }; Suppose we want to be able to use member functions set_day, set_month, and set_year in cascaded member function calls. In particular, in the application program it should be possible to do: dptr->set_day(1)->set_month_(12)->set_year(1970); Where dptr is a pointer to a Date object. Which of the options below contains the correct prototype for member function set_day? B-) int& set_day(int); C-) Date* set_day(int); A-) int* set_day(int); D-) Date& set_day(int);
C.
Suppose we want to be able to use the member functions set_CPU, set_RAM, and set_GPU in cascaded member function calls for a computer object. For example, we want to be able to do things like: Computer comp; comp.set_CPU("Intel").set_RAM("Corsair").set_GPU("Nvidia"); Which of the options below is the correct implementation of the set_CPU function? C-) Computer& Computer::set_cpu(string man) { manufacturer = man; return this; } A-) Computer* Computer::set_cpu(string man) { manufacturer = man; return this; } B-) Computer* Computer::set_cpu(string man) { manufacturer = man; return *this; } D-) Computer& Computer::set_cpu(string man) { manufacturer = man; return *this; }
D.
What is the default access specifier in a class? A. Global B.Public C.local D. private
D.
What is the relationship between throw, try, and catch? A. Throw signals that an exception has occurred Try handles an exception Catch contains code that could possibly cause an exception B. Throw handles an exception Try contains code that could possibly cause an exception Catch signals that an exception has occurred C. Throw handles an exception Try signals that an exception has occurred Catch contains code that could possibly cause an exception D. Throw signals that an exception has occurred Try contains code that could possibly cause an exception Catch handles an exception
D.
What is the return type of operator+ in the Coord class? A-) const Coord& C-) Coord& D-) Coord B-) const Coord
D.
Suppose we have the following code in an application program that uses the Time class: int main() { Time T1{1, 2, 3}; Time T2{T1}; Time T3{4, 5, 6}; T3 = T2; } 1. The line Time T2{T1}; invokes the overloaded assignment operator. 2. The line T3 = T2; invokes the copy constructor. A. 1. True 2. False B. 1. True 2. True C. 1. False 2. True D. 1. False 2. False
D.
Suppose we have the following code in an application program that uses the Time class: int main() { Time T1{1, 2, 3}; Time T2{T1}; Time T3{4, 5, 6}; T3 = T2; } 1. The line Time T2{T1}; invokes the overloaded assignment operator. 2. The line T3 = T2; invokes the copy constructor. A. 1. True 2. False B.1. False 2. True C.1. True 2. True D.1. False 2. False
D.
For operator+ in the Coord class, all of the following are possible valid ways to overload the + operator to add a Coord object and an integer together EXCEPT: A.integer + Coord object (member function) B. Coord object + integer (member function) C. Coord object + integer (friend function) D. integer + Coord object (friend function)
A.
Static member variables cannot be accessed by non-static member functions. The this pointer is passed to static member functions. A-)1. False2. False D-)1. True2. False B-)1. True2. True C-)1. False2. True
A.
Suppose a House class has a static member variable count, and a static member function get_count. Which of the options below is the correct implementation of the get_count function? D-) unsigned int House::get_count() const { return this->count; } B-) unsigned int House::get_count() const { return count; } A-) unsigned int House::get_count() { return count; } C-) unsigned int House::get_count() { return this->count; }
A.
Suppose a Rectangle class has a member function named isEqualTo, which will compare two rectangle objects to see if they are equal to one another. The function returns true if the two Rectanagle objects are equal to one another, otherwise it returns false. If we have Rectangle objects r1 and r2, then the following is an example of how we could call the function: r1.isEqualTo(r2); Which of the options below is the correct function header for the isEqualTo function in the Rectangle class? A. bool Rectangle::isEqualTo(const Rectangle& r) const B. bool Rectangle::isEqualTo(const Rectangle& r) C. bool Rectangle::isEqualTo(Rectangle& r) D. bool Rectangle::isEqualTo(Rectangle& r) const
A.
Suppose a class named Factory has overloaded the == operator, and now we want to overload the != operator in such a way that the overloaded != operator calls the overloaded == operator. The header of this function is: bool Factory::operator!=(const Factory &f) const Which of the following options below is the correct body of this function? A-) return !(STARthis == f); B-) return !(STARthis == &f); D-) return !(this == &f); C-) return !(this == f);
A.
Suppose a program has the following array defined: int arr[12]; Which of the options below uses pointer notation to store 99 in arr[6]? A. STAR(arr+6) = 99; B. &arr+6 = 99; C. &(arr+6) = 99 D. STARarr+6 = 99;
A.
Suppose a program has the following class and main function: NOTE: Access specifiers have been omitted here because there is another question on this quiz about them. class College { string name; string get_name() { return name; } void set_name(string n) { name = n; } }; int main() { College college_obj; return 0; } On which line in the above program would it be appropriate to insert the word "const" ? A.string get_name() B. College college_obj; C. void set_name(string n) D. string name;
A.
Suppose a program has the following three (3) files: A.h: class A{ A(int a_value) : a{a_value}{ cout<<"A constructor\n"; } ~A(){ cout<<"A destructor\n"; } int a; }; B.h: class B{ B(const A& A_obj_value, int b_value) : A_obj{A_obj_value}, b{b_value} { cout<<"B constructor\n"; } ~B(){ cout<<"B destructor\n"; } A A_obj;int b;}; main.cpp: int main(){A{1};B{A, 2}; return 0;} NOTE: Some of the code -- such as access specifiers and include statements -- is not shown. What is the output of the program? A. A constructor B constructor B destructor A destructor A destructor B. A constructor A constructor B constructor B destructor A destructor A destructor C. A constructor B constructor A destructor A destructor B destructor D. A constructor A constructor B constructor A destructor A destructor B destructor
A.
Suppose a program has the following two (2) files: Rectangle.h: class Rectangle { Rectangle(double length_value, double width_value, double area_value) : length{length_value}, width{width_value}, area{area_value} { } void set_length(double length_value) { length = length_value; } double get_length() { return length; } void set_width(double width_value) { width = widh_value; } double get_width() { return width; } void set_area(double area_value) { area = area_value; } double get_area() { return area; } void calc_area() { area = length * width; } double length; double width; double area; }; main.cpp: int main() { Rectangle R{5.0, 2.0, 10.0}; cout<<"Area: "<<R.get_area()<<endl; R.set_length{7.0}; R.set_width{3.0}; R.set_area(R.get_length() * R.get_width()); R.calc_area(); cout<<"Area: "<<R.get_area()<<endl; R.set_area(15.0); cout<<"Area: "<<R.get_area()<<endl; return 0; } NOTE: Some of the code -- such as access specifiers and include statements -- is not shown. 1. At the end of the application program (i.e., right before return 0;), the value of R.area is NOT equal to R.length * R.width. 2. Another way this Rectangle class could be implemented is as follows: remove the area member variable, remove the area_value parameter from the constructor and the area{area_value} statement, remove the set_area member function, and remove the calc_area member function. And change the implementation of the get_area member function to the following: double get_area() {return length * width;} Then, remove all calls to the set_area and calc_area functions from the application program. A. 1. True 2. True B.1. False 2. True C.1. False 2. False D.1. True 2. False
A.
Suppose there are two pointers, ptr1 and ptr2. Both are pointers to integers. if(ptr1 == ptr2) cout<<"Same A"<<endl; else cout<<"Different A"<<endl; if(STARptr1 == STARptr2) cout<<"Same B"<<endl; else cout<<"Different B"<<endl; All of the following combinations of output messages are possible EXCEPT: A. Same A Different B B. Different A Same B C. Same A Same B D. Different A Different B
A.
Suppose there is a class named Course with member variable num_of_students: class Course { Private: int num_of_students; } This class is supposed to have an overloaded ++ (increment) operator to increment num_of_students for any Course object. Which of the following options below is the corrrect prefix ++ operator implemented as a member function? B-) Course& operator++(Course &c){c.num_of_students+=1;return c;} C-) Course Course::operator++(){num_of_students+=1;return *this;} A-) Course& Course::operator++(){num_of_students+=1;return *this;} D-) Course operator++(Course &c){c.num_of_students+=1;return c;}
A.
Suppose we want to model the following relationship between a Person class, Computer class, and CPU class: Which of the options below contains the correct class declarations? HINT: With a true composition relationship, a class should directly have a member variable of the other classes's type. B-) class CPU { private: string manufacturer; } class Computer { private: string manufacturer; CPU *cpu; } class Person { private: string name; Computer *computer; } D-) class Person { private: string name; } class Computer { private: string manufacturer; Person *person; } class CPU { private: string manufacturer; Computer *computer; } A-) class CPU { private: string manufacturer; } class Computer { private: string manufacturer; CPU cpu; } class Person { private: string name; Computer computer; } C-) class Person { private: string name; } class Computer { private: string manufacturer; Person person; } class CPU { private: string manufacturer; Computer computer; }
A.
The & operator is used to dereference a pointer The * operator is the address operator A. 1. False 2. False B. 1. True 2. True C. 1. True 2. False D. 1. False 2. True
A.
The default constructor takes _ argument(s) a. zero (0) b. two (2) c. one (1) d. three (3)
A.
With the way the assignment operator was overloaded in the Coord class, all of the options below are allowed EXCEPT: D-) (C1 = C2 = C3 = C4); B-) C1 = C2 = (C3 = C4); A-) (C1 = C2) = (C3 = C4); C-) (C1 = (C2 = (C3 = C4)));
A.
Suppose there are two pointers, ptr1 and ptr2. Both are pointers to integers. if(ptr1 == ptr2) cout<<"Same A"<<endl; else cout<<"Different A"<<endl; if(*ptr1 == *ptr2) cout<<"Same B"<<endl; else cout<<"Different B"<<endl; All of the following combinations of output messages are possible EXCEPT: A. Different A Same B B. Same A Different B C.Different A Different B D.Same A Same B
B.
#include <iostream> #include "Tree.h" using namespace std; void tree_func(); Tree A; Tree B; int main() { { tree_func(); static Tree C; } Tree D; return 0; } void tree_func() { static Tree E; { Tree F; } } What is the order in which the objects are destroyed? 1. _ is destroyed first. 2. _ is destroyed second. 3. _ is destroyed third. 4. _ is destroyed fourth. 5. _ is destroyed fifth. 6. _ is destroyed sixth. A. 1. E 2. F 3. C 4. D 5. A 6. B B. 1. F 2. D 3. C 4. E 5. B 6. A C. 1. D 2. C 3. F 4. E 5. B 6. A D. 1. F 2. E 3. D 4. C 5. B 6. A
B.
#include <iostream> #include "Tree.h" using namespace std; int main() { { Tree A; Tree B } Tree C; Tree D: } What is the order in which the objects are destroyed? _ is destroyed first. _ is destroyed second. _ is destroyed third. _ is destroyed fourth. D-) 1.. C 2.. D 3.. A 4.. B C-) 1.. D 2.. C 3.. B 4.. A A-) 1.. A 2.. B 3.. C 4.. D B-) 1.. B 2.. A 3.. D 4.. C
B.
1. The destructor for any object is invoked when the main function goes out of scope. 2. While the destructor is running the memory held by the object is released. A-) 1. True2. True C-) 1. True2. False B-) 1. False2. False D-) 1. False2. True
B.
A utility function is usually a public member function in a class. A utility function is designed to help another member function in the class perform its task. A. 1. True 2. False B. 1. False 2. True C.1. True 2. True D.1. False 2. False
B.
Constructors are called for _ objects first. B-) global C-) static A-) constant D-) local
B.
Constructors are called for _ objects first. D-) local C-) static A-) constant B-) global
B.
In a UML diagram, which of the options below 1) Describes a function that can be accessed anywhere - both inside of the class and outside of the class (such as in main) and 2) Returns an integer? A. +some_name(some_value: int) B. +some_name(): int C. -some_name(): int D. -some_name(some_value: int)
B.
Suppose a program has the following array: [1, 2, 3] The goal of the program is to print the following: The contents of the array in reverse order AND The contents of the array in forward order So the output of the program would be: 3 2 1 1 2 3 Which of the options below is the correct implementation of the program? D-) int arr[SIZE] = {1, 2, 3}; int *ptr = &arr[SIZE-1]; for(int i=0; i<size; i++) cout<<*(ptr-i)<<endl; ptr++; for(int i=0; i<SIZE; i++) { cout<<*ptr<<endl; ptr++; } A-) int arr[SIZE] = {1, 2, 3}; int *ptr = &arr[SIZE-1]; for(int i=0; i<SIZE; i++) { cout<<*ptr<<endl; ptr--; } ptr++; for(int i=0; i<size; i++) cout<<*(ptr+i)<<endl; B-) int arr[SIZE] = {1, 2, 3}; int *ptr = &arr[SIZE-1]; for(int i=0; i<size; i++) cout<<*(ptr-i)<<endl; ptr--; for(int i=0; i<SIZE; i++) { cout<<*ptr<<endl; ptr++; } C-) int arr[SIZE] = {1, 2, 3}; int *ptr = &arr[SIZE-1]; for(int i=0; i<SIZE; i++) { cout<<*ptr<<endl; ptr--; } ptr--; for(int i=0; i<size; i++) cout<<*(ptr+i)<<endl;
B.
Suppose a program has the following class and main function: NOTE: Access specifiers have been omitted here because there is another question on this quiz about them. class College { string name; string get_name() { return name; } void set_name(string n) { name = n; } }; int main() { College college_obj; return 0; } On which line in the above program would it be appropriate to insert the word "const" ? A. void set_name(string n) B. string get_name() C. string name; D. College college_obj;
B.
Suppose a program has the following class: class Computer { private: string gpu; public: void set_gpu(string g) { gpu = g; } }; And the following driver program: int main { Computer comp; Computer &compref = comp; Computer *compptr = ∁ } For which of the options below are BOTH statements 1 AND 2 correct for setting the gpu member variable to the string "NVIDIA GeForce GTX 1080" for the comp object? A. compref.set_gpu("NVIDIA GeForce GTX 1080"); compptr.set_gpu("NVIDIA GeForce GTX 1080"); B. compref.set_gpu("NVIDIA GeForce GTX 1080");compptr->set_gpu("NVIDIA GeForce GTX 1080"); C. compref->set_gpu("NVIDIA GeForce GTX 1080"); compptr.set_gpu("NVIDIA GeForce GTX 1080"); D. compref->set_gpu("NVIDIA GeForce GTX 1080"); compptr->set_gpu("NVIDIA GeForce GTX 1080");
B.
Suppose a program has the following class: class Date{ private:int day;int month;int year;public:void set_date(int, int, int);void set_day(int);void set_month(int);void set_year(int); }; void Date::set_date(int d, int m, int y){ set_year(y); set_month(m); set_day(d); } void Date::set_day(int d){if(d >=1 && d<=31)day = d; elsethrow invalid_argument("invalid day"); } void Date::set_month(int m){if(m >=1 && m<=12)month = m; elsethrow invalid_argument("invalid month"); } void Date::set_year(int y){if(y >=1 && y<=2017)year = y; elsethrow invalid_argument("invalid year"); } And the following driver program: int main(){ Date d; try{d.set_date(32, 13, 2018); } catch (invalid_argument &e){cout<<"EXCEPTION: "<<e.what() << endl; } } What is the output of this program? A.All of the above B. EXCEPTION: invalid day C. EXCEPTION: invalid year D. EXCEPTION: invalid month
B.
Suppose there is a class named Gas_Pedal, which represents a gas pedal in a car. The Gas_Pedal class has a member function named apply_gas_pedal, which takes in an integer (0 - 100) as an argument. The prototype of this member function is: void apply_gas_pedal(int); The integer passed to the function (0 - 100) represents the degree of force applied to the gas pedal (i.e., how hard the gas pedal is being pressed down). The larger the number, the more force is applied to the gas pedal. For example, apply_gas_pedal(0) represents the case were the gas pedal is not being pressed down on at all (i.e., the car is not moving). apply_gas_pedal(100) represents the case were the gas pedal is being pressed down all the way (i.e., the car is traveling at it's maximum speed). Suppose there is also a class named Car. The Car class has a member function named increase_speed, which takes in an integer (0 - 100) as an argument. The prototype of this member function is: void increase_speed(int); The integer passed to the function (0 - 100) represents the degree to which the car's speed is increased. The larger the number, the more the car's speed is increased. For example, increase_speed(0) would not increase the car's speed at all (i.e., the car would continue traveling at it's current speed). increase_speed(100) would bring the car to it's maximum speed. Which of the options below shows the correct relationship between the apply_gas_pedal and increase_speed functions from the Gas_Pedal and Car classes, respectively? A. void Car::increase_speed(int amount) { gas_pedal->apply_gas_pedal(amount); } B. void Car::increase_speed(int amount) { gas_pedal.apply_gas_pedal(amount); } C. void Gas_Pedal::apply_gas_pedal(int amount) { car.increase_speed(amount); } D. void Gas_Pedal::apply_gas_pedal(int amount) { car->increase_speed(amount); }
B.
The size of an object depends on the amount of memory required to store the class's what? A. Constructors B. Variables C. Functions D. All of the above
B.
The size of an object depends on the amount of memory required to store the class's what? A.Constructors B. Variables C.Functions D.All of the above
B.
Which of the following can use a member initializer list? A. Get function B. Constructor C. Set function D. Object
B.
Which of the following is like a blueprint or template that you can use to create things from? a. funciton b. class c. constructor d. object
B.
Which of the options below contains the correct prototypes for BOTH of the overloaded [] operators in the array class? D-)int operator[](int);int operator[](int) const; A-)int operator[](int);int& operator[](int) const; C-)int& operator[](int);int& operator[](int) const; B-)int& operator[](int);int operator[](int) const;
B.
Which of the options below shows the correct way to setup an include guard in a class named Rectangle? NOTE: The code for the Rectangle class is not shown here. This question is about the correct order of the three statements to make the include guard. A. 1. #ifndef RECTANGLE_H 2. #endif 3. #define RECTANGLE_H B. 1. #ifndef RECTANGLE_H 2. #define RECTANGLE_H 3. #endif C. 1. #define RECTANGLE_H 2. #endif 3. #ifndef RECTANGLE_H D. 1. #define RECTANGLE_H 2. #ifndef RECTANGLE_H 3. #endif
B.
class Course { private: string course_name; public: void set_course_name(const string &cn) { course_name = cn; } } What is the type of the hidden this pointer in the set_course_name function? B-) Course* const D-) Course* C-) const Course* const A-) const Course*
B.
int arr[5] = {10, 15, 20, 25, 30}; int *ptr = arr; Which of the options below uses pointer subscript notation? A. STAR(ptr+2) = 1337; B. ptr[2] = 1337; C. arr[2] = 1337; D. STAR(arr+2) = 1337
B.
int main { Coord C1(93, 44); cout<<C1--; cout<<C1 cout<<-C1; cout<<C1; } What is the output of the above program? C-) (92, 43) (92, 43)(-92, -43) (92, 43) A-) (92, 43) (92, 43)(-92, -43) (-92, -43) D-) (93, 44) (92, 43)(-92, -43) (-92, -43) B-) (93, 44) (92, 43)(-92, -43) (92, 43)
B.
Suppose there is a class named Person which has a static member count, and a static member function get_count. Which of the options below shows the way that get_count would typically be called? D-) int main() { Person p; cout << Person::p.get_count() < < endl; } C-) int main() { Person p; cout << p.Person::get_count() < < endl; } B-) int main() { cout << Person::get_count() < < endl; } A-) int main() { Person p; cout << p.get_count() < < endl; }
B>
Suppose a program has the following House class (implementation details are omitted): class House { int num_of_bedrooms; House(); House(int b); void set_num_of_bedrooms(int b); int get_num_of_bedrooms(); }; And for each House object that is created, it needs to be guaranteed that the num_of_bedrooms is at least 1. In other words, input validation logic is needed to make sure that num_of_bedrooms is always at least 1. If code in the application program (i.e., in main) attempts to set num_of_bedrooms to less than 1, the input validation logic will detect this and simply set num_of_bedrooms to 1, and display an error message to the user that the number of bedrooms must be at least 1. Where in the House class would it be appropriate to place this input validation logic? A.House(int b) B. House() C. void set_num_of_bedrooms(int b) D. int get_num_of_bedrooms()
C.
Suppose a program starts by defining the following: const short int SIZE = 4; short int arr[SIZE] = {15, 30, 45, 60}; short int *ptr = &arr[0]; And suppose the array is stored in RAM (memory) as follows: Address Value 00000000 15 00000002 30 00000004 45 00000006 60 Then the program continues: for(short int i=0; i<SIZE: i++) cout<<*ptr+i<<endl; What is the output of the program? B-) 00000000 00000002 00000004 00000006 D-) 15 30 45 60 C-) 15 16 17 18 A-) 00000000 00000001 00000002 00000003
C.
Suppose there is a Class named Car, which has a member function named set_make that can be used to set the make of a car object to a particular value (e.g. "Toyota", Ford", "Hyundai", etc.): NOTE: Access specifiers have been omitted here because there is another question on this quiz about them. class Car { string make; void set_make(string m) { make = m; } string get_make() { return make; } }; Then in main we have the following code: int main { string value = "Toyota"; Car car_obj; ................ return 0; } Which line of code could be inserted in main below the line Car car_obj; to call the set_make function for the car_obj object with the argument "Toyota"? a. set_make(car_obj->value); b. car_obj->set_make(value); c. car_obj.set_make(value); d. set_make(car_obj.value);
C.
Suppose there is a class named Computer, which can be used to create objects that store information about a particular computer. This class is developed by the class developer. A different person, the application developer, needs to use the Computer class in their application. However, as described above, the application developer did NOT develop the class - they are just using it. The application code is in a file named Main.cpp. In this scenario, the application developer would normally have access to all of the following files EXCEPT: A. Main.exe B. Main.obj C. Computer.cpp D. Computer.h
C.
Suppose we have the following stored in RAM (memory): Where for each row in the table, the address column lists a hexadecimal memory address, and the value column lists the value that is stored at that memory location. For example, the value 55 is stored at memory location 0X1234ABCD. What is the output of the following cout statements? cout<<&ptr<<endl; cout<<ptr<<endl; A. 0X1234ABCD 0XFABC7890 B. 55 0X1234ABCD C. 0XFABC7890 0X1234ABCD D. 0XFABC7890 55
C.
Suppose we have the following stored in RAM (memory): Where for each row in the table, the address column lists a hexadecimal memory address, and the value column lists the value that is stored at that memory location. For example, the value 55 is stored at memory location 0X1234ABCD. What is the output of the following cout statements? cout<<&ptr<<endl; cout<<ptr<<endl; A. 0XFABC7890 55 B. 55 0X1234ABCD C. 0XFABC7890 0X1234ABCD D. 0X1234ABCD 0XFABC7890
C.
The doubleVal function is supposed to be passed a pointer to an integer, and it doubles the value of the number. Which of the options below is the correct implementation of the doubleVal function? A. void doubleVal(int &ptr) { &ptr *= 2; B. void doubleVal(int *ptr) { &ptr *= 2; } C. void doubleVal(int *ptr) { STARptr *= 2; } D.void doubleVal(int &ptr) { STARptr *= 2; }
C.
The doubleVal function is supposed to be passed a pointer to an integer, and it doubles the value of the number. Which of the options below is the correct implementation of the doubleVal function? A. void doubleVal(int &ptr) { STARptr *= 2; } B. void doubleVal(int STARptr) { &ptr *= 2; } C. void doubleVal(int STARptr) {STARptr *= 2; } D. void doubleVal(int &ptr) { &ptr *= 2;
C.
What is the name of a constructor that calls another constructor? A-) Overloaded constructor D-) Explicit constructor C-) Delegating constructor B-) Default constructor
C.
When a function is declared a friend by a class, it becomes a member of that class. An entire class may be declared a friend of another class. C-)1. False2. True B-)1. True2. True D-)1. True2. False A-)1. False2. False
C.
When a function is declared a friend by a class, it becomes a member of that class. An entire class may be declared a friend of another class. C-)1. False2. True D-)1. True2. False A-)1. False2. False B-)1. True2. True
C.
Which of the following can be used to initialize an object when it is declared in an application program? A. Private Constructor B. Private Member Function C. Public Constructor D.Public Member Function
C.
Which of the following can be used to initialize an object when it is declared in an application program? A. Private Member Function B. Public Member Function C. Public Constructor D. Private Constructor
C.
Which of the following can be used to initialize an object when it is declared in an application program? A. Public Member Function B. Private Member Function C. Public Constructor D. Private Constructor
C.
Which of the following operators MUST be overloaded as a friend function? A-) += C-) << B-) () D-) []
C.
Which of the following options below will print out the addresses of all of the elements of an array? A. for(int i=0; i<SIZE; i++) cout<<&(arr+i)<<endl; B. for(int i=0; i<SIZE; i++) cout<<*(arr+i)<<endl; C. for(int i=0; i<SIZE; i++) cout<<&arr[i]<<endl; D. for(int i=0; i<SIZE; i++) cout<<*arr[i]<<endl;
C.
Which of the following options below will print out the addresses of all of the elements of an array? A. for(int i=0; i<SIZE; i++) cout<<*arr[i]<<endl; B. for(int i=0; i<SIZE; i++) cout<<*(arr+i)<<endl; C. for(int i=0; i<SIZE; i++) cout<<&arr[i]<<endl; D.for(int i=0; i<SIZE; i++) cout<<&(arr+i)<<endl;
C.
Suppose there is a class named Ship that has overloaded the >> operator. The following code is in the application program: Ship s1, s2; cin >> s1 >> s2; What do the function calls to operator>> look like? A-) s2.operator>>(cin.operator>>(s1)); B-) s2.operator>>(s1.operator>>(cin)); D-) operator>>(operator>>(cin, s1), s2); C-) operator>>(s2, operator>>(s1, cin));
D.
... (header omitted) :size(arr.size), ptr(arr.ptr) { } The code shown above is part of the implementation of what from the Array class (shallow copy version)? C-) default constructor D-) copy constructor B-) operator= function A-) operator[] function
D.
A swap function works as follows: It takes in two pointers as arguments. Both pointers point to integers. The values of the two pointers are swapped. For example if num1 is initially 5 and num2 is initially 10, then num1=10 and num2=5 after the swap function has finished executing. NOTE: Assume the following code is in main: int num1=10, int num2=5; swap(&num1, &num2); Which of the options below is the correct implementation of the swap function? A. void swap(int STARx, int STARy) { int temp; temp = &x; STARx = &y; STARy = temp; } B. void swap(int STARx, int STARy) { int STARtemp = nullptr; STARtemp = STARx; STARx = STARy; STARy = STARtemp; } C. void swap(int STARx, int STARy) { int STARtemp = nullptr; STARtemp = &x; STARx = &y; STARy = &temp; } D. void swap(int STARx, int STARy) { int temp; temp = STARx; STARx = STARy; STARy = temp; }
D.
Friendship is symmetric (if A is a friend of B, this also means B is a friend of A). Friendship is transitive (if A is a friend of B and B is a friend of C, this also means A is a friend of C). C-)1. True2. True D-)1. False2. False A-)1. True2. False B-)1. False2. True
D.
In the Coord class, suppose we wanted to implement operator- (subtraction) in such a way that it uses both operator+ and operator- (unary minus). Which of the options below implements operator- (subtraction) in this way as a friend function that subtracts one Coord object from another? A-) return -(*this + C); D-) return C1 + -C2; B-) return *this + -C; C-) return -(C1 + C2);
D.
One of the concepts we learned about early in chapter 3 is data hiding. Which of the terms below refers to data hiding? A. Polymorphism B. Instantiation C. Inheritance D. Encapsulation
D.
Suppose a program has the following College class: class College { std::string college_name; void set_college_name(std::string c); std::string get_college_name(); }; The functions will be implemented in another file outside of the class definition. Which of the options below is the correct way to implement the set_college_name function? A. void::College set_college_name(string c) { college_name = c; } B. void::set_college_name College(string c) { college_name = c; } C. void set_college_name::College(string c) { college_name = c; } D. void College::set_college_name(string c) { college_name = c; }
D.
Suppose a program has the following class header: class A { public: int B() const; int C(); } And the following application program: int main(){ A a1; const A a2; } Which of the options below will cause the program to not compile if it is included in the application program? C-) a2.B(); A-) a1.B(); D-) a2.C(); B-) a1.C();
D.
Suppose a program has the following three (3) files: Car.h: class Car { Car(string &make_value, string & model_value, int year_value) : make{make_value}, model{model_value}, year{year_value} { } string make; string model; int year; }; Person.h: class Person { Person(string &firstname_value, string &lastname_value, int age_value, Car &car_obj_value) : firstname{firstname_value}, lastname{lastname_value}, age{age_value}, car_obj{car_obj_value} { } string firstname; string lastname; int age; Car car_obj; }; main.cpp: int main() { Car C{"Toyota", "Corolla", 2021}; Person P{"Bruce", "Wayne", 45, C}; return 0; } NOTE: Some of the code -- such as access specifiers and include statements -- is not shown. How many times is the default copy constructor in the Car class called when we create the object P in main.cpp? A. 2 B. 3 C. 4 D. 1
D.
Suppose there are two classes, Bedroom and House. Which of the options below shows the correct relationship that exists between these two classes? A. class Bedroom { private: vector<House*> house; } B. class Bedroom { private: vector<House> house; } C. class House { private: vector<Bedroom*> bedroom; } D. class House { private: vector<Bedroom> bedroom; }
D.
Suppose there is a class named House with member variable num_of_bedrooms: class House { private: int num_of_bedrooms; } This class is supposed to have an overloaded -- (decrement) operator to decrement num_of_bedrooms for any House object. Which of the following options below is the postfix -- operator implemented as a friend function? A-) House& House::operator--(int) { House temp = *this; num_of_bedrooms-=1; return temp; } D-) House operator--(House &h, int) { House temp = h; h.num_of_bedrooms-=1; return temp; } B-) House House::operator--(int) { House temp = *this; num_of_bedrooms-=1; return temp; } C-) House& operator--(House &h, int) { House temp = h; h.num_of_bedrooms-=1; return temp; }
D.