CS 150 OCC Gilbert
76 flashcards · Computer Science · by vincentdiep
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
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.
#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.
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
Follows provided instructions for building your program.
Make
Converts processed source code to assembly language.
Compiler
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
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
Used by the tool-chain to produce native object code.
Assembler
What command checks a homework assignment for correctness?
make test
#include <iostream> int main() { std::cout << "Hello CS 150"; }
Compiles, runs, prints output without a newline.
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
Reads an executable image on disk and starts it running.
Loader
What is wrong with this IPO fragment? cout << "Name: "; string name; cout << "Hello, " << name << endl; cint >> name;
Input occurs after output
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
What command hands in a homework assignment for course credit?
make submit
What happens if this program is compiled and run? int main() { }
Compiles, runs and returns 0 to the operating system.
#include <iostream> using std::cout; int main() { cout << "Hello CS 150\n"; }
Compiles, runs, prints output with a newline.
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
What command only builds, but does not run or test, a homework assignment?
make
[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.
[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
[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
[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
[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
[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()
[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()
[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()
[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
[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()
[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
[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
[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
[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()
[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<()
[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()
[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()
[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()
In C++, as in Java, pure virtual functions may not have an implementation.
False
The C++ facility that allows a derived class to have multiple base classes is known as interface inheritance
False
In C++, an Abstract Base Class is any class that has one or more virtual member functions
False
The istream class in the C++ standard library uses multiple inheritance
False
Since an abstract class cannot be instantiated, it is illegal to have references of abstract types
False
Using public inheritance to derive Stack from vector is a good design because vector provides all the capabilities that a Stack requires
False
An abstract class is a class that contains no data members
False
Constructing an instance of an abstract class is legal, provided you do not initialize it
False
Consider the Shape class hierarchy, along with Circle, Square and Star from your text. The Shape class is a concrete class.
False
What Java calls a static method is called a pure virtual member function in C++
False
If a class is abstract, you may create instances, but not pointers of that class
False
An abstract class may, but is not required to, override its pure virtual (abstract) member functions
False
Composition models an is-a relationship between classes
False
Composition can be used to create adapter classes that change the implementation of one class to meet the needs of another
False
Private inheritance models an is-a relationship between classes
False
In C++, public inheritance can be used to create adapter classes
False
An abstract class is a class that contains only virtual member functions
False
Using the keyword abstract to the heading of a virtual member function converts it to a pure virtual member function
False
Abstract classes provide a set of capabilities that derived classes may inherit
False
In adapter classes, the member functions override superclass member functions to provide new behavior
False
Consider the Shape class hierarchy, along with Circle, Square and Star from your text. The Circle class is an abstract class
False
You may create a reference to a class that is abstract
True
It is illegal to construct an instance of an abstract class
True
Abstract classes specify a set of responsibilities that derived classes must fulfill
True
The iostream class in the C++ standard library uses multiple inheritance
True
In C++, an Abstract Base Class is any class that has one pure virtual member function
True
An abstract class is a class that contains member functions that are specified but not implemented
True
The C++ facility that allows a derived class to have multiple base classes is known as multiple inheritance
True
In C++ pure virtual member functions may have an optional implementation
True
Adding = 0 to the end of the heading of a virtual member function converts it to a pure virtual member function
True
An abstract class requires its concrete derived classes to override all of its pure virtual (abstract) member functions
True
In composition-based adapter classes, the member functions delegate or forward requests to the data member that can satisfy the request
True
In C++, private inheritance can be used to create adapter classes
True
Public inheritance models an is-a relationship between classes
True
Using public inheritance to derive Stack from vector is a problem because a Stack is really not a vector
True
If a class is abstract, you may create a pointer of that class
True
What Java calls an abstract method is called a pure virtual member function in C++
True
Consider the Shape class hierarchy, along with Circle, Square and Star from your text. The Shape class is an abstract base class
True