1 how many members data and functions does the following class have class rational p 5346709

1.      How many members (data and functions) does the following class have?

class Rational

{

public:

Rational();

Rational(int numer, int denom);

Rational(int whole);

int getNumerator();

int getDenominator();

friend void display(ostream& out, const Rational& value);

private:

int numerator;

int denominator;

};

a.   2

b.   6

c.   5

d.   7

2.      Operators can be overlooked as:

a.   friends of a class.

b.   members of a class.

c.   non-friends, non-members of a class.

d.   All of the choices apply..

3.      Why should you generally pass an object of the class to a friend function as a reference parameter?

a.   If the friend function changes the values of the data member(s)

b.   If the friend function will not change the values of the data member(s)

c.   It is more efficient to pass the object by reference

d.   If the friend function changes the values of the data member(s) and it is more efficient to pass the object by reference

4.      What is wrong with the following member function definition given the class below?

class Rational

{

public:

Rational();

Rational(int numer, int denom);

Rational(int whole);

int getNumerator() const;

int getDenominator() const;

friend void display(ostream& out, const Rational& value);

private:

int numerator;

nt denominator;

};

int Rational::getNumerator() const

{

numerator = 0;

return numerator;

}

a.   You cannot set the numerator to zero.

b.   The function may not modify the numerator, but it can modify the denominator.

c.   The function may not modify any of the private data members.

d.   You cannot set the numerator to zero and the function may not modify any of the private data members.

5.      To overload functions with symbolic names (like + – /

a.   const

b.   operator

c.   reference

d.   void

6.      What is wrong with the following overloaded extraction operator declaration?

istream& operator >>(istream& in, const myClass &object);

a.   Object should not be a pass by reference parameter.

b.   Object should not be a const parameter.

c.   You cannot put the & on the return type.

d.   Nothing is wrong with the overloaded extraction operator declaration.

7.      Which of the following would be an appropriate function declaration to add two rational numbers?

a.   void friend operator+( const Rational &left, const Rational &right);

b.   void operator+( const Rational &left, const Rational &right);

c.   friend Rational operator+( const Rational &left, const Rational &right);

d.   Rational operator+( const Rational &left, const Rational &right);

8.      How many parameters are there in a binary operator implemented as a friend?

a.   0

b.   1

c.   2

d.   As many as you need

9.      How many parameters are there in a unary operator implemented as a friend?

a.   0

b.   1

c.   2

d.   As many as you need

10.    What member functions do you need to allow the compiler to perform automatic type conversions from a type different than the class to the class?

a.   Overloaded constructors

b.   Converters

c.   This cannot be done

d.   This already happens automatically

11.    In an overloaded insertion or extraction operator, which object should be the first parameter, the stream or the object of the class?

a.   The stream

b.   The object

c.   It does not matter

d.   None of the choices apply.

12.    Which of the following operators cannot be overloaded?

a.   =

b.   ==

c.   .

d.   []

13.    Given the following class and array declaration, how would you print out the age of the 10th person in the array?

class personClass

{

public:

void setAge(int newAge);

void setGender( char newGender);

void setSalary(float newSalary);

int getAge();

char getGender();

float getSalary();

private:

int age;

char gender;

float salary;

};

personClass people[100];

a.   cout

b.   cout

c.   cout

d.   cout

14.    Which of the following statements are true?

a.   Array elements may be user-defined types (structs or classes).

b.   If a function is expecting a variable of the base type of the array, then you can pass an element of the array to the function.

c.   All of the choices apply.

d.   None of the choices apply.

15.    Which of the following statements are true?

a.   A dynamic array can have a base type which is a class or a struct.

b.   A class or a struct may have a member which is a dynamic array.

c.   A dynamic array can have a base type which is a class or a struct and a class or a struct may have a member which is a dynamic array.

d.   None of the choices apply.

16.    When a dynamic array with a class for a base type is declared, which constructor is called?

a.   Copy constructor

b.   Destructor

c.   Default constructor

d.   Explicit constructor

17.    The destructor for a class is called:

a.   explicitly from the main program.

b.   when the class is instantiated.

c.   when the object of the class goes out of scope.

d.   only at the end of main.

18.    The copy constructor for a class is called when a(n):

a.   object of the class is passed by value to a function.

b.   object of the class is initialized by another object of the class.

c.   function returns an object of the class.

d.   All of the choices apply.

19.    Which of the following are not correct?

a.   The destructor of a class is not named the same as the name of the class, but preceded with a tilde.

b.   The destructor of a class is not called when an object of the class goes out of scope.

c.   The destructor of a class is not a member of the class.

d.   The destructor of a class is a void function.

20.    Which of the following are valid declarations for an assignment operator for a class named myClass?

a.   void friend operator = (myClass& left, const myClass& source);

b.   void operator = (myClass& left, const myClass& source);

c.   void friend operator = (const myClass& source);

d.   void operator = (const myClass& source);

21.    Friend functions are members of the class.

a.   True

b.   False

22.    All operators can be overloaded.

a.   True

b.   False

23.    If you have mutators and accessors, you should not have friend functions also.

a.   True

b.   False

24.    Friend functions may directly modify or access the private data members.

a.   True

b.   False

25.    The following is a properly declared overloaded insertion operator for myClass.

a.   True

b.   False

26.    Functions that are constant member functions may call the class mutator functions.

a.   True

b.   False

27.    Functions that are constant member functions may call constant class accessor functions.

a.   True

b.   False

28.    You cannot create new operators (such as the quote).

a.   True

b.   False

29.    Operators must be friends of the class.

a.   True

b.   False

30.    You may not change the precedence of operators by overloading them.

a.   True

b.   False

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now