Sie sind auf Seite 1von 9

C++ Programming Today 2nd Edition

Supplemental Multiple Choice Questions

Chapter 7

C++ Programming Today 2nd Edition Supplemental Multiple Choice Questions Chapter 7 Note: Some items have several questions for 56 Total Questions a given block of code. File: Ch7_MC_Q.doc Questions Only
Which statement is true regarding the principles of an object-oriented language? A. Persistence is not an optional object-oriented language requirement. B. Inheritance does not occur when a new class is derived from an existing class or base class. C. Encapsulation means hiding data in a class from other classes. D. Class variables should not be global so all elements of the program can see them. Which statement is true about classes? A. The class declaration should be contained in a .cpp file. B. An error will occur if the function is written within the class declaration. C. The class function definitions (source code) should be placed in the .cpp file. D. Class declarations and definitions (source code) should not be separated into different files. When defining a class member function, the compiler needs to know which class owns a function. Which operator is used to assign ownership to a class? A. right arrow -> B. scope :: C. indirection * D. address & Which statement is true? A. Get and Set are C++ keywords. B. Functions that use the word Set in their name usually return information from a function. C. Functions that use the word Get in their name usually return information from a function. D. None of the above. Which statement is true about class constructors? A. Constructors must be called in main. B. Constructors are automatically called when an object is created. C. Constructors are used to get information from object variables. D. Constructors cannot be overloaded. Which statement is true about destructors? A. Destructors may be used to close a data file. B. Destructors may be used to free memory that an object allocated. C. Destructors are called when an object is destroyed. D. All of the Above. Which one of these principles is not required to define an object oriented language? A. polymorphism B. inheritance C. multi-dimensional arrays D. data hiding An overloaded operator class member function is convenient for: A. comparing two objects of the same class. B. initializing variables in an object. C. ensuring that data hiding has been performed.

100918550.doc

Questions Only

C++ Programming Today 2nd Edition D. adding two objects that are not related.

Supplemental Multiple Choice Questions

Chapter 7

The class declaration uses the keyword class and includes: A. the function call statements. B. member data and member function prototypes. C. initialization statements for data members. D. return statements for all functions. What is this symbol :: called? A. Scoping operator. B. Directional operator. C. Inheritance operator. D. Binary operator. Where should class variables be ideally initialized? A. In a function. B. In a constructor. C. In a function or a constructor. D. In the variable declaration. Which item from the list below describes an objects constructor and destructor functions incorrectly? A. They are called automatically. B. They cannot include a return type. C. They must have the same name as the class. D. They can only be called once in a program. What is a class? A. a set of characteristics and behaviors that define an object. B. a job description. C. A and B. D. none of the above. Which of these characteristics would be included in a class called Car? A. Hair Color B. Car Payment C. Engine Type D. Driver Which of these functions might be included in a class called Car? A. Oil Type B. HonkHorn C. Driver D. License Which of these characteristics might be included in a class called BankAcct? A. Account Number B. Credit card C. Shoe Size D. ATM location Which of the symbols below is a scoping operator? A. : B. * C. ->

100918550.doc

Questions Only

C++ Programming Today 2nd Edition D. ::

Supplemental Multiple Choice Questions

Chapter 7

Which of these functions might be included in a class called BankAcct? A. Passkey B. WriteCheck C. Withdraw D. B and C What does the keyword private mean in a class declaration? A. private members can only be seen by other class members. B. private is a function that keeps data away from external users. C. private members can be seen by any other parts of the program. D. private functions can send data when called from main. What does the keyword public mean in a class declaration? A. public functions can only be seen by other class members. B. public members can be seen by any other parts of the program and accessed via an object. C. public functions cannot see any other parts of the class. D. public members can only be seen by other class members. What is the main purpose of a class constructor function? A. to destruct the class when the program ends. B. to create object and initialize class data when called in main or in another function. C. to reserve memory for all program variables. D. To run all of the member functions. What are two access specifiers that are used in a class? A. public, pirate B. private, open C. public, private D. public, pirouette How are private member variables in a class accessed? A. Through private functions. B. Through public functions. C. The variable is private so is not available. D. A and B. Why are the words get and set used frequently when naming class member functions? A. Because get and set are mandatory. B. Because they are convenient and descriptive. C. to stop compiler errors. D. to stop linker errors. The C++ convention many programmers use when writing large classes is to separate the class declarations from the class functions body source code into two files. What are the two extensions used? A. .ccp and .h B. .c and .hpp C. .h and .cpp D. .chp and .p What kind of information is not included in a class .h file? A. Short, one-line functions. B. function prototypes.

100918550.doc

Questions Only

C++ Programming Today 2nd Edition C. include files. D. main.

Supplemental Multiple Choice Questions

Chapter 7

What is the purpose of the scoping operator? A. To find a target. B. So the program knows which class owns the function. C. There is no scope operator in object oriented programming. D. None of the above. When a program is executing, and it reaches a declaration of an object variable, where does the program execution automatically go to next? A. The class destructor. B. The class constructor. C. The class instructor. D. The class scope operator. Where are object member variables initialized? A. in the class constructor function. B. in the main function. C. in the destructor function. D. in the private: section of the .h file. When would a programmer write more than one constructor? A. You never have more than one constructor. B. The constructor cannot be overloaded. C. The one object can be created by two different constructors. D. When the object can be initialized in more than one way. What symbol is used to indicate a destructor function? A. : B. :: C. ~ D. >> What is wrong with this code? class CReceipt { private: float price; public: CReceipt(); CReceipt( float p); CReceipt(float p) {price = p:} }; A. Nothing is wrong with this code. B. should not have a semi-colon after last brace. C. the constructor does not initialize private variables. D. There are two declarations for the overloaded CReceipt() function. Why would it be necessary and convenient to overload an operator for a class? A. To compare objects. B. You cannot overload an operator in a class. C. To delete objects. D. All of the above.

100918550.doc

Questions Only

C++ Programming Today 2nd Edition When are destructor functions automatically called? A. When an object is destroyed. B. When an object is created. C. When an object is called from main. D. All of the above.

Supplemental Multiple Choice Questions

Chapter 7

Which answer is a properly overloaded operator? A. bool (AddressBk ab) == operator B. (AddressBk ab) == operator bool C. operator bool == (AddressBk ab); D. bool operator == (AddressBk ab); What is a class? A. An instance of an object. B. A job description for an object. C. A list of tasks automatically does the object. D. B and C. Which is not a programming principle that makes a language object-oriented? A. Structure B. Inheritance C. Polymorphism D. Encapsulation What is an object? A. An instance of a class. B. Always created and destroyed as the program runs. C. A job description for a class. D. A and C. Which is not the purpose of a constructor? A. To destruct upon termination of program. B. To initialize data variables. C. To be used upon instantiation. D. To run the program.

What is wrong with this code? class Jeans { private: int size; string brand; public: Jeans() {size = 10; brand = Levis;} void SetSize(int s) {size = s;} void SetBrand(string b){brand = b;} }; int main() { Jeans jeans; jeans.size = 8; return 0; } A. Nothing is wrong with this code.

100918550.doc

Questions Only

C++ Programming Today 2nd Edition

Supplemental Multiple Choice Questions

Chapter 7

B. Cant have two statements in Jeans( ). C. Size is a private variable of Jeans, cant be accessed by jeans. D. Assignment in main should be Jeans.size = 8; Using the code from above, which function would return the brand to main? A. void GetBrand() {return brand;} B. string GetBrand() {return size;} C. string GetBrand() {return brand;} D. None of the Above

class Book { private: int num_pages; string title; public: Book(); void SetBookName(string bn); }; Declare an instance of Book from the above code: A. Mybook Book; B. Book Mybook; C. Book( ) Mybook( ); D. Book Mybook( ); Using the code from above, which is the SetBookName function located in Book.cpp? A. void Book::SetBookName(string bn) {title = bn;} B. SetBookName(string bn) {title = bn;} C. void Book::SetBookName(string title) {title = bn } D. void Book::SetbookName(string bn) {bn = title; } Which of these will return num_pages, based on the code above? A. int n = Mybook.num_pages; B. int n = num_pages.Mybook; C. int n = Mybook->num_pages; D. num_pages is a private variable, it cannot be obtained this way If we needed the number of pages, why is this code in Book.cpp wrong? void GetPages() {return num_pages;} A. GetPages() is not passed a variable. B. The code is okay, the program returns the int intuitively. C. it wont compile, new_pages is an undeclared identifier. D. The code is perfect.

class Television { private: int size, model; string make; public:

100918550.doc

Questions Only

C++ Programming Today 2nd Edition

Supplemental Multiple Choice Questions

Chapter 7

Television() {size= 27; model = 2; make = RCA;} void SetSize(int s){size = s;} void SetModel(int mo){model = mo;} void SetMake(string ma){make = ma;} }; int main() { Television TV; return 0; } From the above code - which function call sets the size to 19? A. TV.setSize(19); B. TV.SetSize(19.5); C. TV.SetSize(19); D. TV.size is a private variable, it cannot be set this way. In the above code, would main have access to size? A. Yes B. No C. only through TV D. Ask another TV

class Animal { private: string species; bool circus; public: Animal(); Void SetAnimalType(string s); }; Which is not a class member based on the above code? A. Animal B. string species; C. void SetAnimalType(string s); D. Animal( ); Which code located in Animal.cpp would return circus from the code above? A. bool getCircus( ); B. void Animal::getCircus() {return circus;} C. bool Animal::getCircus() {return circus} D. bool getCircus() {return circus;} From the above code, who can access species? A. main B. any function in main C. class Animal only D. None of the above

100918550.doc

Questions Only

C++ Programming Today 2nd Edition

Supplemental Multiple Choice Questions

Chapter 7

What is wrong with this code? class Square { private: int side = 4; public: Square() {side = 4;} void SetSide(int s) {side = s;} }; A. Nothing is wrong with the code. B. side cant be initialized in the set. C. side cant be initialized in the private section. D. no need to initialize in the constructor because it is initialized in the private section. What is wrong with this code? class Person { private: string name; string address; public: People(); void SetName(string n); void SetAddress(string a); }; A. The constructor has not initialized its variables. B. There is no constructor. C. Variables are passed into the set functions but nothing is returned. D. None of the above.

What is wrong with the following code? class TVset { private: int screen; bool HiDef; public: TVset( ){}; int Getscreen(int scr); }; int main( ) { TVset myTV; return 0; } A. Nothing is wrong with this code. B. the constructor does not initialize private values. C. there is a semi-colon after the class declaration. D. There are no set or get functions.

100918550.doc

Questions Only

C++ Programming Today 2nd Edition What is wrong with the following code? int TVset::GetScreen(int scr) { screen = scr; }

Supplemental Multiple Choice Questions

Chapter 7

int main( ) { TVset myTV; int myscreen; myscreen = myTV.GetScreen( ); } A. should be myscreen = myTV->GetScreen(); B. Nothing is wrong with the code. C. GetScreen does not return a value. D. None of the above. Which class member prototype will add a function to TVset called WriteTV? A. void WriteTV(); B. WriteTV(); C. void TVset::WriteTV(); D. void TVset();

class Radio { private: int presets = 15; bool FM = true; double cost = 35.95; public: Radio( ); }; What is wrong with the code above? A. Nothing is wrong with the code. B. Cannot assign values in class declaration. C. The constructor does not initialize variables. D. B and C.

100918550.doc

Questions Only

Das könnte Ihnen auch gefallen