home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_01 / saks / largest.cpp < prev    next >
Encoding:
Text File  |  1993-11-07  |  323 b   |  17 lines

  1. Listing 5 - a function that returns the shape with the largest 
  2. area in a collection of shapes
  3.  
  4. const shape *largest(const shape *sa[], size_t n)
  5.     {
  6.     const shape *s = 0;
  7.     double m = 0;
  8.     double a;
  9.     for (size_t i = 0; i < n; ++i)
  10.         if ((a = sa[i]->area()) > m)
  11.             {
  12.             m = a;
  13.             s = sa[i];
  14.             }
  15.     return s;
  16.     }
  17.