C language to achieve student status management system
- 2020-06-03 07:27:19
- OfStack
The example of this paper shares the specific code of C language to achieve student status management system for your reference. The specific content is as follows
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
//********************************** The structure of the body *************************************
struct score
{
char class_num[10];
char person_num[10];
char name[15];
char sex;
int num;
}stu;
//****************************** The output *******************************************
void print1() // Output subject function
{
printf(" The class Student id The name gender score \n");
}
//***************************** The menu ********************************************
int menu() // The menu function
{
char i;
printf("\n\n\n\n");
puts("\t\t********************** The main menu ******************\t\n");
puts("\t\t\t\t1. Student information input \n");
puts("\t\t\t\t2. Student information browsing \n");
puts("\t\t\t\t3. Student information Retrieval \n");
puts("\t\t\t\t4. Student information modification \n");
puts("\t\t\t\t5. Deletion of student information \n");
puts("\t\t\t\t6. refund Out of the Department of system \n");
puts("\t\t**********************************************\t\n");
printf("\t\t\t Please select ( 1-6 ) :[ ]\b\b");
i=getchar();
system("cls");
return i;
}
//********************** Input function *******************************************
void Enter()
{
FILE *fp;
char ch;
if((fp=fopen("f:\\zimou.txt","a+"))==NULL)
{
printf("\nCannot open file!\n");
getch();
exit(1);
}
do
{
printf(" Please enter class :");scanf("%s",stu.class_num);getchar();
printf("\n");
printf(" Please enter your student number :");gets(stu.person_num);
printf("\n");
printf(" Please enter your name :");gets(stu.name);
printf("\n");
printf(" sex Don't (m/f):");scanf("%c",&stu.sex);getchar();
printf("\n");
printf(" points The number :");scanf("%d",&stu.num);getchar();
printf("\n");
fwrite(&stu,sizeof(stu),1,fp);
printf(" Continue to (y/n)?[ ]\b\b");
ch=getchar(); getchar();
}while(ch=='y'||ch=='Y');
fclose(fp);
system("cls");
}
//***************** Browse function **********************************************
void Browse()
{
FILE *fp;
int total=0;
if((fp=fopen("f:\\zimou.txt","a+"))==NULL)
{
printf("\tCan not open the inform file!");
getch();
exit(1);
}
while(fread(&stu,sizeof(stu),1,fp)==1)
{
total++;
if(total==1)
print1();
printf("%-10s%-10s%-20s",stu.class_num,stu.person_num,stu.name);
printf("%-8c",stu.sex);
printf("%-4d ",stu.num);
printf("\n");
}
fclose(fp);
printf("\n\n\t A total of %d records !\n",total);
printf("\tpress any key to continue!");
getchar();
getchar();
system("cls");
}
//******************* Query function *********************************************
void Query()
{
FILE * fp;
char num1[10];
char ch;
if((fp=fopen("f:\\zimou.txt","a+"))==NULL)
{
printf("\tCan not open the inform file!");
getch();
exit(1);
}
do
{
getchar();
rewind(fp);
printf("\n Please enter your student id :");
gets(num1);
while(fread(&stu,sizeof(stu),1,fp)==1)
if(strcmp(num1,stu.person_num)==0)
{
print1();
printf("%-10s%-10s%-20s",stu.class_num,stu.person_num,stu.name);
printf("%-8c",stu.sex);
printf("%-4d ",stu.num);
printf("\n");
break;
}
puts("\n");
printf(" Continue the query? (Y/N):[ ]\b\b");
ch=getchar();
}while(ch=='Y'||ch=='y');
fclose(fp);
system("cls");
}
//********************** Student grade modification function ***********************************
void Recopose()
{
FILE * fp1,* fp2;
char num1[10];
char ch;
getchar();
do
{
if((fp1=fopen("f:\\zimou.txt","a+"))==NULL)
{
printf("\tCan not open the infom file!");
getch();
exit(1);
}
if((fp2=fopen("f:\\ziye.txt","a+"))==NULL)
{
printf("\tCan not creat the temp file!");
getch();
exit(1);
}
printf(" Please enter the student number you want to modify :");
gets(num1);
while(fread(&stu, sizeof(stu),1,fp1)==1)
{
if(strcmp(num1,stu.person_num)==0)
{
print1();
printf("%-10s%-10s%-20s",stu.class_num,stu.person_num,stu.name);
printf("%-8c",stu.sex);
printf("%-4d ",stu.num);
printf("\n");
printf("\n\nPlease input the new information:\n");
printf("\t The class code :");gets(stu.class_num);
printf("\t Student student id :");gets(stu.person_num);
printf("\t The student's name :"); gets(stu.name);
printf("\t Students' gender :");gets(&stu.sex);
printf("\t Student achievement :");scanf("%d",&stu.num); getchar();
}
fwrite(&stu,sizeof(stu),1,fp2);
}
fclose(fp1);
fclose(fp2);
printf(" Modify the success !\n");
remove("f:\\zimou.txt");
rename("f:\\ziye.txt","f:\\zimou.txt");
printf(" Continue to modify? (Y/N):[ ]\b\b");
ch=getchar(); getchar();
}while(ch=='Y'||ch=='y');
system("cls");
}
//********************* Delete function ******************************************
void Delete()
{
FILE * fp1,* fp2;
int flag;
char num1[10];
char ch;
getchar();
do
{
if((fp1=fopen("f:\\zimou.txt","a+"))==NULL)
{
printf("\tCan not open the inform file!");
getch();
exit(1);
}
if((fp2=fopen("f:\\ziye.txt","a+"))==NULL)
{
printf("\tCan not creat the temp file!");
getch();
exit(1);
}
printf(" Please enter the student number you want to delete :");
gets(num1);
flag=0;
while(fread(&stu,sizeof(stu),1,fp1)==1)
{
if(strcmp(num1,stu.person_num)==0)
{
print1();
printf("%-10s%-10s%-20s",stu.class_num,stu.person_num,stu.name);
printf("%-8c",stu.sex);
printf("%-4d ",stu.num);
printf("\n");
flag=1;
}
else
fwrite(&stu,sizeof(stu),1,fp2);
}
fclose(fp1);
fclose(fp2);
if(flag==1)
{
remove("f:\\zimou.txt");
rename("f:\\ziye.txt","f:\\zimou.txt");
}
else
printf("Can not find this record!\n");
printf(" Continue to delete ?(Y/N):[ ]\b\b");
ch=getchar(); getchar();
}while(ch=='Y'||ch=='y');
system("cls");
}
//*********************************** exit **************************************
void Exit()
{
puts("\n\t\t\t\t Thanks for using this system!! \n\n\t\t\t\t If you have any questions, please contact: 1005483758@qq.com \n");
exit(0);
}
//****************** The welcome screen **********************************
void Welcome()
{
printf("\n\n");
printf(" \t ┏ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ┓ \n");
printf(" \t ┃ ********************************************************** ┃ \n");
printf(" \t ┃ *** ┏ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ┓ *** ┃ \n");
printf(" \t ┃ *** ┃ ************************************************ ┃ *** ┃ \n");
printf(" \t ┃ *** ┃ *** **** ┃ *** ┃ \n");
printf(" \t ┃ *** ┃ *** Welcome to use the Student achievement management system **** ┃ *** ┃ \n");
printf(" \t ┃ *** ┃ *** **** ┃ *** ┃ \n");
printf(" \t ┃ *** ┃ *** **** ┃ *** ┃ \n");
printf(" \t ┃ *** ┃ *** Producer: XXY **** ┃ *** ┃ \n");
printf(" \t ┃ *** ┃ *** **** ┃ *** ┃ \n");
printf(" \t ┃ *** ┃ *** 2013.6.20 **** ┃ *** ┃ \n");
printf(" \t ┃ *** ┃ *** **** ┃ *** ┃ \n");
printf(" \t ┃ *** ┃ ************************************************ ┃ *** ┃ \n");
printf(" \t ┃ *** ┗ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ┛ *** ┃ \n");
printf(" \t ┃ ********************************************************** ┃ \n");
printf(" \t ┗ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ┛ \n");
puts(" \n\t 1. Administrator login ! \n");
puts(" \n\t 2. tourists landing ! \n");
printf("\n Please select login ( 1 or 2 ) :[ ]\b\b"); / / Shift to the left 1 " \b "
}
//***************************** The main function ****************************************
int main()
{
int i,k=0;
char username[15],pwd[7],c;
system("color 5e");// color
Welcome();
c=getchar();getchar();
if (c=='1')
{
system("cls");// Jump to the page.
puts("\n\n\n\n\n\n\n\t\t\t\t tube Richard member deng Lu! \n\n\n\n\n\t\t\t\t please deng lu !");
getchar();
for(i=0;i<3;i++)
{
printf("\n Please enter a user name :");
gets(username);
printf("\n Please enter the 6 A password :");
gets(pwd);
// Judge conditions
if((strcmp(username,"xiaxianyun")==0)&&(strcmp(pwd,"123456")==0))
{
printf("\n You have logged in successfully \n");
k=1;
for(i=0;i<20;i++)
{
printf(".");
Sleep(100);
}
system("cls");
while(1)
switch(menu())
{
case '1':Enter();break;
case '2':Browse();break;
case '3':Query();break;
case '4':Recopose();break;
case '5':Delete();break;
case '6':Exit();break;
}
break;
}
else
printf("\n Invalid username or password Please re-enter :\n");
continue;
}
if(k==0)
printf("\n Continuous input error 3 time Will exit the program \n");
Sleep(2000);
exit(1);
}
else if(c=='2')// Visitors to login
{
system("cls");// Jump to the page.
puts("\n\n\n\n\n\n\n\t\t\t\t huan To meet swim The guest Into the Into the! \n\n\n\n\n\t\t\t\t please indeed set !");
getchar();
system("cls");
while(1)
switch(menu())
{
case '1':Enter();break;
case '2':Browse();break;
case '3':Query();break;
case '4':system("cls");getchar();
puts("\n\n\t\t Sorry you don't have permission to modify! \n\n");
printf("\t\tpress any key to continue!");getchar();system("cls");break;
case '5':system("cls");getchar();
puts("\n\n\t\t Sorry you do not have permission to delete! \n\n");
printf("\t\tpress any key to continue!");getchar();system("cls");break;
case '6':Exit();break;
}
}
return 0;
}