Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- struct hs
- {
- int CODEstudent;
- char Name[26];
- float ws,pt,pe,fe;
- };
- void trim(char a[])
- {
- int i,j,k,h,n;
- char b[100];
- n = strlen(a);
- i=0;
- j=n-1;
- while(a[i]==' ')
- i++;
- while(a[j]==' ')
- j--;
- k=0;
- for(h=i;h<=j;h++)
- b[k++]=a[h];
- b[k]='\0';
- strcpy(a,b);
- }
- void InputValidf (float *n)
- {
- char c;
- int re, valid=0;
- do{
- fflush(stdin);
- re= scanf ("%f%c",n,&c);
- if (re<0 || re>10)
- printf (" Data type errox !!\n");
- else if (c != '\n')
- printf ("Integer musted be inputted !!\n");
- else
- valid =1;
- if (valid==0)
- printf ("Repeat input again !\n");
- } while (!valid);
- }
- int FindStd(hs a[], int &RollNo, int size)
- {
- bool found = false;
- printf("Enter RollNo to find: "); scanf("%d", &RollNo);
- printf ("STT | MSV | Ten | Workshop | Progress Test | PE | FE\n");
- for(int i=1; i<=size; i++)
- if(a[i].CODEstudent == RollNo)
- {
- found = true;
- printf("\n%2d. %5d %15s %6.2f %6.2f %6.2f %6.2f\n", i, a[i].CODEstudent, a[i].Name, a[i].ws, a[i].pt, a[i].pe, a[i].fe);
- return i;
- }
- if (!found)
- {
- printf("Roll number not found\n");
- return -1;
- }
- }
- void EditStd(hs a[], int &CODEstudent, int size)
- {
- int i_found;
- i_found = FindStd(a, CODEstudent, size);
- if(i_found!=-1)
- {
- printf("MSV: "); scanf("%d", &a[i_found].CODEstudent);
- fflush(stdin);
- printf("FullName: "); gets(a[i_found].Name);
- printf("workshop: "); scanf("%f", &a[i_found].ws);
- fflush(stdin);
- printf("progress test: "); scanf("%f", &a[i_found].pt);
- fflush(stdin);
- printf("pratical exam: "); scanf("%f", &a[i_found].pe);
- fflush(stdin);
- printf("final exam: "); scanf("%f", &a[i_found].fe);
- fflush(stdin);
- }
- else
- printf("Not found\n");
- }
- void DeleteStd(hs a[], int &CODEstudent, int *size)
- {
- int i_found;
- int i;
- i_found = FindStd(a, CODEstudent, *size);
- if(i_found!=-1)
- {
- for (i=i_found;i<*size;i++)
- a[i]=a[i+1];
- (*size)--;
- }
- else
- printf("Not found\n");
- }
- int LoadFile(char *filename, hs a[], int *size)
- {
- char ch;
- int i;
- char ten[50], msv[50], workshop[50],pract[50], parte[50],finale[50];
- FILE *fp = fopen(filename,"r+");
- if(fp==NULL)
- {
- printf(" file %s not found\n",filename);
- return(0);
- }
- rewind(fp);
- i=1;
- while(fscanf(fp,"%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^\n]\n",msv,ten,workshop,pract,parte,finale)==6)
- {
- trim(ten);
- trim(msv);
- trim(workshop);
- trim(pract);
- trim(parte);
- trim(finale);
- a[i].CODEstudent = atoi(msv);
- strcpy(a[i].Name,ten);
- a[i].ws = atof(workshop);
- a[i].pt = atof(pract);
- a[i].pe = atof(parte);
- a[i].fe = atof(finale);
- i++;
- }
- *size=i-1;
- fclose(fp);
- return(1);
- }
- int SaveFile( char *filename, hs a[], int size)
- {
- char ch;
- int i;
- FILE *fp=NULL;
- fp = fopen(filename, "r+");
- if(fp!=NULL)
- {
- printf("Replace file %s (y/n)?", filename);
- fclose(fp);
- ch = getche();
- if(ch!='y')
- return(0);
- }
- fp = fopen(filename, "w+");
- if(fp!=NULL)
- {
- for(i=1; i<=size; i++)
- {
- fprintf(fp, "\n%5d | %15s | %2.2f | %2.2f | %2.2f | %2.2f", a[i].CODEstudent, a[i].Name, a[i].ws, a[i].pt, a[i].pe, a[i].fe);
- }
- fclose(fp);
- }
- else
- printf("failed");
- return(1);
- }
- int main()
- {
- char ch1='\0',ch2='\0',ch3='\0',ch4='\0';
- char ma[10];FILE *fp;char buff[255];
- int stdcount=0,i,j,CODEstudent;
- hs a[60];
- system("cls");
- fflush(stdin);
- printf("********************************\n");
- printf("* *\n");
- printf("*HE THONG QUAN LI LOP HOC *\n");
- printf("*1. Quan li danh sach sinh vien*\n");
- printf("*2. Thoat *\n");
- printf("*Moi ban nhap lua chon: *\n");
- printf("* *\n");
- printf("* *\n");
- printf("********************************\n");
- scanf("%c",&ch1);
- fflush(stdin);
- while (ch1!='2')
- {
- switch (ch1)
- {
- case '1':
- {
- system("cls");
- fflush(stdin);
- printf("******************************************************\n");
- printf("*1. In ra danh sach sinh vien *\n");
- printf("*2. Them mot sinh vien moi vao lop *\n");
- printf("*3. Tim Sinh Vien Theo Ma *\n");
- printf("*4. Sua, xoa mot sinh vien theo ma sinh vien *\n");
- printf("*5. Nap danh sach tu file *\n");
- printf("*6. In danh sach ra file *\n");
- printf("*7. Bang diem cua lop *\n");
- printf("*8. Thong ke sinh vien trong lop *\n");
- printf("*9. Tro ve menu chinh *\n");
- printf("*Moi ban nhap lua chon: *\n");
- printf("******************************************************\n");
- scanf("%c",&ch2);
- switch (ch2)
- {
- case '1':
- {
- system("cls");
- fflush(stdin);
- printf("DANH SACH SINH VIEN\n");
- if (stdcount==0) printf ("Khong co sinh vien nao...");
- else
- printf ("-----------------------------\n");
- printf ("|STT MSV Ho Ten |\n");
- {
- for (i=1;i<=stdcount;i++)
- {
- printf("|%2d. %5d. %16s|\n" ,i,a[i].CODEstudent,a[i].Name);
- }
- }
- printf ("-----------------------------\n");
- system("pause");
- }
- break;
- case '2':
- {
- system("cls");
- fflush(stdin);
- int kt=0;
- printf("nhap vao ma so sinh vien: \n");
- fflush(stdin);
- scanf("%d",&a[stdcount+1].CODEstudent);
- for (i=1;i<stdcount;i++) if (a[stdcount+1].CODEstudent==a[i].CODEstudent)
- {
- printf("MSSV ban vua nhap da bi trung\n");
- kt=1;
- break;
- }
- if (kt==0)
- {
- stdcount++;
- fflush(stdin);
- printf("nhap vao ten sinh vien: \n");
- fflush(stdin);
- //InputValidC (&a[stdcount].Name);
- scanf("%[^\n]",&a[stdcount].Name);
- printf("nhap vao diem workshop: \n");
- fflush(stdin);
- InputValidf (&a[stdcount].ws);
- printf("nhap vao diem progress test: \n");
- fflush(stdin);
- InputValidf (&a[stdcount].pt);
- printf("nhap vao diem pratical exam: \n");
- fflush(stdin);
- InputValidf (&a[stdcount].pe);
- printf("nhap vao diem final exam: \n");
- fflush(stdin);
- InputValidf (&a[stdcount].fe);
- }
- system("pause");
- }
- break;
- case '3':
- {
- FindStd(a, CODEstudent, stdcount);
- system("pause");
- }
- break;
- case '4':
- {
- int ch;
- char m[20];
- printf("Nhap vao 1 de xoa, 2 de sua:\n");
- scanf("%d",&ch);
- if(ch>2 || ch<0) printf("Nhap sai, nhap lai!!");
- fflush(stdin);
- while (ch==2 || ch==1)
- {
- if (ch==1)
- {
- DeleteStd(a, CODEstudent, &stdcount);
- }
- if (ch==2)
- {
- EditStd(a,CODEstudent,stdcount);
- }
- break;
- }
- system("pause");
- }
- break;
- case '5':
- if(LoadFile("text.dat", a, &stdcount)==1)
- printf("loaded\n");
- else
- printf("error\n");
- system("pause");
- break;
- case '6':
- if(SaveFile("text.dat", a, stdcount)==1)
- printf("saved\n");
- else
- printf("error");
- system("pause\n");
- break;
- case '7' :
- {
- fflush(stdin);
- system("cls");
- printf ("BANG DIEM CUA LOP\n");
- printf("*______________________________________________________________________________*\n");
- printf ("STT Full Name Workshop Progress Test Practical Exam Final Exam\n");
- for (i=1;i<stdcount;i++)
- {
- printf (" %2d. |%15s | %2.2f | %2.2f | %2.2f | %2.2f \n", i, a[i].Name, a[i].ws, a[i].pt, a[i].pe, a[i].fe);
- }
- printf("*______________________________________________________________________________*\n");
- system("pause");
- }
- break;
- case '8':
- {
- float tb=0,max=0,min=10;
- int cc,cc3;
- char cc2[26],cc4[26];
- system("cls");
- printf ("THONG KE CU THE SINH VIEN\n");
- printf("Passed: \n");
- for (i=1;i<=stdcount;i++)
- {
- if ((a[i].ws>0) && (a[i].pt>0) && (a[i].pe>4) && (a[i].fe>4) && (a[i].ws*0.1+a[i].pt*0.2+a[i].pe*0.4+a[i].fe*0.3) >= 5) printf("%6d - %15s \n",a[i].CODEstudent,a[i].Name);
- }
- printf("\n");
- printf("Sinh vien truot: \n");
- for (i=1;i<=stdcount;i++)
- {
- if ((a[i].ws=0) || (a[i].pt=0) || (a[i].pe<4) || (a[i].fe<4) || (a[i].ws*0.1+a[i].pt*0.2+a[i].pe*0.4+a[i].fe*0.3) < 5) printf("%6d - %15s \n",a[i].CODEstudent,a[i].Name);
- }
- printf("\n");
- printf("Sinh vien duoc hoc bong: \n");
- for (i=1;i<=stdcount;i++)
- {
- if ((a[i].ws/10+a[i].pt/5+a[i].pe*2/5+a[i].fe*3/10 +2)>= 9) printf("%6d - %15s \n",a[i].CODEstudent,a[i].Name);
- }
- printf("\n");
- printf("Sinh vien diem cao nhat la: \n");
- for (i=1;i<=stdcount;i++)
- {
- tb=(a[i].ws/10+a[i].pt/5+a[i].pe*2/5+a[i].fe*3/10 +3);
- if (tb>=max)
- {
- max=tb;
- cc=a[i].CODEstudent;
- strcpy(cc2,a[i].Name);
- }
- }
- printf("%6d - %15s Trung binh mon %2.2f\n",cc,cc2,max);
- printf("Sinh vien diem thap nhat la: \n");
- for (i=1;i<=stdcount;i++)
- {
- tb=(a[i].ws*0.1+a[i].pt*0.2+a[i].pe*0.4+a[i].fe*0.3);
- if (tb<=min)
- {
- min=tb;
- cc3=a[i].CODEstudent;
- strcpy(cc4,a[i].Name);
- }
- }
- printf("%6d - %15s Trung binh mon %2.2f\n",cc3,cc4,min);
- system("pause");
- }
- break;
- case '9':
- {
- system("cls");
- fflush(stdin);
- printf("******************************************************\n");
- printf("*Cam on ban da su dung phan mem *\n");
- printf("*Moi chi tiet va gop y xin lien he *\n");
- printf("* *\n");
- printf("* *\n");
- printf("* *\n");
- printf("* *\n");
- printf("* *\n");
- printf("* Trieu Nam Hai*\n");
- printf("* SDT: 01683574189*\n");
- printf("******************************************************\n");
- system("pause");
- }
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment