home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c063 / 1.ddi / EXAMPLES.ZIP / SOLAR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-18  |  1.3 KB  |  48 lines

  1. //SOLAR.CPP--Example from Chapter 3, "An Introduction to C++"
  2.  
  3. #include <graphics.h>
  4. #include <iostream.h>
  5. #include <string.h>
  6.  
  7. struct planet {
  8.     char name[10];
  9.     float distance;
  10.     float radius;
  11.     int color;
  12.     int fill_type;
  13. };
  14.  
  15. planet solar_system[9];
  16. planet *planet_ptr;
  17. int    planet_num;
  18.  
  19. int main()
  20. {
  21.     strcpy(solar_system[0].name,"Mercury");
  22.     solar_system[0].distance = 0.4;
  23.     solar_system[0].radius = 0.4;
  24.     solar_system[0].color = EGA_YELLOW;
  25.     solar_system[0].fill_type = EMPTY_FILL;
  26.  
  27.     planet_ptr = solar_system;
  28.     planet_ptr++;             // Point to second planet structure
  29.      strcpy (planet_ptr->name,"Venus");
  30.     planet_ptr->distance = 0.7;
  31.     planet_ptr->radius = 1.0;
  32.     planet_ptr->color = EGA_BROWN;
  33.     planet_ptr->fill_type = SOLID_FILL;
  34.  
  35.     planet_ptr = solar_system;         // Reset to first element
  36.     for (planet_num = 0; planet_num < 2; planet_num++, planet_ptr++) 
  37.         {
  38.        cout << " \nPlanetary statistics: ";
  39.        cout << " \nName: "<< planet_ptr->name;
  40.        cout << " \nDistance from Sun in AU: "<< planet_ptr->distance;
  41.        cout << " \nRadius in Earth radii: "<<  planet_ptr->radius;
  42.        cout << " \nColor constant value "<< planet_ptr->color;
  43.        cout << " \nFill pattern constant value "<< planet_ptr->fill_type;
  44.         }
  45.  
  46.    return 0;
  47. }
  48.