Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- struct daten{
- int art;
- char bes[80];
- char kbes[80];
- double pre;
- };
- void eingabe();
- void anzeige(struct daten katalog[], int anzahl);
- void hinzufuegen(struct daten katalog[], int *anzahl);
- void s_get();
- void suche(struct daten katalog[], int anzahl);
- void preis(struct daten katalog[], int anzahl);
- void suche_text (struct daten katalog[], int anzahl);
- int main () {
- int anzahl = 5;
- char c;
- struct daten katalog[20] = {
- {3311, "GeForce GTX 295", "Sauschnelles Teil", 415.50},
- {2840, "Radeon HD 5870", "Dicke Dose", 320.95},
- {1579, "HDD Baracuda 2000 GB", "Viele zu klein", 199.10},
- {3356, "QuadCore 3,5 GHz", "Kraft Proz", 495.00},
- {4371, "DDR3 PC3-16000 4x4GB Kit", "Gib mir Mehr ...", 679.80}
- }; //Initialisierungsliste
- do{
- eingabe();
- printf("Eingabe : ");
- c = getchar(); // Tastatur-Eingabe
- getchar(); // Enter Taste wegwerfen
- switch(c) {
- case '1':
- anzeige(katalog,anzahl);
- break;
- case '2':
- hinzufuegen(katalog, &anzahl);
- break;
- case '3':
- suche(katalog, anzahl);
- break;
- case '4':
- preis(katalog, anzahl);
- break;
- case '5':
- suche_text(katalog, anzahl);
- break;
- }
- } while (c != '0');
- return 0;
- }
- void eingabe(){
- printf("1) Katalog Zeigen\n");
- printf("2) Artikel Hinzufuegen\n");
- printf("3) Artikel Suchen und Anzeigen (Bestellnummer)\n");
- printf("4) Artikel suchen und Anzeigen (Preis)\n");
- printf("5) Artikel suchen und Anzeigen (Name)\n");
- printf("0) Beenden\n\n");
- }
- void anzeige(struct daten katalog[], int anzahl){
- int i;
- printf("%10s %-30s %-25s %6s\n",
- "Bestellnr", "Bezeichnung", "Beschreibung", "Preis");
- for (i=0; i <anzahl; i++)
- printf("%10d %-30s %-25s %6.2lf\n",
- katalog[i].art, katalog[i].bes, katalog[i].kbes, katalog[i].pre);
- printf("\n");
- }
- void hinzufuegen(struct daten katalog[], int *anzahl){
- printf("Bestellnr:");
- scanf("%d", &(katalog[*anzahl].art)); getchar();
- printf("Bezeichnung: ");
- s_get(katalog[*anzahl].bes);
- printf("Kurzbeschreibung: ");
- s_get(katalog[*anzahl].kbes);
- printf("Preis: ");
- scanf("%lf", &(katalog[*anzahl].pre)); getchar();
- (*anzahl)++;
- }
- void s_get(char *s){
- while((*(s++) = getchar())!='\n');
- *(--s) = '\0';
- }
- void suche(struct daten katalog[], int anzahl){
- int i, suchnummer;
- printf("Bestellnr:");
- scanf("%d", &suchnummer); getchar();
- printf("%10s %-30s %-25s %6s\n",
- "Bestellnr", "Bezeichnung", "Beschreibung", "Preis");
- for (i=0; i <anzahl; i++)
- if (suchnummer == katalog[i].art)
- printf("%10d %-30s %-25s %6.2lf\n",
- katalog[i].art, katalog[i].bes, katalog[i].kbes, katalog[i].pre);
- printf("\n");
- }
- void preis(struct daten katalog[], int anzahl){
- int i;
- double preis;
- printf("Preis: ");
- scanf("%lf", &preis); getchar();
- printf("Artikel mit Preis groesser %6.2lf Euro. \n",preis);
- printf("%10s %-30s %-25s %6s\n",
- "Bestellnr", "Bezeichnung", "Beschreibung", "Preis");
- for (i=0; i <anzahl; i++)
- if (preis < katalog[i].pre)
- printf("%10d %-30s %-25s %6.2lf\n",
- katalog[i].art, katalog[i].bes, katalog[i].kbes, katalog[i].pre);
- printf("\n");
- printf("Artikel mit Preis kleiner %6.2lf Euro. \n",preis);
- printf("%10s %-30s %-25s %6s\n",
- "Bestellnr", "Bezeichnung", "Beschreibung", "Preis");
- for (i=0; i <anzahl; i++)
- if (preis >= katalog[i].pre)
- printf("%10d %-30s %-25s %6.2lf\n",
- katalog[i].art, katalog[i].bes, katalog[i].kbes, katalog[i].pre);
- printf("\n");
- }
- void suche_text(struct daten katalog[], int anzahl){
- int i;
- char suchstr[255];
- printf("Text:");
- s_get(suchstr);
- printf("%10s %-30s %-25s %6s\n",
- "Bestellnr", "Bezeichnung", "Beschreibung", "Preis");
- for (i=0; i <anzahl; i++)
- if (strstr(katalog[i].bes, suchstr)||
- strstr(katalog[i].kbes, suchstr))
- printf("%10d %-30s %-25s %6.2lf\n",
- katalog[i].art, katalog[i].bes, katalog[i].kbes, katalog[i].pre);
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement