Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

28. Consider the code snippet below: class Question { public: virtual void display() const; virtual void display(ostream& out) const; . . . }; class ChoiceQuestion

28. Consider the code snippet below:

class Question { public: virtual void display() const; virtual void display(ostream& out) const; . . . }; class ChoiceQuestion : public Question { public: void display(); . . . };

What change should be made to allow ChoiceQuestion::display() to override Question::display()?

Group of answer choices

ChoiceQuestion::display() needs to be explicitly declared public.

ChoiceQuestion::display() needs to be const.

ChoiceQuestion::display() needs to be explicitly declared virtual.

No change needed, as it already overrides Question::display().

33. What does the following code do?

istream& operator>>(istream& in, Time& a) { int hours, minutes; char separator; in >> hours; in.get(separator); // Read : character in >> minutes; a = Time(hours, minutes); return in; }

Group of answer choices

Creates a Time object from the user (or file) input

All of these

Allows reading multiple Time objects in one statement such as cin >> Time1 >> Time2;

Redefines the > > operator

34. Which of the following non-member function headers best fits the post-increment operator for an object, such as

Time t(1,30); Time x = t++;

Group of answer choices

Time operator++(Time& a, int i)

void operator++(Time a)

Time operator++(Time a)

Time operator++(Time& a)

35.Which of the following class member function headers best fits the pre-increment operator for an object, such as

Time t(1,30); Time x = ++t;

Group of answer choices

Time Time::operator++(Time& a)

Time Time::operator++(int i)

Time Time::operator++()

Time Time::operator++(Time& a, int i)

37.Which of the following function headers best fits a type conversion operator to convert an object of the Fraction class to type double, so that one can use implicit type conversions such as

double root = sqrt( Fraction f(1,2));

Group of answer choices

double operator double(Fraction f) const

Fraction::operator double() const

double convert(Fraction f) const

double Fraction::operator() const

38. What if anything is wrong with the following class definition?

class Fraction //represents fractions of the type 1/2, 3/4, 17/16 { public: Fraction(int n, int d); Fraction(int n); Fraction(); double operator+(Fraction other) const; double operator-(Fraction other) const; double operator*(Fraction other) const; bool operator<(Fraction other) const; void print(ostream& out) const; // other member functions exist but not shown private: int numerator; int denominator; };

Group of answer choices

Nothing is wrong

The operator functions should return type Fraction

Not all the constructors are needed

It is missing a private double data member to represent the decimal value of the fraction

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago