Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // dnam. Schülerliste.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. typedef struct{ int KatNr;
  6.                 char vname[21];
  7.                 char nname[31];
  8.               }TListe;
  9.  
  10. void einlesenSchuelerliste(TListe **p,int anz);
  11. void ausgebenSchuelerliste(TListe **p,int anz);
  12. void loescheSchueler(TListe **p,int anz,int auswahl);
  13. void sortiereKatnr(TListe **p,int anz);
  14. void sortiertnachVorname(TListe **p,int anz);
  15. int _tmain(int argc, _TCHAR* argv[])
  16. {   TListe **pSchueler;
  17.    int n=0,menu,auswahl;
  18.    pSchueler=(TListe**)malloc(sizeof(TListe));
  19.     do
  20.     {  
  21.         printf("1...Schueler hinzufuegen\n2...Schuelerliste ausgeben\n3...Schueler loeschen\n4...Sortiert nach Vornamen\n5...Ende\n");
  22.         scanf("%d",&menu);
  23.         system("cls");
  24.         switch(menu)
  25.         {  case 1: n++;
  26.                    pSchueler=(TListe**)realloc(pSchueler,n*sizeof(TListe));
  27.                    *(pSchueler+(n-1))=(TListe*)malloc(sizeof(TListe));
  28.                    einlesenSchuelerliste(pSchueler,n);
  29.                    sortiereKatnr(pSchueler,n);
  30.                    break;
  31.            case 2: ausgebenSchuelerliste(pSchueler,n);
  32.                    break;
  33.            case 3: printf("Welcher Schueler soll geloescht werden?");
  34.                    scanf("%d",&auswahl);
  35.                    free((*pSchueler+(auswahl-1)));
  36.                    loescheSchueler(pSchueler,n,auswahl);
  37.                    n--;
  38.                    break;
  39.            case 4: sortiertnachVorname(pSchueler,n);
  40.                    break;
  41.         }
  42.     }while(menu!=5);
  43.     return 0;
  44. }
  45.  
  46. void einlesenSchuelerliste(TListe **p,int anz)
  47. {
  48.          
  49.             printf("\nKatalognummer: ");
  50.             scanf("%d",&(**(p+(anz-1))).KatNr);
  51.             printf("Vorname: ");
  52.             scanf("%s",(**(p+(anz-1))).vname);
  53.             fflush(stdin);
  54.             printf("Nachname: ");
  55.             scanf("%s",(**(p+(anz-1))).nname);
  56.             fflush(stdin);
  57.        
  58. }
  59.  
  60. void ausgebenSchuelerliste(TListe **p,int anz)
  61. {
  62.     for(int i=0;i<anz;i++)
  63.         {
  64.             printf("\nKatalognummer: %d",(*(p+i))->KatNr);
  65.             printf("\n\tVorname: %s",(*(p+i))->vname);
  66.             printf("\n\tNachname: %s\n",(*(p+i))->nname);
  67.         }
  68. }
  69.  
  70. void loescheSchueler(TListe **p,int anz,int auswahl)
  71. {
  72.     while(auswahl<=anz)
  73.     {
  74.         *(p+(auswahl-1))=*(p+(auswahl));
  75.         auswahl++;
  76.     }
  77. }
  78.  
  79. void sortiereKatnr(TListe **p,int anz)
  80. {
  81.     int i,j,min;
  82.     TListe *help;
  83.     for(i=0;i<anz-1;i++)
  84.     {  min=i;
  85.        for(j=i+1;j<anz;j++)
  86.            if((*(p+i))->KatNr>(*(p+j))->KatNr)
  87.                min=j;
  88.         if(i!=min)
  89.         {
  90.             help=*(p+i);
  91.             *(p+i)=*(p+min);
  92.             *(p+min)=help;
  93.         }
  94.     }
  95. }
  96.  
  97. void sortiertnachVorname(TListe **p,int anz)
  98. {   int i,j,min;
  99.     for(i=0;i<anz;i++)
  100.     {  min=i;
  101.        for(j=i+1;j<anz;j++)
  102.        {   if(strcmp((*p+i)->vname,(*p+j)->vname)<0)
  103.            {   printf("%s\n",(*(p+i))->vname);
  104.                 break;
  105.            }
  106.        }
  107.        
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement