您现在的位置是: 首页 > 教育改革 教育改革

分数查询系统制作,分数查询的软件

tamoadmin 2024-05-18 人已围观

简介#include"stdio.h"#include<string.h>#include<stdlib.h>#define N 30struct student{ int num; char name[20]; int age; int Math; int English; int Physical; long int sum;}stu[N];enter(){int i,n;

分数查询系统制作,分数查询的软件

#include"stdio.h"

#include<string.h>

#include<stdlib.h>

#define N 30

struct student

{

int num;

char name[20];

int age;

int Math;

int English;

int Physical;

long int sum;

}stu[N];

enter()

{int i,n;

printf("How many students(1-%d)?:",N);

scanf("%d",&n);

printf("\nEnter data now\n\n");

for(i=0;i<n;i++)

{printf("\n Input %dth student record.\n",i+1);

input(i);

}

if(i!=0) save(n);

printf_back(); /* browse or back */

}

add()

{int i,n,m,k;

FILE *fp;

n=load();

printf("How many students are you want to add(1-%d)?:",N-n);

scanf("%d",&m);

k=m+n;

for(i=n;i<k;i++)

{printf("\n Input %dth student record.\n",i+1);

input(i);

}

if((fp=fopen("score.txt","ab"))==NULL)

{printf("Cannot open file.\n");

}

for(i=n;i<k;i++)

if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)

printf("file write error.\n");

fclose(fp);

printf_back();

}

/* insert()

{int n,c;

struct student s;

n=load();

puts("\n Input one data.\n");

do

{input(n);

printf_face();

printf_one(n);

printf("\n\nAre you sure?\n\n\t 1.Sure\t2.cancel and again\t3.Back without save [ ]\b\b");

scanf("%d",&c);

if(c==1)

{

save(n+1);

printf_back();

}

else if(c!=2) menu();

}

while(c==2);

} */

modify()

{struct student s;

FILE *fp;

int i,n,k,w0=1,w1,w2=0;

n=load();

do

{

k=-1;

printf_face();

for(i=0;i<n;i++)

{if((i!=0)&&(i%10==0))

{printf("\n\nRemember NO.031073- which needed modify.Pass any key to continue ...");

getch();

puts("\n\n");

}

printf_one(i);

printf("\n");

}

do

{printf("\n\nEnter NO.031073- that you want to modify! NO.:031073-");

scanf("%d",&s.num);

for(i=0;i<n;i++)

if(s.num==stu[i].num)

{k=i;

s=stu[i]; /* chengji beifei */

}

if(k==-1) printf("\n\nNO exist!please again");

}

while(k==-1);

printf_face();

printf_one(k);

w1=modify_data(k,n);

if(w1==1)

{printf("\nSuccessful ^_^.\n\nAre you modify another?\n\n\t1.Yes2.Back with save\t[ ]\b\b");

scanf("%d",&w0);

w2=1;

}

else

{w0=0; /* end */

if(w2==1)

stu[k]=s;

}

if(w0!=1&&w2==1) save(n); /* w0!=1 return w2==1 modify */

}

while(w0==1);

menu();

}

delete()

{struct student s;

FILE *fp;

int i,n,k,w0=1,w1,w2=0;

n=load();

do

{

k=-1;

printf_face();

for(i=0;i<n;i++)

{if((i!=0)&&(i%10==0))

{printf("\n\nRemember NO.031073- which needed delete.Pass any key to continue ...");

getch();

puts("\n\n");

}

printf_one(i);

printf("\n");

}

do

{printf("\n\nEnter NO.031073- that you want to delete! NO.:031073-");

scanf("%d",&s.num);

for(i=0;i<n;i++)

if(s.num==stu[i].num)

{k=i;

s=stu[i]; /* chengji beifei */

}

if(k==-1) printf("\n\nNO exist!please again");

}

while(k==-1);

printf_face();

printf_one(k);

printf("\nAre you sure?\n\n\t1.Sure2.Back without save in this time [ ]\b\b");

scanf("%d",&w1);

if(w1==1)

{

stu[k].sum=0;

printf("\nSuccessful ^_^.\n\nAre you delete another?\n\n\t1.Yes2.Back with save\t[ ]\b\b");

scanf("%d",&w0);

w2=1;

}

else

{w0=0; /* end */

if(w2==1)

stu[k]=s;

}

if(w0!=1&&w2==1) save(n);

}

while(w0==1);

menu();

}

modify_score()

{struct student s;

FILE *fp;

int i,n,k,w0=1,w1,w2=0;

n=load();

do

{

k=-1;

printf_face();

for(i=0;i<n;i++)

{if((i!=0)&&(i%10==0))

{printf("\n\nRemember NO.031073 which score needed modify.Pass any key to continue ...");

getch();

puts("\n\n");

}

printf_one(i);

printf("\n");

}

do

{printf("\n\nEnter NO.031073- that you want to modify! NO.:031073-");

scanf("%d",&s.num);

for(i=0;i<n;i++)

if(s.num==stu[i].num)

{k=i;

s=stu[i]; /* chengji beifei */

}

if(k==-1) printf("\n\nNO exist!please again");

}

while(k==-1);

printf_face();

printf_one(k);

w1=modify_score1(k);

if(w1==1)

{printf("\nSuccessful ^_^.\n\nAre you modify another score?\n\n\t1.Yes2.Back with save\t[ ]\b\b");

scanf("%d",&w0);

w2=1;

}

else

{w0=0; /* end */

if(w2==1)

stu[k]=s;

}

if(w0!=1&&w2==1) save(n); /* w0!=1 return w2==1 modify */

}

while(w0==1);

menu();

}

order()

{int i,j,k,n;

struct student s;

n=load();

for(i=0;i<n-1;i++)

{k=i;

for(j=i+1;j<n;j++)

if(stu[j].num<stu[k].num) k=j;

s=stu[i];stu[i]=stu[k];stu[k]=s;

}

save(n);

puts("\n\n");

printf_back();

}

browse()

{int i,j,n;

n=load();

printf_face();

for(i=0;i<n;i++)

{if((i!=0)&&(i%10==0))

{printf("\n\nPass any key to contiune ...");

getch();

puts("\n\n");

}

printf_one(i);

printf("\n");

}

printf("\tThere are %d record.\n",n);

printf("\nPass any key to back...");

getch();

menu();

}

save(int n)

{FILE *fp;

int i;

if((fp=fopen("score.txt","wb"))==NULL)

{printf("\nCannot open file\n");

return NULL;

}

for(i=0;i<n;i++)

if(stu[i].sum!=0)

if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)

printf("file write error\n");

fclose(fp);

}

load()

{FILE *fp;

int i;

if((fp=fopen("score.txt","rb"))==NULL)

{printf("\nCannot open file\n");

return NULL;

}

for(i=0;!feof(fp);i++)

fread(&stu[i],sizeof(struct student),1,fp);

fclose(fp);

return(i-1);

}

no_input(int i,int n)

{int k,w1;

do

{w1=0;

printf("NO.:031073-");

scanf("%d",&stu[i].num);

if(stu[i].num<1 || stu[i].num>N)

{puts("Input error! Only be made up of(1-N).Please reinput!\n");

w1=1;

}

if(w1!=1)

for(k=0;k<n;k++)

if(k!=i&&(stu[k].num==stu[i].num))

{puts("This record is exist. Please reinput!\n");

w1=1;break;

}

}

while(w1==1);

}

enter_score(int i)

{printf("Math English Physical");

scanf("%d %d %d",&stu[i].Math,&stu[i].English,&stu[i].Physical);

}

sum(int i)

{

stu[i].sum=stu[i].Math+stu[i].English+stu[i].Physical;

}

input(int i)

{no_input(i,i);

printf("name: age:");

scanf("%s %d",stu[i].name,&stu[i].age);

enter_score(i);

sum(i);

}

modify_score1(int i)

{int c,w1;

do

{

puts("\nmodify by=>\n\n 1.Math 2.English 3.Physical4.all score 5.cancel and back");

printf("Which you needed?:[ ]\b\b");

scanf("%d",&c);

if(c>5||c<1)

{puts("\nChoice error! Please again!");

getchar();

}

}

while(c>5||c<1);

do

{switch(c)

{

case 1:printf("Math:");scanf("%d",&stu[i].Math);break;

case 2:printf("English:");scanf("%d",&stu[i].English);break;

case 3:printf("Physical:");scanf("%d",&stu[i].Physical);break;

case 4:enter_score(i);break;

case 5:break;

}

if(c>0&&c<5) sum(i);

puts("\nNow:\n");

printf_face();

printf_one(i);

printf("\nAre you sure?\n\n\t1.Sure 2.No and remodify3.Back without save in this time [ ]\b\b");

scanf("%d",&w1);

}

while(w1==2);

return(w1);

}

modify_data(int i,int n)

{int c,w1;

do

{

puts("\nmodify by=>\n\n 1.NO. 2.name 3.age 4.Math 5.English 6.Physical7.all score 8.all data 9.cancel and back");

printf("Which you needed?:[ ]\b\b");

scanf("%d",&c);

if(c>9||c<1)

{puts("\nChoice error! Please again!");

getchar();

}

}

while(c>9||c<1);

do

{switch(c)

{case 1:no_input(i,n);break;

case 2:printf("name:");scanf("%s",stu[i].name);break;

case 3:printf("age:");scanf("%d",&stu[i].age);break;

case 4:printf("Math:");scanf("%d",&stu[i].Math);break;

case 5:printf("English:");scanf("%d",&stu[i].English);break;

case 6:printf("Physical:");scanf("%d",&stu[i].Physical);break;

case 7:enter_score(i);break;

case 8:input(i);break;

case 9:break;

}

if(c>3&&c<8) sum(i);

puts("\nNow:\n");

printf_face();

printf_one(i);

printf("\nAre you sure?\n\n\t1.Sure 2.No and remodify3.Back without save in this time [ ]\b\b");

scanf("%d",&w1);

}

while(w1==2);

return(w1);

}

printf_face()

{printf("\nNO.031073 name age Math English Physical sum\n");

}

printf_one(int i)

{

printf("%6d %8s %4d",stu[i].num,stu[i].name,stu[i].age);

printf("%5d %5d %8d %10d",stu[i].Math,stu[i].English,stu[i].Physical,stu[i].sum);

}

printf_back()

{int k,w;

printf("\n\n\tSuccessful.^_^\n\n");

printf("What do you want to do?\n\n\t1.Browse all now\t2.Back:[ ]\b\b");

scanf("%d",&w);

if(w==1) browse();

else menu();

}

menu()

{int w1;

char n;

do

{

puts("\t\t****************MENU****************\n\n");

puts("\t\t\t\tA.Enter new data");

puts("\t\t\t\tB.Addition data");

puts("\t\t\t\tC.Modify data");

puts("\t\t\t\tD.Delete data");

puts("\t\t\t\tE.Modify score");

puts("\t\t\t\tF.Order by number");

puts("\t\t\t\tG.Browse all");

puts("\t\t\t\tH.Exit");

puts("\n\n\t\t************************************\n");

printf("Choice your number(A-H):[ ]\b\b");

n=getchar();

printf("\n");

if(n<'A'||n>'H')

w1=1;

else w1=0;

}

while(w1==1);

switch(n)

{case 'A':enter();break;

case 'B':add();break;

case 'C':modify();break;

case 'D':delete();break;

case 'E':modify_score();break;

case 'F':order();break;

case 'G':browse();break;

case 'H':exit(0);

}

}

char password[7]="123456";

main()

{

char s[7];

printf("\t\t请输入密码:\n\t\t\n\t\t");

scanf("%s",s);

if(!strcmp(s,password))

{

printf("\n\t\t恭喜你进入学生成绩管理系统\n");

menu();

}

else

{

printf("\t\t 密码错误\n\n");

main();

}

}

文章标签: # printf # stu # amp