Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 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(student* student1){
  51. student* wsk = student1;
  52.  
  53. if(student1 == NULL)
  54. printf("Brak studentow");
  55. int i = 1;
  56. system("CLS");
  57. while( wsk->ocena = 0)
  58. {
  59. printf("Numer na liscie: %d \nImie: %s \nNazwisko: %s \nNumer albumu: %d\n", i, wsk->imie, wsk->nazwisko, wsk->indeks);
  60. printf("\nPodaj ocene ucznia: ");
  61. scanf("%d", wsk->ocena);
  62. wsk=wsk->next;
  63. i++;
  64. }
  65. getch();
  66. system("CLS");
  67. }
  68.  
  69. void usun(student** student1, int ID)
  70. {
  71. student* poprzedni = NULL;
  72. student* wsk = *student1;
  73. int i;
  74. for(i = 1; i < ID; i++)
  75. {
  76. poprzedni=wsk;
  77. wsk=wsk->next;
  78.  
  79. }
  80. if(poprzedni==NULL)
  81. {
  82. (*student1)=(*student1)->next;
  83. free(wsk);
  84. }
  85. else
  86. {
  87. poprzedni->next=wsk->next;
  88. free(wsk);
  89. }
  90. }
  91. void rezygnacja(student** student1){
  92. int ID;
  93. printf("Podaj numer osoby na liscie: " );
  94. scanf("%d", &ID);
  95.  
  96. if((ID > dlugosc_listy(*student1)) || (ID < 1))
  97. {
  98. printf("Nie ma takiego numeru");
  99.  
  100. }
  101. else
  102. {
  103. usun(student1,ID);
  104. }
  105. }
  106.  
  107.  
  108. void lista_studentow(student* student1){
  109.  
  110. student* wsk = student1;
  111.  
  112. if(student1 == NULL)
  113. printf("Brak studentow");
  114. int i = 1;
  115. system("CLS");
  116. while( wsk != NULL)
  117. {
  118. printf("Numer na liscie: %d \nImie: %s \nNazwisko: %s \nNumer albumu: %d\n", i, wsk->imie, wsk->nazwisko, wsk->indeks);
  119. wsk=wsk->next;
  120. i++;
  121. }
  122. getch();
  123. system("CLS");
  124.  
  125. }
  126.  
  127. void przeliczstudentow(){
  128. }
  129.  
  130. void sredniaocen(){
  131. }
  132.  
  133. int main(){
  134.  
  135. student* student1 = NULL;
  136.  
  137.  
  138. int stop;
  139.  
  140. while(stop!=9){
  141. printf("1. - Dodaj studenta");
  142. printf("\n2. - Rozpocznij egzamin");
  143. printf("\n3. - Rezygnacja studenta");
  144. printf("\n4. - Wyswietl liste studentow");
  145. printf("\n5. - Przelicz studentow");
  146. printf("\n6. - Srednia ocen egzaminu");
  147. printf("\n9. - Zakoncz program");
  148. printf("\nWybieram:");
  149. scanf("%d",&stop);
  150.  
  151. switch(stop){
  152. //Dodaj studenta
  153. case 1:
  154. dodajUcznia(&student1);
  155. break;
  156. //Rozpocznij egzamin
  157. case 2:
  158. system("CLS");
  159. egzamin(student1);
  160. break;
  161. //Rezygnacja studenta
  162. case 3:
  163. rezygnacja(&student1);
  164. break;
  165. //Wyswietl liczbe studentow
  166. case 4:
  167. system("CLS");
  168. lista_studentow(student1);
  169. break;
  170. //Przelicz studentow
  171. //case 5:
  172. //przeliczstudtentow();
  173. //case 6:
  174. //srednia_ocen_egzaminu();
  175. }
  176. }
  177. system("cls");
  178. printf("Dziekuje za skorzystanie z programu, zegnam");
  179. getch();
  180. return 0;
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement