home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / tcpp / examples / solar.c < prev    next >
C/C++ Source or Header  |  1990-06-09  |  1KB  |  61 lines

  1. /* SOLAR.C - Beispiel aus Kapitel 4 der
  2.    Einführung */
  3.  
  4. #include <graphics.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. typedef struct {
  9.    char name[10];
  10.    float abstand;
  11.    float radius;
  12.    int farbe;
  13.    int fill_typ;
  14. } planet;
  15.  
  16. planet sonnen_system[9];
  17. planet *planet_ptr;
  18. int    planet_num;
  19.  
  20. int main()
  21. {
  22.    strcpy(sonnen_system[0].name,"Merkur");
  23.    sonnen_system[0].abstand = 0.4;
  24.    sonnen_system[0].radius = 0.4;
  25.    sonnen_system[0].farbe = EGA_YELLOW;
  26.    sonnen_system[0].fill_typ = EMPTY_FILL;
  27.  
  28.    planet_ptr = sonnen_system;
  29.  
  30.    /* zeigt auf die zweite planet-Struktur */
  31.    planet_ptr++;
  32.  
  33.    strcpy (planet_ptr->name,"Venus");
  34.    planet_ptr->abstand = 0.7;
  35.    planet_ptr->radius = 1.0;
  36.    planet_ptr->farbe = EGA_BROWN;
  37.    planet_ptr->fill_typ = SOLID_FILL;
  38.  
  39.    /* setzt den Zeiger auf das erste Element
  40.       zurück */
  41.    planet_ptr = sonnen_system;
  42.  
  43.    for (planet_num = 0;
  44.         planet_num < 2;
  45.     planet_num++, planet_ptr++)
  46.    {
  47.       printf("\nPlaneten-Statistik:\n");
  48.       printf("Name: %s\n", planet_ptr->name);
  49.       printf("Entfernung von der Sonne (in "
  50.              "astronomischen Einheiten): %4.2f\n",
  51.              planet_ptr->abstand);
  52.       printf("Radius (in Erdradien): %4.2f\n",
  53.              planet_ptr->radius);
  54.       printf("Farbe: %d\n", planet_ptr->farbe);
  55.       printf("Füllmuster: %d\n",
  56.          planet_ptr->fill_typ);
  57.    }
  58.  
  59.    return 0;
  60. }
  61.