home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / samples / sam06l / city.cp_ / CITY.CPP
Encoding:
C/C++ Source or Header  |  1992-09-28  |  1020 b   |  53 lines

  1. //#include <stdio.h>
  2. #include <string.h>
  3. #include <iostream.h>
  4.  
  5.  
  6. class CITY
  7. {
  8.    char * Name;
  9.    int    Longitude;
  10.    int    Latitude;
  11.  
  12. public:
  13.  
  14.    CITY(char * NewName, int NewLong, int NewLat)
  15.    {
  16.       Name = new char[strlen(NewName) + 1];
  17.       strcpy (Name, NewName);
  18.  
  19.       Longitude = NewLong;
  20.       Latitude = NewLat;
  21.    }
  22.  
  23.    char * GetName(void)
  24.    {
  25.       return Name;
  26.    }
  27.  
  28.    int GetLongitude(void)
  29.    {
  30.       return Longitude;
  31.    }
  32.  
  33.    int GetLatitude(void)
  34.    {
  35.       return Latitude;
  36.    }
  37. };
  38.  
  39.  
  40. int main(void)
  41. {
  42.    CITY Toronto( "Toronto", 79, 44);
  43.  
  44. //   printf("\nThe longitude of %s is %4i", Toronto.GetName(), Toronto.GetLongitude());
  45. //   printf("\nThe latitude of %s is %4i", Toronto.GetName(), Toronto.GetLatitude());
  46.    cout << "\nThe longitude of " << Toronto.GetName() << " is " << Toronto.GetLongitude() << " degrees.";
  47.    cout << "\nThe latitude of " << Toronto.GetName() << " is " << Toronto.GetLatitude() << " degrees.";
  48.  
  49.    return 0;
  50.  
  51. }
  52.  
  53.