Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. //Struktura
  6. typedef struct student{
  7. char nazwisko[20];
  8. char imie[20];
  9. int indeks;
  10. float ocena;
  11. struct student* next;
  12. }student;
  13.  
  14. //Liczenie dlugosci listy studentow
  15. int dlugosc_listy(student* student1)
  16. {
  17. int d = 0;
  18. student* wsk = student1;
  19. while(wsk != NULL)
  20. {
  21. d++;
  22. wsk = wsk->next;
  23. }
  24. return d;
  25. }
  26.  
  27. //Dodanie nowego wezla w liscie
  28. void dodaj(student** student1, student* nowa){
  29. while (*student1 != NULL) student1 = &((*student1)->next);
  30. *student1 = nowa;
  31. nowa->next = NULL;
  32. }
  33.  
  34. //Dodanie danych ucznia do nowego wezla
  35. void dodajUcznia(student** student1){
  36. system("cls");
  37. student* nowa= (student*)malloc(sizeof(student));
  38. printf("Podaj Nazwisko:");
  39. scanf("%s",nowa->nazwisko);
  40.  
  41. printf("\nPodaj Imie:");
  42. scanf("%s",&nowa->imie);
  43.  
  44. printf("\nPodaj Numer Indeksu:");
  45. scanf("%d",&nowa->indeks);
  46.  
  47. nowa->ocena=0;
  48.  
  49. system("cls");
  50. dodaj(student1,nowa);
  51. }
  52.  
  53. //Wpisanie ocen uczniom
  54. void egzamin(student* student1){
  55. student* wsk = student1;
  56.  
  57. if(student1 == NULL){
  58. printf("Brak studentow");
  59. getch();
  60. }
  61. float ocena=0;
  62. int i = 1;
  63. system("CLS");
  64. while( wsk != NULL)
  65. {
  66. if(wsk->ocena==0){
  67. printf("Numer na liscie: %d \nImie: %s \nNazwisko: %s \nNumer albumu: %d\n", i, wsk->imie, wsk->nazwisko, wsk->indeks);
  68. printf("\nPodaj ocene ucznia: ");
  69. scanf("%f", &ocena);
  70. wsk->ocena=ocena;
  71. wsk=wsk->next;
  72. i++;
  73. system("CLS");
  74. }
  75. else{
  76. i++;
  77. wsk=wsk->next;
  78. }
  79. }
  80. printf("Nacisnij ENTER aby kontynuowac");
  81. getch();
  82. system("CLS");
  83. }
  84.  
  85. //Usuniecie studenta z listy oraz zwolnienie jego miejsca w pamieci
  86. void usun(student** student1, int ID)
  87. {
  88. student* poprzedni = NULL;
  89. student* wsk = *student1;
  90. int i;
  91. for(i = 1; i < ID; i++)
  92. {
  93. poprzedni=wsk;
  94. wsk=wsk->next;
  95.  
  96. }
  97. if(poprzedni==NULL)
  98. {
  99. (*student1)=(*student1)->next;
  100. free(wsk);
  101. }
  102. else
  103. {
  104. poprzedni->next=wsk->next;
  105. free(wsk);
  106. }
  107. }
  108.  
  109. //Usuniecie studenta poprzez podanie jego numeru na liscie
  110. void rezygnacja(student** student1){
  111. int ID;
  112. printf("Podaj numer osoby na liscie: " );
  113. scanf("%d", &ID);
  114.  
  115. if((ID > dlugosc_listy(*student1)) || (ID < 1))
  116. {
  117. printf("Nie ma takiego numeru");
  118.  
  119. }
  120. else
  121. {
  122. usun(student1,ID);
  123. }
  124. }
  125.  
  126. //Wypisanie wszystkich studentow
  127. void lista_studentow(student* student1){
  128.  
  129. student* wsk = student1;
  130.  
  131. if(student1 == NULL){
  132. printf("Brak studentow");
  133. printf("\nNacisnij ENTER aby kontynuowac");
  134. getch();
  135. }
  136. int i = 1;
  137. system("CLS");
  138. while( wsk != NULL)
  139. {
  140. printf("Numer na liscie: %d \nImie: %s \nNazwisko: %s \nNumer albumu: %d\n", i, wsk->imie, wsk->nazwisko, wsk->indeks);
  141. if(wsk->ocena != 0){
  142. printf("Ocena: %.2f", wsk->ocena);
  143. }
  144. else{
  145. printf("Ocena: Nie podszedl do egzaminu");
  146. }
  147. wsk=wsk->next;
  148. i++;
  149. printf("\n\n");
  150. }
  151. printf("\nNacisnij ENTER aby kontynuowac");
  152. getch();
  153. system("CLS");
  154.  
  155. }
  156.  
  157. //Sprawdzenie listy studentow
  158. void przelicz_studentow(student* student1){
  159.  
  160. student* wsk = student1;
  161.  
  162. if(student1 == NULL){
  163. printf("Brak studentow");
  164. printf("\nNacisnij ENTER aby kontynuowac");
  165. getch();
  166. }
  167. int i = 0;
  168. system("CLS");
  169. while( wsk != NULL)
  170. {
  171. wsk=wsk->next;
  172. i++;
  173. }
  174. printf("\nLista studentow zawiera: %d osob",i);
  175. printf("\nNacisnij ENTER aby kontynuowac");
  176. getch();
  177. system("CLS");
  178. }
  179.  
  180. //Zliczenie sredniej z ocen studentow
  181. void sredniaocen(student* student1){
  182.  
  183. student* wsk = student1;
  184.  
  185. if(student1 == NULL){
  186. printf("Brak studentow");
  187. getch();
  188. }
  189. system("CLS");
  190. float srednia=0;
  191. int i = 0;
  192. while (wsk != NULL) {
  193. if (wsk->ocena != 0) {
  194. srednia = srednia + wsk->ocena;
  195. i++;
  196. }
  197. wsk = wsk->next;
  198. }
  199. printf("\nSrednia ocen uczniow wynosi: %.2f", srednia/i);
  200. printf("\nNacisnij ENTER aby kontynuowac");
  201. getch();
  202. system("CLS");
  203.  
  204. }
  205.  
  206. int main(){
  207.  
  208. student* student1 = NULL;
  209.  
  210.  
  211. int stop;
  212.  
  213. while(stop!=9){
  214. printf("1. - Dodaj studenta");
  215. printf("\n2. - Rozpocznij egzamin");
  216. printf("\n3. - Rezygnacja studenta");
  217. printf("\n4. - Wyswietl liste studentow");
  218. printf("\n5. - Przelicz studentow");
  219. printf("\n6. - Srednia ocen egzaminu");
  220. printf("\n9. - Zakoncz program");
  221. printf("\nWybieram: ");
  222. scanf("%d",&stop);
  223.  
  224. switch(stop){
  225. //Dodaj studenta
  226. case 1:
  227. dodajUcznia(&student1);
  228. break;
  229. //Rozpocznij egzamin
  230. case 2:
  231. system("CLS");
  232. egzamin(student1);
  233. break;
  234. //Rezygnacja studenta
  235. case 3:
  236. rezygnacja(&student1);
  237. break;
  238. //Wyswietl liczbe studentow
  239. case 4:
  240. system("CLS");
  241. lista_studentow(student1);
  242. break;
  243. //Przelicz studentow
  244. case 5:
  245. przelicz_studentow(student1);
  246. break;
  247. //Srednia ocen
  248. case 6:
  249. sredniaocen(student1);
  250. break;
  251. }
  252. }
  253. system("cls");
  254. printf("Dziekuje za skorzystanie z programu, zegnam");
  255. printf("\nNacisnij ENTER aby kontynuowac");
  256. getch();
  257. return 0;
  258. }
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. // Piotr Matejak I8X2N1 WAT WCY Pozdrawiam Cieplutko
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement