Skip to Content
Navigating C++ and Object-Oriented Design
book

Navigating C++ and Object-Oriented Design

by Paul Anderson, Gail Anderson
October 1997
Intermediate to advanced
800 pages
20h 48m
English
Pearson
Content preview from Navigating C++ and Object-Oriented Design

12.7. Exercises

1: In the tax() function on page 566, implement the isA() function for the Investment class hierarchy.
2:Study the following program and its output.
// fig.C - Circles and Squares with Figure base class 
#include <iostream.h>
#include "Figure.h"

int main()
{
   Circle c1(4);                  // define Circle
   Square s1(8);                  // define Square

   Circle c2(6);                  // define Circle
   Square s2(12);                 // define Square

   c1 += c2;                      // make Circle c1 bigger
   c1 += s2;                      // error

   s1 += s2;                      // make Square s1 bigger
   s1 += c2;                      // error

   cout << "c1 = " << c1 << endl;
   cout << "s1 = " << s1 << endl;
   return 0;
}

$ fig
Circle: right operand should be a Circle
Square: right operand should be a Square
c1 = 314.159 for a Circle
s1 = 400 for a Square

The program overloads operator+=() ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Exploring C++20: The Programmer's Introduction to C++

Exploring C++20: The Programmer's Introduction to C++

Ray Lischner

Publisher Resources

ISBN: 0135327482Purchase book