Sams Teach Yourself C in 21 Days

(singke) #1
Object-Oriented Programming Languages 639

87: cout << “\nDraw cube 1 with area of “ << cube1.area() << “\n”; BD1
88: cube1.draw(); //Actually uses square’s draw function
89:
90: return 0;
91: }

Draw square 1 with area of 25
*****
*****
*****
*****
*****
Draw square 2 with area of 9

***
***
***
Draw square 3 with area of 16

****
****
****
****
Draw cube 1 with area of 64
****
****
****
****

LISTINGB1.2 continued

OUTPUT

Thecoutobject in C++ is used for printing. You will learn about coutin
Note tomorrow’s lesson.

This is not the best-written C++ program; however, it does illustrate the differ-
ences between C++ and C in a relatively few lines of code. Later in today’s les-
son, you will see that Java also uses very similar concepts to these. In the next few days,
you’ll learn ways to improve this listing. Tomorrow you will also learn more about print-
ing in C++ with the coutobject. You can see that this object is used a number of times in
this listing.

ANALYSIS

36 448201x-Bonus1 8/13/02 11:18 AM Page 639

Free download pdf