Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- //Struktura
- typedef struct student{
- char nazwisko[20];
- char imie[20];
- int indeks;
- float ocena;
- struct student* next;
- }student;
- //Liczenie dlugosci listy studentow
- int dlugosc_listy(student* student1)
- {
- int d = 0;
- student* wsk = student1;
- while(wsk != NULL)
- {
- d++;
- wsk = wsk->next;
- }
- return d;
- }
- //Dodanie nowego wezla w liscie
- void dodaj(student** student1, student* nowa){
- while (*student1 != NULL) student1 = &((*student1)->next);
- *student1 = nowa;
- nowa->next = NULL;
- }
- //Dodanie danych ucznia do nowego wezla
- void dodajUcznia(student** student1){
- system("cls");
- student* nowa= (student*)malloc(sizeof(student));
- printf("Podaj Nazwisko:");
- scanf("%s",nowa->nazwisko);
- printf("\nPodaj Imie:");
- scanf("%s",&nowa->imie);
- printf("\nPodaj Numer Indeksu:");
- scanf("%d",&nowa->indeks);
- nowa->ocena=0;
- system("cls");
- dodaj(student1,nowa);
- }
- //Wpisanie ocen uczniom
- void egzamin(student* student1){
- student* wsk = student1;
- if(student1 == NULL){
- printf("Brak studentow");
- getch();
- }
- float ocena=0;
- int i = 1;
- system("CLS");
- while( wsk != NULL)
- {
- if(wsk->ocena==0){
- printf("Numer na liscie: %d \nImie: %s \nNazwisko: %s \nNumer albumu: %d\n", i, wsk->imie, wsk->nazwisko, wsk->indeks);
- printf("\nPodaj ocene ucznia: ");
- scanf("%f", &ocena);
- wsk->ocena=ocena;
- wsk=wsk->next;
- i++;
- system("CLS");
- }
- else{
- i++;
- wsk=wsk->next;
- }
- }
- printf("Nacisnij ENTER aby kontynuowac");
- getch();
- system("CLS");
- }
- //Usuniecie studenta z listy oraz zwolnienie jego miejsca w pamieci
- void usun(student** student1, int ID)
- {
- student* poprzedni = NULL;
- student* wsk = *student1;
- int i;
- for(i = 1; i < ID; i++)
- {
- poprzedni=wsk;
- wsk=wsk->next;
- }
- if(poprzedni==NULL)
- {
- (*student1)=(*student1)->next;
- free(wsk);
- }
- else
- {
- poprzedni->next=wsk->next;
- free(wsk);
- }
- }
- //Usuniecie studenta poprzez podanie jego numeru na liscie
- void rezygnacja(student** student1){
- int ID;
- printf("Podaj numer osoby na liscie: " );
- scanf("%d", &ID);
- if((ID > dlugosc_listy(*student1)) || (ID < 1))
- {
- printf("Nie ma takiego numeru");
- }
- else
- {
- usun(student1,ID);
- }
- }
- //Wypisanie wszystkich studentow
- void lista_studentow(student* student1){
- student* wsk = student1;
- if(student1 == NULL){
- printf("Brak studentow");
- printf("\nNacisnij ENTER aby kontynuowac");
- getch();
- }
- int i = 1;
- system("CLS");
- while( wsk != NULL)
- {
- printf("Numer na liscie: %d \nImie: %s \nNazwisko: %s \nNumer albumu: %d\n", i, wsk->imie, wsk->nazwisko, wsk->indeks);
- if(wsk->ocena != 0){
- printf("Ocena: %.2f", wsk->ocena);
- }
- else{
- printf("Ocena: Nie podszedl do egzaminu");
- }
- wsk=wsk->next;
- i++;
- printf("\n\n");
- }
- printf("\nNacisnij ENTER aby kontynuowac");
- getch();
- system("CLS");
- }
- //Sprawdzenie listy studentow
- void przelicz_studentow(student* student1){
- student* wsk = student1;
- if(student1 == NULL){
- printf("Brak studentow");
- printf("\nNacisnij ENTER aby kontynuowac");
- getch();
- }
- int i = 0;
- system("CLS");
- while( wsk != NULL)
- {
- wsk=wsk->next;
- i++;
- }
- printf("\nLista studentow zawiera: %d osob",i);
- printf("\nNacisnij ENTER aby kontynuowac");
- getch();
- system("CLS");
- }
- //Zliczenie sredniej z ocen studentow
- void sredniaocen(student* student1){
- student* wsk = student1;
- if(student1 == NULL){
- printf("Brak studentow");
- getch();
- }
- system("CLS");
- float srednia=0;
- int i = 0;
- while (wsk != NULL) {
- if (wsk->ocena != 0) {
- srednia = srednia + wsk->ocena;
- i++;
- }
- wsk = wsk->next;
- }
- printf("\nSrednia ocen uczniow wynosi: %.2f", srednia/i);
- printf("\nNacisnij ENTER aby kontynuowac");
- getch();
- system("CLS");
- }
- int main(){
- student* student1 = NULL;
- int stop;
- while(stop!=9){
- printf("1. - Dodaj studenta");
- printf("\n2. - Rozpocznij egzamin");
- printf("\n3. - Rezygnacja studenta");
- printf("\n4. - Wyswietl liste studentow");
- printf("\n5. - Przelicz studentow");
- printf("\n6. - Srednia ocen egzaminu");
- printf("\n9. - Zakoncz program");
- printf("\nWybieram: ");
- scanf("%d",&stop);
- switch(stop){
- //Dodaj studenta
- case 1:
- dodajUcznia(&student1);
- break;
- //Rozpocznij egzamin
- case 2:
- system("CLS");
- egzamin(student1);
- break;
- //Rezygnacja studenta
- case 3:
- rezygnacja(&student1);
- break;
- //Wyswietl liczbe studentow
- case 4:
- system("CLS");
- lista_studentow(student1);
- break;
- //Przelicz studentow
- case 5:
- przelicz_studentow(student1);
- break;
- //Srednia ocen
- case 6:
- sredniaocen(student1);
- break;
- }
- }
- system("cls");
- printf("Dziekuje za skorzystanie z programu, zegnam");
- printf("\nNacisnij ENTER aby kontynuowac");
- getch();
- return 0;
- }
- // Piotr Matejak I8X2N1 WAT WCY Pozdrawiam Cieplutko
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement