[go: up one dir, main page]

0% found this document useful (0 votes)
74 views7 pages

CSC 210 A7

This document contains instructions and exercises for CSC 210. It instructs the student to complete exercises 39a, b, and c from pages 883 and 965-969 of their textbook. It then provides the text of exercise 39a, which asks which of three class instantiation statements is legal, followed by the answers explaining why statements b and c are legal but statement a is not.

Uploaded by

Rica Pulongbarit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views7 pages

CSC 210 A7

This document contains instructions and exercises for CSC 210. It instructs the student to complete exercises 39a, b, and c from pages 883 and 965-969 of their textbook. It then provides the text of exercise 39a, which asks which of three class instantiation statements is legal, followed by the answers explaining why statements b and c are legal but statement a is not.

Uploaded by

Rica Pulongbarit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CSC 210

Complete the following:

 Exercises
a. 39 (Page 883)
b. 1 - 10, 14 - 19 (Pages 965 - 969)
c.

39. Suppose that the definitions of the classes employeeType, fullTimeEmployee, and
partTimeEmployee are as given in Example 12-9 of this chapter. Which of the following
statements is legal? (14)

1. employeeType tempEmp;

Because employeeType is an abstract class, you cannot instantiate an object of this class.
Therefore, this statement is illegal.

b. fullTimeEmployee newEmp();

This statement is legal.

c. partTimeEmployee pEmp("Molly", "Burton", 101, 0.0, 0);

This statement is legal.


ANSWERS:

1.

a. true

b. false

c. true

d. false

e. false

f. false

g. false
h. false

i. true

j. false

k. false

l. true

m. true

2. a function to define the performance of the operator to be overloaded

The operator overloading function’s name should be the keyword operator followed by the operator to be
overloaded

3.

., .*, ::, ?:, and sizeof

4. example:

thisTest thisTest: operator+

{ return *this;

//this means the contents of the object is returned as whole

5.The statement return this; returns the address of the object while the state-

ment return *this; returns the value of the object.

6.function that is non-member of a class but has access to all members (public or non-public) of class

7.A friend function is a nonmember of a class, whereas a member function is a

member of a class.

8.

a. friend bool compareDate(dateType&, dateType&);

b.

bool compareDate(dateType& date1,dateType& date 2)

{
int d11=(1000*date1.dyear+100*date1.dMonth + date1.dDay);

intd12==(1000*date2.dyear+100*date2.dMonth + date2.dDay);

if(d11>d12)

{return true;}

else

{ return false;}

9. Because the left operand of << is a stream object, which is not of the type mystery.

10.1

14. line 4, no return type,

It should be: bool operator>=(const secret&) const;

15. In Line 4, the return type of the function operator* should be temp.

The correct statement is:

temp operator*(const temp& obj); //Line 4

16.

17. In Line 3, the return type of the function operator< should be bool.

The correct statement is:

friend bool operator<(const mystery& a,


const mystery& b); //Line 3
18.

19. In Lines 3 and 11, the return type of the function operator+ should be discover. Also since operator+ is a friend
function of the class, the name of the class and the scope resolution operator in the heading of the function, in Line
11, are not needed. The correct statements are:

friend discover operator+(const discover&, const discover&);

discover operator+(const discover& a, const discover& b)

You might also like