#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define SIZE 2
function declaration
void add ();//Add Student information function
void Show ();//Display student information function
void fail ();//Failed Student information function
void Excellent ();//excellent student information function
void Delete ();//delete the specified student information function
void exit ();//exit Student management System
Structural body.
struct Student
{
int num;//No.
Char name[20];//name
Char sex[10];//Sex
int age;//Age
Char add[20];//Address
Float score[3];//Results
}stu[size];
interface functions
void InterFace ()
{
printf ("\t\t******************************************");
printf ("\n\t\t******************************************");
printf ("\n\t\t\t*** welcome into Student management system ***\n");
printf ("\t\t******************************************\n");
printf ("\t\t******************************************\t\n");
printf ("\n\t<1> Add student information \t\t\t<2> show student information \ n");
printf ("\t<3> students have \t\t<4> excellent students (each course is more than 85) \ n");
printf ("\t<5> Delete specified student information \t\t<6> exit system \ n");
Select the function declaration.
void Select ();
Invokes the selection function.
Select ();
}
A function to add student information.
void Add ()
{
int i;
printf ("Please enter student's information: \ n");
for (i=0;i<size;i++)
{
printf ("Study No.:");
scanf ("%d", &stu[i].num);
printf ("Name:");
scanf ("%s", stu[i].name);
printf ("Age:");
scanf ("%d", &stu[i].age);
printf ("Gender:");
scanf ("%s", stu[i].sex);
printf ("Language score:");
scanf ("%f", &stu[i].score[0]);
printf ("Math score:");
scanf ("%f", &stu[i].score[1]);
printf ("English score:");
scanf ("%f", &stu[i].score[2]);
Open File operation
FILE *FP;
if (fp = fopen ("F:\\file.txt", "WB")) ==null)
{
printf ("Cannot open file\n");
}
for (i=0;i<size;i++)
if (fwrite (&stu[i],sizeof (struct Student), 1,FP)!=1)
printf ("File Write error!\n");
Fclose (FP);
System ("CLS"); Clear Screen
InterFace (); Calling interface functions
}
}
//Display student information.
Void Show ()
{
FILE *fp;
int i;
if (fp = fopen ("F:\\file.txt", "RB") ==null)
{
printf ("Cannot open file\n");
}
printf ("School name, age, gender, language score, English score,");
printf ("\ n");
for (i=0;i<size;i++)
{
Fread (&stu[i],sizeof (struct Student), 1,FP);
printf ("\n%2d%-6s%4d%-6s%4.2f\t%4.2f\t%4.2f\n", Stu[i].num,stu[i].name,
Stu[i].age,stu[i].sex,stu[i].score[0 ],STU[I].SCORE[1],STU[I].SCORE[2]);
}
fclose (FP);
printf ("Press any key to return:");
Getch ();
System ("CLS");
InterFace ();
}
//Fail student information function.
Void Fail ()
{
int i;
FILE *FP;
if (fp = fopen ("F:\\file.txt", "R") ==null)
{
printf ("Cannot open file!\n");
}
printf ("Failing student information is as follows:");
printf ("School name, age, gender, and English results in math scores");
printf ("\ n");
for (i=0;i<size;i++)
{
Fread (&stu[i],sizeof (struct Student), 1,FP);
if (stu[i].score[0]<60 | | stu[i].score[1]<60 | | stu[i].score[2]<60)
printf ("\n%2d%-6s%4d%-6s%4.2f\t% 4.2f\t%4.2f\n ",
Stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].score[0],
Stu[i].score[1],stu[i]. SCORE[2]);
}
fclose (FP);
printf ("Press any key to return:");
Getch ();
System ("CLS");
InterFace ();
}
Excellent student information is as follows.
void Excellent ()
{
int i;
FILE *FP;
if (fp = fopen ("F:\\file.txt", "R")) ==null)
{
printf ("Cannot open file!\n");
}
printf ("Excellent student information as follows:");
printf ("School number, name, age, gender, language score, Math score, English score");
printf ("\ n");
for (i=0;i<size;i++)
{
Fread (&stu[i],sizeof (struct Student), 1,FP);
if (stu[i].score[0]>85 | | stu[i].score[1]>85 | | stu[i].score[2]>85)
printf ("\n%2d%-6s%4d%-6s%4.2f\t%4.2f\t%4.2f\n",
Stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].score[0],
STU[I].SCORE[1],STU[I].SCORE[2]);
}
Fclose (FP);
printf ("Press any key to return:");
Getch ();
System ("CLS");
InterFace ();
}
Deletes the information for the specified student.
void Delete ()
{
int i,n;
FILE *FP;
if (fp = fopen ("F:\\file.txt", "R")) ==null)
{
printf ("Cannot open file\n");
}
printf ("Please enter the student number for deletion:");
scanf ("%d", &n);
for (i=0;i<size;i++)
{
Fread (&stu[i],sizeof (struct Student), 1,FP);
if (Stu[i].num = = N)
Continue
printf ("\n%2d%-6s%4d%-6s%4.2f\n%4.2f\t%4.2f\n", Stu[i].num,stu[i].name,
STU[I].AGE,STU[I].SEX,STU[I].SCORE[0],STU[I].SCORE[1],STU[I].SCORE[2]);
}
Fclose (FP);
printf ("Press any key to return:");
Getch ();
System ("CLS");
InterFace ();
}
Exit the system.
void Exit ()
{
printf ("Press any key to exit");
Exit (0);
}
Select the action mode function.
void Select ()
{
int n;
printf ("Enter The integer Number: (1~6)");
scanf ("%d", &n);
Switch (n)
{
Case 1:system ("CLS"); Add (); Break
Case 2:system ("CLS"); Show (); Break
Case 3:system ("CLS"); Fail (); Break
Case 4:system ("CLS"); Excellent (); Break
Case 5:system ("CLS"); Delete (); Break
Case 6:system ("CLS"); Exit (); Break
default:printf ("error!"); Break
}
}
Main function
int main ()
{
InterFace ();
return 0;
}
/*
void Add ()
{
int i;
printf ("Please enter student's information: study number, name, age, gender, language score, Math score, English score): \ n");
for (i=0;i<size;i++)
{
printf ("Study No.:");
scanf ("%d", &stu[i].num);
printf ("Name:");
scanf ("%s", stu[i].name);
printf ("Age:");
scanf ("%d", &stu[i].age);
printf ("Gender:");
scanf ("%s", stu[i].sex);
printf ("Language score:");
scanf ("%f", stu[i].score1);
printf ("Math score:");
scanf ("%f", Stu[i].score2);
printf ("English score:");
scanf ("%f", stu[i].score3);
Opens the file operation.
FILE *FP;
if (fp = fopen ("F:\\file.txt", "WB")) ==null)
{
printf ("Cannot open file\n");
}
for (i=0;i<size;i++)
if (fwrite (&stu[i],sizeof (struct Student), 1,FP)!=1)
{
printf ("File Write error!\n");
}
Fclose (FP);
System ("CLS"); Clear the screen.
InterFace (); Call interface functions.
}
*/
"A small student management system"