Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- struct student{
- char nazwisko[20];
- int nr, ects, pop; // nr - numer semestru, ects - deficyt ECTS, pop - oplata za poprawki
- };
- int szukaj(struct student *tab, int i){
- int j;
- char *buff;
- printf("Podaj numer porzadkowy studenta: \n");
- scanf("%d",&j);
- return j;
- }
- struct student dodaj(){
- int j,x;
- struct student *tab;
- tab=(struct student*)calloc(1,sizeof(struct student));
- printf("Podaj nazwisko: \n");
- scanf("%s",tab->nazwisko);
- x=strlen(tab->nazwisko);
- for(j=0;j<x;j++){
- if((isdigit(tab->nazwisko[j]))!=0){
- printf("W imieniu nie moze byc cyfr \n");
- return *tab;
- }
- }
- printf("Podaj numer semestru: \n");
- scanf("%d",&tab->nr);
- if(tab->nr>9){
- printf("Nie ma takiego numeru semestru \n");
- return *tab;
- }
- if(tab->nr<0){
- printf("BLAD \n");
- return *tab;
- }
- printf("Podaj deficyt punktow ects: \n");
- scanf("%d",&tab->ects);
- if(tab->ects>30){
- printf("Ten student juz dawno pracuje w biedronce \n");
- return *tab;
- }
- if(tab->ects<0){
- printf("Nie mozna miec ujemnej liczby punktow deficytu \n");
- return *tab;
- }
- tab->pop=0;
- return *tab;
- }
- int usun(struct student *tab,int i, int j){
- int z;
- for(z>j;z<i;z++){
- return z;
- }
- }
- void zal(struct student *tab, int j){
- int z,e;
- z=tab[j].nr;
- e=tab[j].ects;
- if(z==1){
- printf("Nie da sie miec deficytu na 1 semestrze \n");
- return;
- }
- if(z==2){
- if(e>11){
- printf("Student nie zdal \n");
- return;
- }
- if(e<11){
- printf("Student zdal \n");
- return;
- }
- }
- if(z==3 || z==4){
- if(e>15){
- printf("Student nie zdal \n");
- return;
- }
- if(e<15){
- printf("Student zdal \n");
- return;
- }
- }
- if(z==5){
- if(e>12){
- printf("Student nie zdal \n");
- return;
- }
- if(e<12){
- printf("Student zdal \n");
- return;
- }
- }
- if(z==6){
- if(e>9){
- printf("Student nie zdal \n");
- return;
- }
- if(e<9){
- printf("Student zdal \n");
- return;
- }
- }
- if(z==7 || z==8){
- if(e>6){
- printf("Student nie zdal \n");
- return;
- }
- if(e<6){
- printf("Student zdal \n");
- return;
- }
- }
- if(z==9){
- if(e>0){
- printf("Student nie zdal \n");
- return;
- }
- if(e<0){
- printf("Nie da sie miec ujemnej liczby punktow deficytowych \n");
- return;
- }
- }
- }
- void powt(struct student **tab, int i){
- int j;
- for(j=0;j<i;j++){
- tab[j]->pop=tab[j]->ects*20;
- }
- }
- void print(struct student *tab, int j){
- printf("Student %s zaplaci za powtorki %d zl \n",tab[j].nazwisko,tab[j].pop);
- }
- void zapis(struct student *tab, int i, char *path){
- FILE *f;
- int j;
- if(tab==NULL) return;
- f=fopen(path,"wt");
- if(f==NULL) return;
- fprintf(f,"%d \n",i);
- for(j=0;j<i;j++){
- fprintf(f,"%s ;%d ;%d ;%d \n",tab[j].nazwisko,tab[j].nr,tab[j].ects,tab[j].pop);
- }
- fclose(f);
- }
- struct student *wczytaj(int i,char *path){
- FILE *f;
- int j;
- struct student *tab;
- f=fopen(path,"rt");
- if(f==NULL) return tab;
- if(fscanf(f,"%d",&i)!=1) return tab;
- tab=(struct student*)calloc(i,sizeof(struct student));
- for(j=0;j<i;j++){
- fscanf(f,"%s ;%d ;%d ;%d",tab[j].nazwisko,&tab[j].nr,&tab[j].ects,&tab[j].pop);
- }
- fclose(f);
- return tab;
- }
- void fre(struct student **tab, int i){
- int j;
- if(*tab==NULL) return;
- for(j=0;j<i;j++){
- free(tab[j]);
- }
- free(*tab);
- }
- void druk(struct student *tab, int i){
- int j;
- for(j=0;j<i;j++){
- printf("%d %s %d %d %d \n",(j+1),tab[j].nazwisko,tab[j].nr,tab[j].ects,tab[j].pop);
- }
- printf("\n");
- }
- int main(){
- FILE *f;
- int z, i=0,j;
- struct student *tab;
- tab=(struct student*)malloc(1*sizeof(struct student));
- while(1){
- printf("0: Wyjdz z programu \n"
- "1: Dodaj studenta \n"
- "2: Usun studenta \n"
- "3: Sprawdz czy student zdal \n"
- "4: Oblicz ile studenci zaplaca za powtorki \n"
- "5: Zobacz ile dany student zaplaci za powtorki \n"
- "6: Zapisz studentow do pliku \n"
- "7: Pobierz studentow z pliku \n"
- "8: Wydrukuj liste studentow \n");
- scanf("%d",&z);
- if(z==0) break;
- switch(z){
- case 1:{
- tab=(struct student*)realloc(tab,(i+1)*sizeof(struct student));
- tab[i]=dodaj();
- i++;
- break;
- }
- case 2:{
- j=szukaj(tab,i);
- for(z=j-1;z<i;z++){
- tab[z]=tab[z+1];
- }
- tab=(struct student*)realloc(tab,(i-1)*sizeof(struct student));
- i--;
- break;
- }
- case 3:{
- zal(tab,szukaj(tab,i));
- break;
- }
- case 4:{
- powt(&tab,i);
- break;
- }
- case 5:{
- print(tab,szukaj(tab,i));
- break;
- }
- case 6:{
- zapis(tab,i,"studenci.csv");
- break;
- }
- case 7:{
- fre(&tab,i);
- tab=wczytaj(i,"studenci.csv");
- break;
- }
- case 8:{
- druk(tab,i);
- break;
- }
- default:{
- printf("Nie ma takiego polecenia \n");
- break;
- }
- }
- }
- fre(&tab,i);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement