Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // dnam. Schülerliste.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- typedef struct{ int KatNr;
- char vname[21];
- char nname[31];
- }TListe;
- void einlesenSchuelerliste(TListe **p,int anz);
- void ausgebenSchuelerliste(TListe **p,int anz);
- void loescheSchueler(TListe **p,int anz,int auswahl);
- void sortiereKatnr(TListe **p,int anz);
- void sortiertnachVorname(TListe **p,int anz);
- int _tmain(int argc, _TCHAR* argv[])
- { TListe **pSchueler;
- int n=0,menu,auswahl;
- pSchueler=(TListe**)malloc(sizeof(TListe));
- do
- {
- printf("1...Schueler hinzufuegen\n2...Schuelerliste ausgeben\n3...Schueler loeschen\n4...Sortiert nach Vornamen\n5...Ende\n");
- scanf("%d",&menu);
- system("cls");
- switch(menu)
- { case 1: n++;
- pSchueler=(TListe**)realloc(pSchueler,n*sizeof(TListe));
- *(pSchueler+(n-1))=(TListe*)malloc(sizeof(TListe));
- einlesenSchuelerliste(pSchueler,n);
- sortiereKatnr(pSchueler,n);
- break;
- case 2: ausgebenSchuelerliste(pSchueler,n);
- break;
- case 3: printf("Welcher Schueler soll geloescht werden?");
- scanf("%d",&auswahl);
- free((*pSchueler+(auswahl-1)));
- loescheSchueler(pSchueler,n,auswahl);
- n--;
- break;
- case 4: sortiertnachVorname(pSchueler,n);
- break;
- }
- }while(menu!=5);
- return 0;
- }
- void einlesenSchuelerliste(TListe **p,int anz)
- {
- printf("\nKatalognummer: ");
- scanf("%d",&(**(p+(anz-1))).KatNr);
- printf("Vorname: ");
- scanf("%s",(**(p+(anz-1))).vname);
- fflush(stdin);
- printf("Nachname: ");
- scanf("%s",(**(p+(anz-1))).nname);
- fflush(stdin);
- }
- void ausgebenSchuelerliste(TListe **p,int anz)
- {
- for(int i=0;i<anz;i++)
- {
- printf("\nKatalognummer: %d",(*(p+i))->KatNr);
- printf("\n\tVorname: %s",(*(p+i))->vname);
- printf("\n\tNachname: %s\n",(*(p+i))->nname);
- }
- }
- void loescheSchueler(TListe **p,int anz,int auswahl)
- {
- while(auswahl<=anz)
- {
- *(p+(auswahl-1))=*(p+(auswahl));
- auswahl++;
- }
- }
- void sortiereKatnr(TListe **p,int anz)
- {
- int i,j,min;
- TListe *help;
- for(i=0;i<anz-1;i++)
- { min=i;
- for(j=i+1;j<anz;j++)
- if((*(p+i))->KatNr>(*(p+j))->KatNr)
- min=j;
- if(i!=min)
- {
- help=*(p+i);
- *(p+i)=*(p+min);
- *(p+min)=help;
- }
- }
- }
- void sortiertnachVorname(TListe **p,int anz)
- { int i,j,min;
- for(i=0;i<anz;i++)
- { min=i;
- for(j=i+1;j<anz;j++)
- { if(strcmp((*p+i)->vname,(*p+j)->vname)<0)
- { printf("%s\n",(*(p+i))->vname);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement