- #include<stdio.h>
- #include<string.h>
- #include <stdlib.h>
- #include <time.h>
- #define SIZE 100
- #define true 0
- #define false 1
- struct student
- {
- char stdid[SIZE];
- char name[SIZE];
- int lvl;
- double sum, eng, math, sci, his, fil, genav;
- };
- struct student st[SIZE];
- int count = 0;
- FILE *f;
- int writefile()
- {
- int i;
- f = fopen("sms.txt", "w");
- if (f == NULL)
- return -1;
- fprintf(f, "%d\n", count);
- for (i = 0; i < count; ++i)
- {
- fputs(st[i].stdid, f);
- fprintf(f, "\n");
- fputs(st[i].name, f);
- fprintf(f, "\n");
- fprintf(f, "%d\n", st[i].lvl);
- fprintf(f, "\n");
- fprintf(f, "%.2lf\n", st[i].eng);
- fprintf(f, "%.2lf\n", st[i].math);
- fprintf(f, "%.2lf\n", st[i].sci);
- fprintf(f, "%.2lf\n", st[i].his);
- fprintf(f, "%.2lf\n", st[i].fil);
- }
- fclose(f);
- return 0;
- }
- int writefile2()
- {
- int i;
- f = fopen("sms.txt", "w");
- if (f == NULL)
- return -1;
- fprintf(f, "%d\n", count);
- for (i = 0; i < count; ++i)
- {
- fputs(st[i].stdid, f);
- fprintf(f, "\n");
- fputs(st[i].name, f);
- fprintf(f, "\n");
- fprintf(f, "%d\n", st[i].lvl);
- fprintf(f, "\n");
- }
- fclose(f);
- return 0;
- }
- int readFile()
- {
- int n = 0;
- int i;
- f = fopen("sms.txt", "r");
- if (f == NULL)
- return -1;
- fscanf(f, "%d\n", &n);
- for (i = 0; i < n; ++i)
- {
- fgets(st[i].stdid, SIZE, f);
- st[i].stdid[strlen(st[i].stdid) - 1] = 0; // remove new lines
- fgets(st[i].name, SIZE, f);
- st[i].name[strlen(st[i].name)-1] = 0;
- fscanf(f, "%d", &st[i].lvl);
- fscanf(f, "%.2lf", &st[i].eng);
- fscanf(f, "%.2lf", &st[i].math);
- fscanf(f, "%.2lf", &st[i].sci);
- fscanf(f, "%.2lf", &st[i].his);
- fscanf(f, "%.2lf\n", &st[i].fil);
- }
- fclose(f);
- return n;
- }
- int readFile2()
- {
- int n = 0;
- int i;
- f = fopen("sms.txt", "r");
- if (f == NULL)
- return -1;
- fscanf(f, "%d\n", &n);
- for (i = 0; i < n; ++i)
- {
- fgets(st[i].stdid, SIZE, f);
- st[i].stdid[strlen(st[i].stdid) - 1] = 0; // remove new lines
- fgets(st[i].name, SIZE, f);
- st[i].name[strlen(st[i].name)-1] = 0;
- fscanf(f, "%d", &st[i].lvl);
- fclose(f);
- return n;
- }
- }
- void delay(int number_of_seconds)
- {
- int milli_seconds = 1000 * number_of_seconds;
- clock_t start_time = clock();
- while (clock() < start_time + milli_seconds);
- }
- void deletestudent()
- {
- count=readFile();
- char stdid[SIZE];
- int i,j;
- int z=false;
- printf("ENTER ID YOU WANT TO DELETE: ");
- fflush(stdin);
- gets(stdid);
- for(i=0;i<count;i++)
- {
- z=true;
- if(strcmp(st[i].stdid,stdid)==0)
- {
- for( j=i; j<(count-1); j++)
- {
- st[j]=st[j+1];
- }
- printf("\nSTUDENT HAS BEEN REMOVED SUCCESSFULLY!");
- count--;
- }
- }
- if(z==false)
- {
- printf("STUDENT ID NOT FOUND!");
- }
- writefile();
- }
- int IDChecker (int i, int j)
- {
- count=readFile();
- printf("\nSTUDENT ID: ");
- fflush(stdin);
- gets(st[count].stdid);
- if (strcmp(st[i].stdid,st[j].stdid)==0)
- {
- printf("ID NUMBER IS ALREADY TAKEN!");
- return IDChecker(i++,j--);
- }
- }
- void addnewstudent()
- {
- readFile2();
- if (count>0)
- {
- count=readFile2();
- IDChecker(0,count);
- }
- else
- {
- printf("\nSTUDENT ID: ");
- fflush(stdin);
- gets(st[count].stdid);
- }
- printf("FULL NAME: ");
- gets(st[count].name);
- {
- int c=10;
- int lvl;
- while (c!=0)
- {
- printf("GRADE LEVEL(1-6): ");
- scanf("%d", &(st[count].lvl));
- if ((st[count].lvl)>=1 && (st[count].lvl)<=6)
- {
- c=0;
- }
- else
- {
- printf("\nSORRY, YOU HAVE ENTERED AN INVALID NUMBER. PLEASE TRY AGAIN.\n");
- }
- printf("\n");
- }
- }
- ++count;
- writefile2();
- }
- int checkID(char stdid[])
- {
- int i;
- count=readFile();
- readFile();
- for(i=0;i<count;i++)
- {
- if(strcmp(stdid,st[i].stdid)!=0)
- {
- fclose(f);
- }
- return 1;
- }
- fclose(f);
- return 0;
- }
- void displayallstudents()
- {
- int i;
- count = readFile2();
- printf("\n");
- printf("\n");
- printf("\n\t\t\t\t STUDENT NAME\t-\tSTUDENT ID\t-\tGRADE LEVEL");
- printf("\n\t\t\t ----------------------------------------------------------------------\n");
- printf("\n");
- printf("\n");
- for (i=0;i<count;i++)
- {
- printf("\t\t\t\t%s\t-\t%s\t-\t%d\n", st[i].name, st[i].stdid, st[i].lvl);
- }
- }
- void inputgrades()
- {
- char stdid[SIZE];
- int test;
- int i;
- int choice;
- printf("ENTER STUDENT ID: ");
- fflush(stdin);
- gets(stdid);
- test=checkID(stdid);
- if (test == 0)
- {
- printf("STUDENT ID NOT FOUND");
- }
- else
- {
- readFile();
- {
- for(i=0;i<count;i++)
- {
- if(strcmp(stdid,st[i].stdid)!=0)
- writefile();
- else
- {
- printf("\nFULL NAME: %s", st[i].name);
- printf("\nSTUDENT ID: %s", st[i].stdid);
- printf("\nGRADE LEVEL: %d", st[i].lvl);
- printf("\n\nREPORT CARD:\n\n");
- printf("ENGLISH:\t");
- scanf("%lf", &(st[i].eng));
- printf("MATH:\t\t");
- scanf("%lf", &(st[i].math));
- printf("SCIENCE:\t");
- scanf("%lf", &(st[i].sci));
- printf("HISTORY:\t");
- scanf("%lf", &(st[i].his));
- printf("FILIPINO:\t");
- scanf("%lf", &(st[i].fil));
- }
- writefile();
- }
- }
- }
- fclose(f);
- f = fopen("sms.txt", "r");
- readFile();
- {
- writefile();
- }
- fclose(f);
- }
- void viewgrades()
- {
- char stdid[SIZE];
- int test;
- int i;
- int choice;
- printf("ENTER STUDENT ID: ");
- fflush(stdin);
- gets(stdid);
- test=checkID(stdid);
- if (test == 0)
- {
- printf("STUDENT ID NOT FOUND");
- }
- else
- {
- readFile();
- {
- for(i=0;i<count;i++)
- {
- if(strcmp(stdid,st[i].stdid)!=0)
- writefile();
- else
- {
- printf("\nWELCOME TO %s's PROFILE!\n", st[i].name);
- printf("\nFULL NAME: %s", st[i].name);
- printf("\nSTUDENT ID: %s", st[i].stdid);
- printf("\nGRADE LEVEL: %d", st[i].lvl);
- printf("\n\nREPORT CARD:\n\n");
- printf("SUBJECT\t\t|\tGRADE\t\t|\tREMARKS");
- printf("\n----------------------------------------------------------------------\n");
- printf("\nENGLISH\t\t|\t%.2lf\t\t|\t", st[i].eng);
- if (st[i].eng < 75)
- {
- printf("FAILED\n");
- }
- else
- {
- printf("PASSED\n");
- }
- printf("MATH\t\t|\t%.2lf\t\t|\t", st[i].math);
- if (st[i].math < 75)
- {
- printf("FAILED\n");
- }
- else
- {
- printf("PASSED\n");
- }
- printf("SCIENCE\t\t|\t%.2lf\t\t|\t", st[i].sci);
- if (st[i].sci < 75)
- {
- printf("FAILED\n");
- }
- else
- {
- printf("PASSED\n");
- }
- printf("HISTORY\t\t|\t%.2lf\t\t|\t", st[i].his);
- if (st[i].his < 75)
- {
- printf("FAILED\n");
- }
- else
- {
- printf("PASSED\n");
- }
- printf("FILIPINO\t|\t%.2lf\t\t|\t", st[i].fil);
- if (st[i].fil < 75)
- {
- printf("FAILED\n");
- }
- else
- {
- printf("PASSED\n");
- }
- printf("----------------------------------------------------------------------\n");
- st[i].sum = st[i].eng + st[i].math + st[i].sci + st[i].his + st[i].fil;
- st[i].genav = st[i].sum / 5;
- printf("GENERAL AVERAGE\t|\t%.2lf\t\t|\t", st[i].genav);
- if (st[i].genav < 75)
- {
- printf("FAILED\n");
- }
- else
- {
- printf("PASSED\n");
- }
- writefile();
- }
- }
- }
- fclose(f);
- f = fopen("sms.txt", "r");
- readFile();
- {
- writefile();
- }
- fclose(f);
- }
- }
- void editstudent()
- {
- char stdid[SIZE];
- int test;
- int i;
- int choice;
- printf("ENTER STUDENT ID: ");
- fflush(stdin);
- gets(stdid);
- test=checkID(stdid);
- if (test == 0)
- {
- printf("STUDENT ID NOT FOUND");
- }
- else
- {
- readFile();
- {
- for(i=0;i<count;i++)
- {
- if(strcmp(stdid,st[i].stdid)!=0)
- writefile();
- else
- {
- printf("\nWHAT DO YOU WANT TO UPDATE?\n\n");
- printf("<1> STUDENT ID\n");
- printf("<2> FULL NAME\n");
- printf("<3> GRADE LEVEL\n");
- printf("<4> ENGLISH GRADE\n");
- printf("<5> MATH GRADE\n");
- printf("<6> SCIENCE GRADE\n");
- printf("<7> HISTORY GRADE\n");
- printf("<8> FILIPINO GRADE\n");
- printf("<9> UPDATE ALL INFORMATION OF STUDENT\n");
- printf("\nCHOOSE TASK TO PERFORM: ");
- fflush(stdin);
- scanf("%d", &choice);
- switch (choice)
- {
- case 1:
- printf("STUDENT ID: ");
- fflush(stdin);
- gets(st[i].stdid);
- break;
- case 2:
- printf("FULL NAME: ");
- fflush(stdin);
- gets(st[i].name);
- break;
- case 3:
- {
- int c=10;
- int lvl;
- while (c!=0)
- {
- printf("\nGRADE LEVEL(1-6): ");
- scanf("%d", &(st[i].lvl));
- if ((st[i].lvl)>=1 && (st[i].lvl)<=6)
- {
- c=0;
- }
- else
- {
- printf("\nSORRY, YOU HAVE ENTERED AN INVALID NUMBER. PLEASE TRY AGAIN.\n");
- }
- printf("\n");
- }
- }
- break;
- case 4:
- printf("\nENGLISH GRADE: ");
- scanf("%lf", &(st[i].eng));
- break;
- case 5:
- printf("\nMATH GRADE: ");
- scanf("%lf", &(st[i].math));
- break;
- case 6:
- printf("\nSCIENCE GRADE: ");
- scanf("%lf", &(st[i].sci));
- break;
- case 7:
- printf("\nHISTORY GRADE: ");
- scanf("%lf", &(st[i].his));
- break;
- case 8:
- printf("\nFILIPINO GRADE: ");
- scanf("%lf", &(st[i].fil));
- break;
- default:
- printf("YOU HAVE ENTERED AN INVALID NUMBER.");
- break;
- }
- writefile();
- }
- }
- }
- fclose(f);
- f = fopen("sms.txt", "r");
- readFile();
- {
- writefile();
- }
- fclose(f);
- printf("PROFILE UPDATED");
- }
- }
- int main ()
- {
- int a=10;
- int id;
- char name[SIZE];
- char pswd[SIZE];
- system("color F6");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("\t\t O==========================================================O\n");
- printf("\t\t | OUR LADY OF FATIMA UNIVERISTY - VALENZUELA CITY CAMPUS |\n");
- printf("\t\t | |");
- printf("\n\t\t | WELCOME TO THE INSTRUCTOR PORTAL! |\n");
- printf("\t\t O==========================================================O\n");
- printf("\n");
- printf("\n");
- printf("\n");
- while (a!=0)
- {
- char un[SIZE];
- char pswd[SIZE];
- printf("\n\t\t\t\t\t\t USERNAME: ");
- scanf("%s", un);
- printf("\t\t\t\t\t\t PASSWORD: ");
- scanf("%s", pswd);
- if (strcmp(un, "olfu") == 0 && strcmp(pswd, "ccs") == 0)
- {
- printf("\n\t\t\t\t\tLOGIN SUCCESSFUL! PLEASE WAIT A MOMENT...");
- a=0;
- delay(2);
- system("cls");
- }
- else
- {
- printf("\n\t\t\t THE USERNAME AND/OR PASSWORD IS INCORRECT. PLEASE TRY AGAIN IN 3 SECONDS.");
- delay(3);
- system("cls");
- }
- printf("\n");
- }
- int i, j, ch, num, flag, stdid;
- int choice, upd, updchoice;
- struct student *st;
- num = 0;
- st = (struct student *)malloc(sizeof(struct student) * num);
- while (1)
- {
- printf("\n");
- printf("\n");
- printf("\n\t\t O==================STUDENT MANAGEMENT SYSTEM==================O");
- printf("\n\t\t\t\t| |");
- printf("\n\t\t\t\t| <1> ADD A NEW STUDENT\t\t\t |\n");
- printf("\t\t\t\t| <2> SHOW STUDENT LIST\t\t\t |\n");
- printf("\t\t\t\t| <3> INPUT STUDENT'S GRADES\t\t |\n");
- printf("\t\t\t\t| <4> VIEW STUDENT'S GRADES\t\t |\n");
- printf("\t\t\t\t| <5> EDIT STUDENT PROFILE\t\t |\n");
- printf("\t\t\t\t| <6> DELETE A STUDENT\t\t\t |\n");
- printf("\t\t\t\t| <7> EXIT\t\t\t\t |");
- printf("\n\t\t\t\t| |");
- printf("\n\t\t O=============================================================O\n");
- printf("\n");
- printf("\n");
- printf("\n\t\t\t\t\t CHOOSE A TASK TO PERFORM (1-7): ");
- scanf("%d", &choice);
- switch(choice)
- {
- case 1: addnewstudent();
- break;
- case 2: displayallstudents();
- break;
- case 3: inputgrades();
- break;
- case 4: viewgrades();
- break;
- case 5: editstudent();
- break;
- case 6: deletestudent();
- break;
- case 7: exit(1);
- break;
- default:
- printf("YOU HAVE ENTERED AN INVALID VALUE");
- break;
- }
- }
- while(choice!=8);
- }
[text] Student Management System with File Handling (WIP)
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: