Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. typedef struct student{
  6. char nazwisko[20];
  7. char imie[20];
  8. int indeks;
  9. float ocena;
  10. struct student* next;
  11. }student;
  12.  
  13. int dlugosc_listy(student* student1)
  14. {
  15. int d = 0;
  16. student* wsk = student1;
  17. while(wsk != NULL)
  18. {
  19. d++;
  20. wsk = wsk->next;
  21. }
  22. return d;
  23. }
  24.  
  25. void dodaj(student** student1, student* nowa){
  26. while (*student1 != NULL) student1 = &((*student1)->next);
  27. *student1 = nowa;
  28. nowa->next = NULL;
  29. }
  30.  
  31. void dodajUcznia(student** student1){
  32. system("cls");
  33. student* nowa= (student*)malloc(sizeof(student));
  34. printf("Podaj Nazwisko:");
  35. scanf("%s",&nowa->nazwisko);
  36.  
  37. printf("\nPodaj Imie:");
  38. scanf("%s",&nowa->imie);
  39.  
  40. printf("\nPodaj Numer Indeksu:");
  41. scanf("%d",&nowa->indeks);
  42.  
  43. nowa->ocena=0;
  44.  
  45. system("cls");
  46. dodaj(student1,nowa);
  47. }
  48.  
  49.  
  50. void egzamin(){
  51. }
  52. void usun(student** student1, int ID)
  53. {
  54. student* poprzedni = NULL;
  55. student* wsk = *student1;
  56. int i;
  57. for(i = 1; i < ID; i++)
  58. {
  59. poprzedni=wsk;
  60. wsk=wsk->next;
  61.  
  62. }
  63. if(poprzedni==NULL)
  64. {
  65. (*student1)=(*student1)->next;
  66. free(wsk);
  67. }
  68. else
  69. {
  70. poprzedni->next=wsk->next;
  71. free(wsk);
  72. }
  73. }
  74. void rezygnacja(student** student1){
  75. int ID;
  76. printf("Podaj numer osoby na liscie: " );
  77. scanf("%d", &ID);
  78.  
  79. if((ID > dlugosc_listy(*student1)) || (ID < 1))
  80. {
  81. printf("Nie ma takiego numeru");
  82.  
  83. }
  84. else
  85. {
  86. usun(student1,ID);
  87. }
  88. }
  89.  
  90.  
  91. void lista_studentow(student* student1){
  92.  
  93. student* wsk = student1;
  94.  
  95. if(student1 == NULL)
  96. printf("Brak studentow");
  97. int i = 1;
  98. system("CLS");
  99. while( wsk != NULL)
  100. {
  101. printf("Numer na liscie: %d \nImie: %s \nNazwisko: %s \nNumer albumu: %d\n", i, wsk->imie, wsk->nazwisko, wsk->indeks);
  102. wsk=wsk->next;
  103. i++;
  104. }
  105. getch();
  106. system("CLS");
  107.  
  108. }
  109.  
  110. void przeliczstudentow(){
  111. }
  112.  
  113. void sredniaocen(){
  114. }
  115.  
  116. int main(){
  117.  
  118. student* student1 = NULL;
  119.  
  120.  
  121. int stop;
  122.  
  123. while(stop!=9){
  124. printf("1. - Dodaj studenta");
  125. printf("\n2. - Rozpocznij egzamin");
  126. printf("\n3. - Rezygnacja studenta");
  127. printf("\n4. - Wyswietl liste studentow");
  128. printf("\n5. - Przelicz studentow");
  129. printf("\n6. - Srednia ocen egzaminu");
  130. printf("\n9. - Zakoncz program");
  131. printf("\nWybieram:");
  132. scanf("%d",&stop);
  133.  
  134. switch(stop){
  135. //Dodaj studenta
  136. case 1:
  137. dodajUcznia(&student1);
  138. break;
  139. //Rozpocznij egzamin
  140. //case 2:
  141. //egzamin();
  142. //Rezygnacja studenta
  143. case 3:
  144. rezygnacja(&student1);
  145. break;
  146. //Wyswietl liczbe studentow
  147. case 4:
  148. system("CLS");
  149. lista_studentow(student1);
  150. break;
  151. //Przelicz studentow
  152. //case 5:
  153. //przeliczstudtentow();
  154. //case 6:
  155. //srednia_ocen_egzaminu();
  156. }
  157. }
  158. system("cls");
  159. printf("Dziekuje za skorzystanie z programu, zegnam");
  160. getch();
  161. return 0;
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement