The document provides instructions for an assignment on classes and objects in C++. It includes 25 multiple choice and coding questions about key concepts such as the purpose of classes, class members, member functions, constructors, and const member functions. Students are asked to write class definitions, member functions, constructors, and code to access class members and call member functions. The assignment is due on August 2, 2018.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
76 views
Assignment On Classes and Objects - Questions
The document provides instructions for an assignment on classes and objects in C++. It includes 25 multiple choice and coding questions about key concepts such as the purpose of classes, class members, member functions, constructors, and const member functions. Students are asked to write class definitions, member functions, constructors, and code to access class members and call member functions. The assignment is due on August 2, 2018.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
ASSIGNMENT – 2 CLASSES AND OBJECTS
NOTE: Kindly submit the assignment in your H.W. copy on/before 2nd August 2018.
1. What is the purpose of a class definition?
2. A ________ has the same relation to an ________ that a basic data type has to a variable of that type. 3. In a class definition, data or functions designated private are accessible a. to any function in the program. b. only if you know the password. c. to member functions of that class. d. only to public members of the class. 4. Write a class definition that creates a class called leverage with one private data member, crowbar, of type int and one public function whose declaration is void pry(). 5. True or false: Data items in a class must be private. 6. Write a statement that defines an object called lever1 of the leverage class described in Question 4. 7. The dot operator (or class member access operator) connects the following two entities (reading from left to right): a. A class member and a class object b. A class object and a class c. A class and a member of that class d. A class object and a member of that class 8. Write a statement that executes the pry() function in the lever1 object, as described in Questions 4 and 6. 9. Member functions defined inside a class definition are ________ by default. 10. Write a member function called getcrow() for the leverage class described in Question 4. This function should return the value of the crowbar data. Assume the function is defined within the class definition. 11. A constructor is executed automatically when an object is ________. 12. A constructor’s name is the same as _________. 13. Write a constructor that initializes to 0 the crowbar data, a member of the leverage class described in Question 4. Assume that the constructor is defined within the class definition. 14. True or false: In a class you can have more than one constructor with the same name. 15. A member function can always access the data a. in the object of which it is a member. b. in the class of which it is a member. c. in any object of the class of which it is a member. d. in the public part of its class. 16. Assume that the member function getcrow() described in Question 10 is defined outside the class definition. Write the declaration that goes inside the class definition. 17. Write a revised version of the getcrow() member function from Question 10 that is defined outside the class definition. 18. The only technical difference between structures and classes in C++ is that _________. 19. If three objects of a class are defined, how many copies of that class’s data items are stored in memory? How many copies of its member functions? 20. Sending a message to an object is the same as _________. 21. Classes are useful because they a. are removed from memory when not in use. b. permit data to be hidden from other classes. c. bring together all aspects of an entity in one place. d. can closely model objects in the real world. 22. True or false: There is a simple but precise methodology for dividing a real-world programming problem into classes. 23. For the object for which it was called, a const member function a. can modify both const and non-const member data. b. can modify only const member data. c. can modify only non-const member data. d. can modify neither const nor non-const member data. 24. True or false: If you declare a const object, it can only be used with const member functions. 25. Write a declaration (not a definition) for a const void function called aFunc() that takes one const argument called jerry of type float.