c语言输入错误要求重新输入密码,C语言写的学生管理系统 求大佬帮改错 顺便加一个输入密码的功能 急急急!!!...

本帖最后由 阳光丶 于 2018-9-28 21:04 编辑

#include

#include

#include

#include

#include

#define LEN sizeof(struct student)

#define FORMAT "%-8d%-15s%-12.1lf%-12.1lf%-12.1lf%-12.1lf\n"

#define DATA stu.num,stu.name,stu.elec,stu.expe,stu.requ,stu.sum

float Felec,Fexpe,Frequ;

struct student/*定义学生成绩结构体*/

{

int num;/*学号*/

char name[15];/*姓名*/

double elec;/*选修课*/

double expe;/*实验课*/

double requ;/*必修课*/

double sum;/*总分*/

};

struct student stu[50];/*定义结构体数组*/

void in();/*录入学生成绩信息*/

void show();/*显示学生信息*/

void order();/*按总分排序*/

void del();/*删除学生成绩信息*/

void modify();/*修改学生成绩信息*/

void menu();/*主菜单*/

void insert();/*插入学生信息*/

void total();/*计算总人数*/

void search();/*查找学生信息*/

int main()/*主函数*/

{

int n;

menu();

scanf("%d",&n);/*输入选择功能的编号*/

while(n)

{

switch(n)

{

case 1:

in();

break;

case 2:

search();

break;

case 3:

del();

break;

case 4:

modify();

break;

case 5:

insert();

break;

case 6:

order();

break;

case 7:

total();

break;

default:break;

}

getch();

menu();/*执行完功能再次显示菜单界面*/

scanf("%d",&n);

}

}

void in()/*录入学生信息*/

{

int i,m=0;/*m是记录的条数*/

char ch[2];

FILE *fp;/*定义文件指针*/

if((fp=fopen("data","ab+"))==NULL)/*打开指定文件*/

{

printf("can not open\n");

return;

}

while(!feof(fp))

{

if(fread(&stu[m] ,LEN,1,fp)==1)

m++;/*统计当前记录条数*/

}

fclose(fp);

if(m==0)

printf("No record!\n");

else

{

system("cls");

show();/*调用show函数,显示原有信息*/

}

if((fp=fopen("data","wb"))==NULL)

{

printf("can not open\n");

return;

}

for(i=0;i

fwrite(&stu ,LEN,1,fp);/*向指定的磁盘文件写入信息*/

printf("please input(y/n):");

scanf("%s",ch);

if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)

{

printf("please input per centum:");

printf("\nelective:");

scanf("%f",&Felec);

printf("\nexperiment:");

scanf("%f",&Fexpe);

printf("\nrequired course:");

scanf("%f",&Frequ);

}

while(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判断是否要录入新信息*/

{

printf("number:");

scanf("%d",&stu[m].num);/*输入学生学号*/

for(i=0;i

if(stu.num==stu[m].num)

{

printf("the number is existing,press any to continue!");

getch();

fclose(fp);

return;

}

printf("name:");

scanf("%s",stu[m].name);/*输入学生姓名*/

printf("elective:");

scanf("%lf",&stu[m].elec);/*输入选修课成绩*/

printf("experiment:");

scanf("%lf",&stu[m].expe);/*输入实验课成绩*/

printf("required course:");

scanf("%lf",&stu[m].requ);/*输入必修课成绩*/

stu[m].sum=stu[m].elec*Felec+stu[m].expe*Fexpe+stu[m].requ*Frequ;/*计算出总成绩*/

if(fwrite(&stu[m],LEN,1,fp)!=1)/*将新录入的信息写入指定的磁盘文件*/

{

printf("can not save!");

getch();

}

else

{

printf("%s saved!\n",stu[m].name);

m++;

}

printf("continue?(y/n):");/*询问是否继续*/

scanf("%s",ch);

}

fclose(fp);

printf("OK!\n");

}

void show()

{

FILE *fp;

int i,m=0;

fp=fopen("data","ab+");

while(!feof(fp))

{

if(fread(&stu[m] ,LEN,1,fp)==1)

m++;

}

fclose(fp);

printf("number  name           elective    experiment  required    sum\t\n");

for(i=0;i

{

printf(FORMAT,DATA);/*将信息按指定格式打印*/

}

}

void menu()/*自定义函数实现菜单功能*/

{

system("cls");

printf("\n\n\n\n\n");

printf("\t\t|---------------------STUDENT-------------------|\n");

printf("\t\t|\t 0. exit                                |\n");

printf("\t\t|\t 1. input record                        |\n");

printf("\t\t|\t 2. search record                       |\n");

printf("\t\t|\t 3. delete record                       |\n");

printf("\t\t|\t 4. modify record                       |\n");

printf("\t\t|\t 5. insert record                       |\n");

printf("\t\t|\t 6. order                               |\n");

printf("\t\t|\t 7. number                              |\n");

printf("\t\t|---------------------|\n\n");

printf("\t\t\tchoose(0-7):");

}

void order()/*自定义排序函数*/

{

FILE *fp;

struct student t;

int i=0,j=0,m=0;

if((fp=fopen("data","ab+"))==NULL)

{

printf("can not open!\n");

return;

}

while(!feof(fp))

if(fread(&stu[m] ,LEN,1,fp)==1)

m++;

fclose(fp);

if(m==0)

{

printf("no record!\n");

return;

}

for(i=0;i

for(j=i+1;j

if(stu.sum

{

t=stu;

stu=stu[j];

stu[j]=t;

}

if((fp=fopen("data","wb"))==NULL)

{

printf("can not open\n");

return;

}

for(i=0;i

if(fwrite(&stu ,LEN,1,fp)!=1)

{

printf("%s can not save!\n");

getch();

}

fclose(fp);

printf("save successfully\n");

}

void del()/*自定义删除函数*/

{

FILE *fp;

int snum,i,j,m=0;

char ch[2];

if((fp=fopen("data","ab+"))==NULL)

{

printf("can not open\n");

return;

}

while(!feof(fp))

if(fread(&stu[m],LEN,1,fp)==1)

m++;

fclose(fp);

if(m==0)

{

printf("no record!\n");

return;

}

printf("please input the number:");

scanf("%d",&snum);

for(i=0;i

if(snum==stu.num)

break;

if(i==m)

{

printf("can not find");

getchar();

return;

}

printf("find the student,delete?(y/n)");

scanf("%s",ch);

if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判断是否要进行删除*/

{

for(j=i;j

stu[j]=stu[j+1];/*将后一个记录移到前一个记录的位置*/

m--;/*记录的总个数减1*/

printf("delete successfully!\n");

}

if((fp=fopen("data","wb"))==NULL)

{

printf("can not open\n");

return;

}

for(j=0;j

if(fwrite(&stu[j] ,LEN,1,fp)!=1)

{

printf("can not save!\n");

getch();

}

fclose(fp);

}

void search()/*自定义查找函数*/

{

FILE *fp;

int snum,i,m=0;

char ch[2];

if((fp=fopen("data","ab+"))==NULL)

{

printf("can not open\n");

return;

}

while(!feof(fp))

if(fread(&stu[m],LEN,1,fp)==1)

m++;

fclose(fp);

if(m==0)

{

printf("no record!\n");

return;

}

printf("please input the number:");

scanf("%d",&snum);

for(i=0;i

if(snum==stu.num)/*查找输入的学号是否在记录中*/

{

printf("find the student,show?(y/n)");

scanf("%s",ch);

if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)

{

printf("number  name           elective    experiment  required    sum\t\n");

printf(FORMAT,DATA);/*将查找出的结果按指定格式输出*/

break;

}

else

return;

}

if(i==m)

printf("can not find the student!\n");/*未找到要查找的信息*/

}

void modify()/*自定义修改函数*/

{

FILE *fp;

int i,j,m=0,snum;

if((fp=fopen("data","ab+"))==NULL)

{

printf("can not open\n");

return;

}

while(!feof(fp))

if(fread(&stu[m],LEN,1,fp)==1)

m++;

if(m==0)

{

printf("no record!\n");

fclose(fp);

return;

}

printf("please input the number of the student which do you want to modify!\n");

scanf("%d",&snum);

for(i=0;i

if(snum==stu.num)/*检索记录中是否有要修改的信息*/

break;

if(i

{

printf("find the student!you can modify!\n");

printf("please input per centum:");

printf("\nelective:");

scanf("%f",&Felec);

printf("\nexperiment:");

scanf("%f",&Fexpe);

printf("\nrequired course:");

scanf("%f",&Frequ);

printf("name:\n");

scanf("%s",stu.name);/*输入名字*/

printf("\nelective:");

scanf("%lf",&stu.elec);/*输入选修课成绩*/

printf("\nexperiment:");

scanf("%lf",&stu.expe);/*输入实验课成绩*/

printf("\nrequired course:");

scanf("%lf",&stu.requ);/*输入必修课成绩*/

stu.sum=stu.elec*Felec+stu.expe*Fexpe+stu.requ*Frequ;

}

else

{

printf("can not find!");

getchar();

return;

}

if((fp=fopen("data","wb"))==NULL)

{

printf("can not open\n");

return;

}

for(j=0;j

if(fwrite(&stu[j] ,LEN,1,fp)!=1)

{

printf("can not save!");

getch();

}

fclose(fp);

}

void insert()/*自定义插入函数*/

{

FILE *fp;

int i,j,k,m=0,snum;

if((fp=fopen("data","ab+"))==NULL)

{

printf("can not open\n");

return;

}

while(!feof(fp))

if(fread(&stu[m],LEN,1,fp)==1)

m++;

if(m==0)

{

printf("no record!\n");

fclose(fp);

return;

}

printf("please input position where do you want to insert!(input the number)\n");

scanf("%d",&snum);/*输入要插入的位置*/

for(i=0;i

if(snum==stu.num)

break;

for(j=m-1;j>i;j--)

stu[j+1]=stu[j];/*从最后一条记录开始均向后移一位*/

printf("now please input the new information.\n");

printf("number:");

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

for(k=0;k

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

{

printf("the number is existing,press any to continue!");

getch();

fclose(fp);

return;

}

printf("please input per centum:");

printf("\nelective:");

scanf("%f",&Felec);

printf("\nexperiment:");

scanf("%f",&Fexpe);

printf("\nrequired course:");

scanf("%f",&Frequ);

printf("name:\n");

scanf("%s",stu[i+1].name);

printf("\nelective:");

scanf("%lf",&stu[i+1].elec);

printf("\nexperiment:");

scanf("%lf",&stu[i+1].expe);

printf("\nrequired course:");

scanf("%lf",&stu[i+1].requ);

stu[i+1].sum=stu[i+1].elec*Felec+stu[i+1].expe*Fexpe+stu[i+1].requ*Frequ;

if((fp=fopen("data","wb"))==NULL)

{

printf("can not open\n");

return;

}

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

if(fwrite(&stu[k] ,LEN,1,fp)!=1)/*将修改后的记录写入磁盘文件中*/

{

printf("can not save!");

getch();

}

fclose(fp);

}

void total()

{

FILE *fp;

int m=0;

if((fp=fopen("data","ab+"))==NULL)

{

printf("can not open\n");

return;

}

while(!feof(fp))

if(fread(&stu[m],LEN,1,fp)==1)

m++;/*统计记录个数即学生个数*/

if(m==0)

{

printf("no record!\n");

fclose(fp);

return;

}

printf("the class are %d students!\n",m);/*将统计的个数输出*/

fclose(fp);

}

  • 0
    点赞
  • 0
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

// 999.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { int a,i,c,n; //定义年份,月份,日期,总天数,总天数除以的余数 int b1=31,b3=31,b5=31,b7=31,b8=31,b10=31,b12=31; int b4=30,b6=30,b9=30,b11=30,b2; //定义每月天数 printf("请输入年月日:\n"); scanf("%d,%d,%d",&a,&i,&c); //输入年份,月份,日期 if((a0!=0&&a%4==0)||(a%400==0)) b2=29; //闰年,二月有29天 else b2=28; //非闰年,二月有28天 if(a>0) { if(i>=1&&i<=12) { if(i==2) //若输入的为二月...(防止输入像2001/2/30这样的错误日期) { if (c<=b2) { n=b1+c; } else printf("输入的日期有误.\n"); } else { if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) //若输入的为31天的几个月...(防止输入像2001/3/33这样的错误日期) { if(c<=31) { switch(i) { case 1:n=c;break; case 3:n=b1+b2+c;break; case 5:n=b1+b2+b3+b4+c;break; case 7:n=b1+b2+b3+b4+b5+b6+c;break; case 8:n=b1+b2+b3+b4+b5+b6+b7+c;break; case 10:n=b1+b2+b3+b4+b5+b6+b7+b8+b9+c;break; case 12:n=b1+b2+b3+b4+b5+b6+b7+b8+b9+b10+b11+c;break; } } else printf("输入的日期有误.\n"); } else { if(i==9||i==4||i==6||i==11) //若输入的为30天的几个月...(防止输入像2001/4/31这样的错误日期) { if(c<=30) { switch(i) { case 4:n=b1+b2+b3+c;break; case 6:n=b1+b2+b3+b4+b5+c;break; case 9:n=b1+b2+b3+b4+b5+b6+b7+b8+c;break; case 11:n=b1+b2+b3+b4+b5+b6+b7+b8+b9+b10+c;break; } } } else printf("输入的日期有误.\n"); } }
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值