This preview has intentionally blurred parts. Sign up to view the full document

View Full Document

Unformatted Document Excerpt

Oriented Object Programming Practice Questions CSE 100, Fall 2007 Arizona State University True/False Indicate whether the statement is true or false. ____ ____ ____ ____ ____ ____ 1. In C++, class is a reserved word and it defines only a data type. 2. The member variables of a class must be of the same type. 3. The member functions of a class must be public. 4. In a class, all function members are public and all member variables are private. 5. A class and its members can be described graphically using Unified Modeling Language (UML) notation. 6. Given the declaration class myClass { public: void print(); //Output the value of x; MyClass(); private: int x; }; myClass myObject; The following statement is legal. myObject.x = 10; ____ 7. Given the declaration class myClass { public: void print(); //Output the value of x; MyClass(); private: int x; }; myClass myObject; The following statement is legal. myObject.print = 10; ____ ____ 8. The public members of a class must be declared before the private members. 9. The constructor with no parameters is called the default constructor. Multiple Choice Identify the choice that best completes the statement or answers the question. ____ 10. The components of a class are called the ____ of the class. a. elements c. objects b. members d. instances ____ 11. Suppose that you have the following UML class diagram of a class. clockType -hr: int -min: int -sec: int +setTime(int, int, int): void +getTime(int&, int&, int&) const: void +printTime() const: void +incrementSeconds(): int +incrementMinutes(): int +incrementHours(): int +equalTime(const clockType&) const: bool +clockType() +clockType(int, int, int) According to the UML class diagram, what is the number of private members of the class a. 0 c. 2 b. 1 d. 3 ____ 12. Suppose that you have the following UML class diagram of a class. clockType -hr: int -min: int -sec: int +setTime(int, int, int): void +getTime(int&, int&, int&) const: void +printTime() const: void +incrementSeconds(): int +incrementMinutes(): int +incrementHours(): int +equalTime(const clockType&) const: bool +clockType() +clockType(int, int, int) According to the UML class diagram, which function is public and doesn't return anything? a. incrementHours c. printTime b. equalTime d. None of these ____ 13. Suppose that you have the following UML class diagram of a class. clockType -hr: int -min: int -sec: int +setTime(int, int, int): void +getTime(int&, int&, int&) const: void +printTime() const: void +incrementSeconds(): +incrementMinutes(): int int +incrementHours(): int +equalTime(const clockType&) const: bool +clockType() +clockType(int, int, int) Which of the following would be a possible definition of the default constructor for the class. a. clockType() { setTime(0, 0, 0); } b. clockType::clockType() { setTime(0, 0, 0); } c. clockType(int x, int y, int z) { setTime(0, 0, 0); } d. clockType::clockType(int x, int y, int z) { setTime(0, 0, 0); } ____ 14. A ____ sign in front of a member name on the UML diagram indicates that this member is a private member. a. + c. # b. d. $ ____ 15. Consider the following class definition. class rectangleType { public: void setLengthWidth(double x, double y); //Postcondition: length = x; width = y; void print() const; //Output length and width; double area(); //Calculate and return the area of the rectangle; double perimeter(); //Calculate and return the parameter; rectangleType(); //Postcondition: length = 0; width = 0; rectangleType(double x, double y); //Postcondition: length = x; width = y; private: double length; double width; }; Which of the following class variable declarations is correct? a. rectangle rectangleType; b. class rectangleType rectangle; c. rectangleType rectangle; d. rectangle rectangleType.area; ____ 16. Consider the following class definition class circleType { public: void set(double r); //Postcondition: radius = r; void print(); //Output radius, area, and circumference. double area(); //Postcondition: Calculate and return area. double circumference(); //Postcondition: Calculate and return circumference. circleType(); //Postcondition: radius = 0; circleType(double r); //Postcondition: radius = r; private: double radius; }; and the declaration circleType myCircle; double r; Which of the following statements are valid in C++? (i) cin >> r; myCircle.area = 3.14 * r * r; cout << myCircle.area << endl; (ii) cin >> r; myCircle.set(r); cout << myCircle.area() << endl; a. Only (i) b. Only (ii) c. Both (i) and (ii) d. None of these ____ 17. In C++, the scope resolution operator is ____. a. : c. $ b. :: d. . Answer Section TRUE/FALSE 1. 2. 3. 4. 5. 6. 7. 8. 9. ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: Register to View AnswerF F F T F F F T REF: REF: REF: REF: REF: REF: REF: REF: REF: 651 651 653 653 653 | 654 654-656 654-656 670 672 MULTIPLE CHOICE 10. 11. 12. 13. 14. 15. 16. 17. ANS: ANS: ANS: ANS: ANS: ANS: ANS: Register to View AnswerD C B B C B B REF: REF: REF: REF: REF: REF: REF: REF: 650 654 653 | 654 653 | 674 654 654 | 655 654 | 655 660 ... View Full Document

End of Preview

Sign up now to access the rest of the document