Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <io.h>
- #include <iostream>
- #include <time.h>
- #include <string.h>
- struct student
- {
- char name[40];
- unsigned int age;
- char id[11];
- unsigned int group;
- };
- struct student* arr [10] = { 0 };
- void Print(int i)
- {
- printf("Imie studenta: %s\n", arr[i]->name);
- printf("Wiek studenta: %d\n", arr[i]->age);
- printf("Pesel studenta: %s\n", arr[i]->id);
- printf("Grupa studenta: %d\n", arr[i]->group);
- }
- void Save()
- {
- int i = 0;
- for (i; i < 10; i++)
- {
- if (arr[i] == NULL)
- {
- arr[i] = (struct student*)malloc(sizeof(struct student));
- printf("Podaj imie studenta:\n");
- scanf("%s", arr[i]->name);
- printf("Podaj wiek studenta:\n");
- scanf("%d", &arr[i]->age);
- printf("Podaj pesel studenta:\n");
- scanf("%s", arr[i]->id);
- printf("Podaj grupe studenta:\n");
- scanf("%d", &arr[i]->group);
- break;
- }
- }
- }
- void Edit(int n)
- {
- arr[n] = (struct student*)malloc(sizeof(struct student));
- printf("Podaj imie studenta:\n");
- scanf("%s", arr[n]->name);
- printf("Podaj wiek studenta:\n");
- scanf("%d", &arr[n]->age);
- printf("Podaj pesel studenta:\n");
- scanf("%s", arr[n]->id);
- printf("Podaj grupe studenta:\n");
- scanf("%d", &arr[n]->group);
- }
- int main()
- {
- int studentsNumber = 0;
- Entrance:
- system("cls");
- printf("======Program tworzacy profil studenta=======\n");
- printf("======Wcisnij:===============================\n");
- printf("======1. By dodac studenta===================\n");
- printf("======2. By zmienic studenta dane============\n");
- printf("======3. By wyswietlic dane studenta=========\n");
- printf("======0. By wyjsc============================\n");
- int choice = 0;
- scanf("%d", &choice);
- switch (choice)
- {
- case 1:
- {
- system("cls");
- Save();
- studentsNumber++;
- goto Entrance;
- }
- case 2:
- {
- Edit:
- system("cls");
- printf("Podaj pesel studenta do edycji:\n");
- char studentsID[11];
- scanf("%s", &studentsID);
- int chosenStudent = 100;
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 11; j++)
- {
- if (arr[i] != NULL)
- {
- if (arr[i]->id[j] != studentsID[j])
- {
- break;
- }
- if (j == 10)
- {
- chosenStudent = i;
- }
- }
- }
- }
- if (chosenStudent == 100)
- {
- printf("Nieprawdilowy pesel!\n");
- goto Entrance;
- }
- system("cls");
- Edit(chosenStudent);
- goto Entrance;
- }
- case 3:
- {
- Start:
- system("cls");
- printf("Wyswietlic wszystkie dane czy jednego studenta(wszystkie - 1, jednego - 2)?\n");
- int locChoice = 0;
- scanf("%d", &locChoice);
- system("cls");
- switch(locChoice)
- {
- case 1:
- {
- for (int i = 0; i < studentsNumber; i++)
- {
- if (arr[i]->name != "")
- {
- printf("Numer studenta: %d\n", i);
- Print(i);
- printf("\n");
- }
- }
- break;
- }
- case 2:
- {
- printf("Podaj pesel studenta:\n");
- char ID[11];
- scanf("%s", &ID);
- int printedNumber = 0;
- system("cls");
- for (int i = 0; i < studentsNumber; i++)
- {
- if (arr[i]->name != "")
- {
- bool print = true;
- for (int j = 0; j < 11; j++)
- {
- int temp = 1;
- if (arr[i]->id[j] != ID[j])
- {
- print = false;
- break;
- }
- }
- if (print == true)
- {
- PrintDetails:
- printedNumber++;
- Print(i);
- break;
- }
- }
- }
- if (printedNumber == 0)
- {
- printf("Nie znaleziono szukanego studenta\n");
- }
- break;
- }
- default:
- {
- printf("Bledny wybor, ponow komende");
- goto Start;
- }
- }
- system("PAUSE");
- goto Entrance;
- }
- case 0:
- {
- goto Close;
- }
- }
- goto Entrance;
- Close: {
- for (int i = 0; i < 10; i++)
- {
- if(arr[i] != NULL)
- {
- free(arr[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement