CS 150 OCC Gilbert

76 flashcards · Computer Science · by vincentdiep

  1. What is wrong with this IPO code fragment? string name; cin >> name; cout << "Name: "; cout << "Hello, " << name << endl;

    The prompt is in the wrong place

  2. You are trying to compile a homework assignment and you see the following message. What is the problem? ~/ $ make make: *** No targets specified and no makefule found. Stop.

    The programmer is in the wrong directory.

  3. #include <iostream> using namespace std; int main() { cout << sqrt(64) << endl; }

    May print 8, but actually contains undefined behavior. sqrt is in the <cmath> header and it was not #included.

  4. Which line(s) contain a variable definition? 13 int main() 14 { 15 cout << "Enter a temperature in Fahrenheit: "; 16 double fahr; 17 cin >> fahr; 18 double celsius = convert(fahr); 19 cout << "Converted: " << fahr << "F->" 20 << celsius << "C" << endl; 21 return 0; 22 }

    Line 16 Line 18

  5. Follows provided instructions for building your program.

    Make

  6. Converts processed source code to assembly language.

    Compiler

  7. Which line(s) contain an output statement? 13 int main() 14 { 15 cout << "Enter a temperature in Fahrenheit: "; 16 double fahr; 17 cin >> fahr; 18 double celsius = convert(fahr); 19 cout << "Converted: " << fahr << "F->" 20 << celsius << "C" << endl; 21 return 0; 22 }

    Line 15 Line 19

  8. Which line(s) uses the character input stream? 13 int main() 14 { 15 cout << "Enter a temperature in Fahrenheit: "; 16 double fahr; 17 cin >> fahr; 18 double celsius = convert(fahr); 19 cout << "Converted: " << fahr << "F->" 20 << celsius << "C" << endl; 21 return 0; 22 }

    Line 17

  9. Used by the tool-chain to produce native object code.

    Assembler

  10. What command checks a homework assignment for correctness?

    make test

  11. #include <iostream> int main() { std::cout << "Hello CS 150"; }

    Compiles, runs, prints output without a newline.

  12. Which line(s) contain a function call? 13 int main() 14 { 15 cout << "Enter a temperature in Fahrenheit: "; 16 double fahr; 17 cin >> fahr; 18 double celsius = convert(fahr); 19 cout << "Converted: " << fahr << "F->" 20 << celsius << "C" << endl; 21 return 0; 22 }

    Line 18

  13. Reads an executable image on disk and starts it running.

    Loader

  14. What is wrong with this IPO fragment? cout << "Name: "; string name; cout << "Hello, " << name << endl; cint >> name;

    Input occurs after output

  15. Which line(s) contain a function declaration? 13 int main() 14 { 15 cout << "Enter a temperature in Fahrenheit: "; 16 double fahr; 17 cin >> fahr; 18 double celsius = convert(fahr); 19 cout << "Converted: " << fahr << "F->" 20 << celsius << "C" << endl; 21 return 0; 22 }

    None of these

  16. What command hands in a homework assignment for course credit?

    make submit

  17. What happens if this program is compiled and run? int main() { }

    Compiles, runs and returns 0 to the operating system.

  18. #include <iostream> using std::cout; int main() { cout << "Hello CS 150\n"; }

    Compiles, runs, prints output with a newline.

  19. Address Hexdump Dissassembly ------------------------------ $0600 a9 c0 LDA #$c0 $0602 aa TAX $0603 e8 INX $0604 69 c4 ADC #$c4 $0606 00 BRK

    native code machine dependent machine language

  20. What command only builds, but does not run or test, a homework assignment?

    make

  21. [2601] What does this code mean? class X:public Y{ ... }; (a) Each X object uses- a Y object (b) Every Y object is-a X object (c) Each X object is-implemented in terms of Y (d) Every X object is-a Y object (e) Every X object has-a Y object

    Every X object is-a Y object.

  22. [2602] What does this code mean? class X:Y{ ... }; (a) Each X object is-implemented in terms of Y (b) Each X object uses- a Y object (c) Every X object is-a Y object (d) Every X object has-a Y object (e) Every Y object is-a X object

    Each X object is-implemented in terms of Y

  23. [2603] What does this code mean? class X{ Y y; ... }; (a) Every X object is-a Y object (b) Every Y object is-a X object (c) Every X object has-a Y object (d) Each X object is-implemented in terms of Y (e) Each X object uses-a Y object

    Every X object has-a Y object

  24. [2604] What does this code mean? class X{ double x = Y().balane(); ... }; (a) Every X object has-a Y object (b) Every Y object is-a X object (c) Every X object is-a Y object (d) Each X object uses-a Y object (e) Each X object is-implemented in terms of Y

    Each X object uses-a Y object

  25. [2605] Specialization inheritance means that the derived class may add new data members and member functions, and may also ________ the virtual member functions in the base class. hide override overload cast delete

    override

  26. [2606] Which member functions in the Performer class may not be overridden? class Performer{ public: void dance() const; virtual void sing() const; virtual void act() const = 0; }; sing() dance() None can be overridden All can be overridden act()

    dance()

  27. [2607] Which member functions in the Performer class may be overridden ( but need not be )? class Performer { public: void dance() const; virtual void sing() const; virtual void act() const = 0; }; act() sing() dance() All can be overridden None can be overridden

    sing()

  28. [2608] Which member functions in the Performer class must be overridden? class Performer{ public: void dance() const; virtual void sing() const; virtual void act() const = 0; }; act() sing() dance() All can be overridden None can be overridden

    act()

  29. [2609] The member function Mime::dance() is : class Performer { public: void dance() const; }; class Mime : public Performer { public: void dance() const; }; final overloaded overridden hidden or shadowed Illegal ( does not compile )

    hidden or shadowed

  30. [2610] Which member function is called? class Performer { public: virtual void sing() const; }; class Crooner : public Performer{ public: void sing() const; }; int main() { Performer* p = new Crooner; p-> sing(); } Crooner::sing() Performer::sing() Neither of these Illegal ( does not compile )

    Crooner::sing()

  31. [2611] Using C++ terminology, the member Card::score() is class Hand{ std::vector<Card> cards; public: Hand() = default; virtual ~Hand() = default; void add(const Card&); virtual int score() const = 0; virtual void sort(); bool operator<(const Card& rhs) const; }; class PokerHand: public Hand {...} class BlackjackHand: public Hand {...} a virtual function an abstract method a pure virtual function an overridden member an overloaded member

    a pure virtual function

  32. [2612] Examine the class hierarchy below. Assume that both derived classes are concrete and completely defined. Which line of code is illegal: class Hand { std::vector<Card> cards; public: Hand() = default; virtual ~Hand() = default; void add(const Card&); virtual int score() const = 0; virtual void sort(); bool operator<(const Card& rhs) const; }; class PokerHand : public Hand { . . . } class BlackjackHand : public Hand { . . . } Hand h PokerHand ph; Hand* hp = new PokerHand; PokerHand ph; Han…

    Hand h

  33. [2613] Examine the class hierarchy below. Assume that both derived classes are concrete and completely defined. What happens when a PokerHand object is passed to the non-member draw() function, assuming that the function makes use of the virtual functions overridden in PokerHand? class Hand { std::vector<Card> cards; public: Hand() = default; virtual ~Hand() = default; void add(const Card&); virtual int score() const = 0; virtual void sort(); bool operator<(const Card& rhs) const; }; class Poke…

    Code compiles, but the parameter is treated as a Hand object, not a PokerHand, so it is not drawn correctly

  34. [2614] Examine the class hierarchy below. Assume that both derived classes are concrete and completely defined. Which of the following member functions cannot be overridden in the derived classes? class Hand { std::vector<Card> cards; public: Hand() = default; virtual ~Hand() = default; void add(const Card&); virtual int score() const = 0; virtual void sort(); bool operator<(const Card& rhs) const; }; class PokerHand : public Hand { . . . } class BlackjackHand : public Hand { . . . } add() sort…

    add()

  35. [2615] Examine the class hierarchy below. Assume that both derived classes are concrete and completely defined. Which of the following member functions cannot be overridden in the derived classes? class Hand { std::vector<Card> cards; public: Hand() = default; virtual ~Hand() = default; void add(const Card&); virtual int score() const = 0; virtual void sort(); bool operator<(const Card& rhs) const; }; class PokerHand : public Hand { . . . } class BlackjackHand : public Hand { . . . } sort() sco…

    operator<()

  36. [2616] Examine the class hierarchy below. Assume that both derived classes are concrete and completely defined. Which of the following member functions cannot be overridden in the derived classes? class Hand { std::vector<Card> cards; public: Hand() = default; virtual ~Hand() = default; void add(const Card&); virtual int score() const = 0; virtual void sort(); bool operator<(const Card& rhs) const; }; class PokerHand : public Hand { . . . } class BlackjackHand : public Hand { . . . } get() sort…

    get()

  37. [2617] Examine the class hierarchy below. Assume that both derived classes are concrete and completely defined. Which of the following member functions must be overridden in the derived classes? class Hand { std::vector<Card> cards; public: Hand() = default; virtual ~Hand() = default; void add(const Card&); virtual int score() const = 0; virtual void sort(); bool operator<(const Card& rhs) const; }; class PokerHand : public Hand { . . . } class BlackjackHand : public Hand { . . . } add() get()…

    score()

  38. [2618] Examine the class hierarchy below. Assume that both derived classes are concrete and completely defined. Which of the following member functions are the derived classes allowed (but not required to) override? class Hand { std::vector<Card> cards; public: Hand() = default; virtual ~Hand() = default; void add(const Card&); virtual int score() const = 0; virtual void sort(); bool operator<(const Card& rhs) const; }; class PokerHand : public Hand { . . . } class BlackjackHand : public Hand {…

    sort()

  39. In C++, as in Java, pure virtual functions may not have an implementation.

    False

  40. The C++ facility that allows a derived class to have multiple base classes is known as interface inheritance

    False

  41. In C++, an Abstract Base Class is any class that has one or more virtual member functions

    False

  42. The istream class in the C++ standard library uses multiple inheritance

    False

  43. Since an abstract class cannot be instantiated, it is illegal to have references of abstract types

    False

  44. Using public inheritance to derive Stack from vector is a good design because vector provides all the capabilities that a Stack requires

    False

  45. An abstract class is a class that contains no data members

    False

  46. Constructing an instance of an abstract class is legal, provided you do not initialize it

    False

  47. Consider the Shape class hierarchy, along with Circle, Square and Star from your text. The Shape class is a concrete class.

    False

  48. What Java calls a static method is called a pure virtual member function in C++

    False

  49. If a class is abstract, you may create instances, but not pointers of that class

    False

  50. An abstract class may, but is not required to, override its pure virtual (abstract) member functions

    False

  51. Composition models an is-a relationship between classes

    False

  52. Composition can be used to create adapter classes that change the implementation of one class to meet the needs of another

    False

  53. Private inheritance models an is-a relationship between classes

    False

  54. In C++, public inheritance can be used to create adapter classes

    False

  55. An abstract class is a class that contains only virtual member functions

    False

  56. Using the keyword abstract to the heading of a virtual member function converts it to a pure virtual member function

    False

  57. Abstract classes provide a set of capabilities that derived classes may inherit

    False

  58. In adapter classes, the member functions override superclass member functions to provide new behavior

    False

  59. Consider the Shape class hierarchy, along with Circle, Square and Star from your text. The Circle class is an abstract class

    False

  60. You may create a reference to a class that is abstract

    True

  61. It is illegal to construct an instance of an abstract class

    True

  62. Abstract classes specify a set of responsibilities that derived classes must fulfill

    True

  63. The iostream class in the C++ standard library uses multiple inheritance

    True

  64. In C++, an Abstract Base Class is any class that has one pure virtual member function

    True

  65. An abstract class is a class that contains member functions that are specified but not implemented

    True

  66. The C++ facility that allows a derived class to have multiple base classes is known as multiple inheritance

    True

  67. In C++ pure virtual member functions may have an optional implementation

    True

  68. Adding = 0 to the end of the heading of a virtual member function converts it to a pure virtual member function

    True

  69. An abstract class requires its concrete derived classes to override all of its pure virtual (abstract) member functions

    True

  70. In composition-based adapter classes, the member functions delegate or forward requests to the data member that can satisfy the request

    True

  71. In C++, private inheritance can be used to create adapter classes

    True

  72. Public inheritance models an is-a relationship between classes

    True

  73. Using public inheritance to derive Stack from vector is a problem because a Stack is really not a vector

    True

  74. If a class is abstract, you may create a pointer of that class

    True

  75. What Java calls an abstract method is called a pure virtual member function in C++

    True

  76. Consider the Shape class hierarchy, along with Circle, Square and Star from your text. The Shape class is an abstract base class

    True