Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct daten{
  5.     int art;
  6.     char bes[80];
  7.     char kbes[80];
  8.     double pre;
  9. };
  10.  
  11. void eingabe();
  12. void anzeige(struct daten katalog[], int anzahl);
  13. void hinzufuegen(struct daten katalog[], int *anzahl); 
  14. void s_get();
  15. void suche(struct daten katalog[], int anzahl);
  16. void preis(struct daten katalog[], int anzahl);
  17. void suche_text (struct daten katalog[], int anzahl);
  18. int main () {
  19.     int anzahl = 5;
  20.     char c;
  21.    
  22. struct daten katalog[20] = {
  23.     {3311, "GeForce GTX 295", "Sauschnelles Teil", 415.50},
  24.     {2840, "Radeon HD 5870", "Dicke Dose", 320.95},
  25.     {1579, "HDD Baracuda 2000 GB", "Viele zu klein", 199.10},
  26.     {3356, "QuadCore 3,5 GHz", "Kraft Proz", 495.00},
  27.     {4371, "DDR3 PC3-16000 4x4GB Kit", "Gib mir Mehr ...", 679.80}
  28.     }; //Initialisierungsliste
  29.  
  30.     do{
  31.     eingabe();
  32.     printf("Eingabe : ");
  33.     c = getchar();      // Tastatur-Eingabe
  34.     getchar();      // Enter Taste wegwerfen
  35.     switch(c) {
  36.       case '1':
  37.        anzeige(katalog,anzahl);
  38.        break;
  39.            case '2':
  40.        hinzufuegen(katalog, &anzahl);
  41.        break;
  42.        case '3':
  43.        suche(katalog, anzahl);
  44.        break;
  45.        case '4':
  46.        preis(katalog, anzahl);
  47.        break;
  48.        case '5':
  49.        suche_text(katalog, anzahl);
  50.        break;  
  51.        }
  52.       } while (c != '0');
  53.  
  54.     return 0;
  55. }
  56.  
  57.  
  58.  
  59.    
  60. void eingabe(){
  61.     printf("1) Katalog Zeigen\n");
  62.     printf("2) Artikel Hinzufuegen\n");
  63.     printf("3) Artikel Suchen und Anzeigen (Bestellnummer)\n");
  64.     printf("4) Artikel suchen und Anzeigen (Preis)\n");
  65.     printf("5) Artikel suchen und Anzeigen (Name)\n");
  66.     printf("0) Beenden\n\n");
  67.  
  68. }
  69.  
  70. void anzeige(struct daten katalog[], int anzahl){
  71.     int i;
  72.         printf("%10s  %-30s %-25s %6s\n",
  73.         "Bestellnr", "Bezeichnung", "Beschreibung", "Preis");  
  74.         for (i=0; i <anzahl; i++)
  75.                
  76.         printf("%10d  %-30s %-25s %6.2lf\n",
  77.         katalog[i].art, katalog[i].bes, katalog[i].kbes, katalog[i].pre);
  78.         printf("\n");  
  79.        
  80.  
  81. }
  82.  
  83. void hinzufuegen(struct daten katalog[], int *anzahl){
  84.     printf("Bestellnr:");
  85.     scanf("%d", &(katalog[*anzahl].art)); getchar();
  86.     printf("Bezeichnung: ");
  87.     s_get(katalog[*anzahl].bes);   
  88.     printf("Kurzbeschreibung: ");
  89.     s_get(katalog[*anzahl].kbes);
  90.     printf("Preis: ");
  91.     scanf("%lf", &(katalog[*anzahl].pre)); getchar();
  92.        
  93.  
  94.     (*anzahl)++;   
  95.  
  96. }
  97.  
  98. void s_get(char *s){
  99.      while((*(s++) = getchar())!='\n');
  100.      *(--s) = '\0';
  101. }
  102.  
  103.  
  104.    
  105.  
  106.  
  107.  
  108. void suche(struct daten katalog[], int anzahl){
  109.     int i, suchnummer;
  110.     printf("Bestellnr:");
  111.     scanf("%d", &suchnummer); getchar();
  112.     printf("%10s  %-30s %-25s %6s\n",
  113.         "Bestellnr", "Bezeichnung", "Beschreibung", "Preis");  
  114.     for (i=0; i <anzahl; i++)
  115.     if (suchnummer == katalog[i].art)    
  116.         printf("%10d  %-30s %-25s %6.2lf\n",
  117.         katalog[i].art, katalog[i].bes, katalog[i].kbes, katalog[i].pre);
  118.         printf("\n");      
  119.  
  120. }
  121.  
  122. void preis(struct daten katalog[], int anzahl){
  123.     int i;
  124.     double preis;
  125.     printf("Preis: ");
  126.     scanf("%lf", &preis); getchar();
  127.     printf("Artikel mit Preis groesser %6.2lf Euro. \n",preis);
  128.     printf("%10s  %-30s %-25s %6s\n",
  129.         "Bestellnr", "Bezeichnung", "Beschreibung", "Preis");  
  130.     for (i=0; i <anzahl; i++)
  131.     if (preis < katalog[i].pre)    
  132.         printf("%10d  %-30s %-25s %6.2lf\n",
  133.             katalog[i].art, katalog[i].bes, katalog[i].kbes, katalog[i].pre);
  134.     printf("\n");      
  135.  
  136.  
  137.     printf("Artikel mit Preis kleiner %6.2lf Euro. \n",preis); 
  138.     printf("%10s  %-30s %-25s %6s\n",
  139.         "Bestellnr", "Bezeichnung", "Beschreibung", "Preis");  
  140.     for (i=0; i <anzahl; i++)
  141.     if (preis >= katalog[i].pre)    
  142.         printf("%10d  %-30s %-25s %6.2lf\n",
  143.         katalog[i].art, katalog[i].bes, katalog[i].kbes, katalog[i].pre);
  144.         printf("\n");  
  145. }
  146.  
  147.  
  148. void suche_text(struct daten katalog[], int anzahl){
  149.     int i;
  150.     char suchstr[255];
  151.     printf("Text:");
  152.     s_get(suchstr);
  153.     printf("%10s  %-30s %-25s %6s\n",
  154.         "Bestellnr", "Bezeichnung", "Beschreibung", "Preis");  
  155.     for (i=0; i <anzahl; i++)
  156.     if (strstr(katalog[i].bes, suchstr)||
  157.         strstr(katalog[i].kbes, suchstr))  
  158.         printf("%10d  %-30s %-25s %6.2lf\n",
  159.         katalog[i].art, katalog[i].bes, katalog[i].kbes, katalog[i].pre);
  160.         printf("\n");  
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement