| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1942 人关注过本帖
标题:哪位大神可以帮我改改!
取消只看楼主 加入收藏
忱罅斯潋旎
Rank: 2
等 级:论坛游民
帖 子:35
专家分:10
注 册:2012-6-3
收藏
得分:0 
回复 21楼 demonleer
呵呵……

做一个温暖的女子,不倾城,不倾国,只倾其所有过我想过的生活
2012-06-18 12:30
忱罅斯潋旎
Rank: 2
等 级:论坛游民
帖 子:35
专家分:10
注 册:2012-6-3
收藏
得分:0 
回复 22楼 user_qiangzi
呵呵……

做一个温暖的女子,不倾城,不倾国,只倾其所有过我想过的生活
2012-06-18 12:30
忱罅斯潋旎
Rank: 2
等 级:论坛游民
帖 子:35
专家分:10
注 册:2012-6-3
收藏
得分:0 
回复 25楼 hellovfp
这是我改过之后的只是还是不能执行文件保存,还有就是录入之后不管怎么选择始终都是跳回主菜单





#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <process.h>
#define n 100
 struct  student                         //定义学生结构体类型
 {
    int num;
    char name;
    char sex;
    char adress;
    int  phonenum;
    int chinese;
    int mathematic;
    int english;
    float aver;
    float mategrade;
    float pindegrade;
    float teachergrade;
    double totalgrade;
}stu[100];



void save()                                      /*建立保存文件函数*/
{   

        FILE *fp;                                 /*定义文件型指针*/
        int i;
        char filename;
 printf("请输入要保存的文件名!\n");
    scanf("%s",filename);
        if((fp=fopen("filename","w"))==NULL)   /*打开输出文件*/
        {
            printf("不能打开文件!\n");   
            return;                              /*终止程序*/
        }
        for(i=0;i<n;i++)                         /*向student文件中写入信息*/
            if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
                printf("文件写入错误\n");
                   fclose(fp);                              /*关闭文件*/
        printf("\n\n\n\n\t\t\t学生信息保存成功!\n");
   



}
 





int input()                                            /*定义录入学生信息函数*/
{


          char Y,N;

        int i,a,m;                                          /*定义局部变量*/
        printf("\t\t输出你想输入的学生信息个数:");
        scanf("%d",&a);
        for(i=0;i<a;i++)                               /*输入每个学生的信息*/
        {
            
            printf("温馨提示:学号姓名性别地址是字符型,联系方式和各类成绩为整型!");
            printf("\n\t\t\t----------------\n");
            printf("\t\t\t学号:");
            scanf("%s",&stu[i].num);                   /*输入学号*/
            printf("\t\t\t姓名:");
            scanf("%s",&stu[i].name);                     /*输入姓名*/
            printf("\t\t\t性别:");
            scanf("%S",&stu[i].sex);                       /*输入性别*/
            printf("\t\t\t地址:");
            scanf("%s",&stu[i].adress);                     /*输入地址*/
            printf("\t\t\t联系方式:");
            scanf("%d",&stu[i].phonenum);                   /*输入联系方式*/
            printf("\t\t\t英语:");
            scanf("%d",&stu[i].english);                     /*输入英语成绩*/
            printf("\t\t\t数学:");
            scanf("%d",&stu[i].mathematic);                   /*输入数学成绩*/
            printf("\t\t\t语文:");
            scanf("%d",&stu[i].chinese);                    /*输入语文成绩*/
             printf("\t\t\t同学互评分:");
            scanf("%d",&stu[i].mategrade);                   /*输入同学互评分成绩*/
             printf("\t\t\t品德分:");
            scanf("%d",&stu[i].pindegrade);                /*输入品德分成绩*/
             printf("\t\t\t教师评分:");
            scanf("%d",&stu[i].teachergrade);               /*输入教师评分成绩*/

stu[i].aver=((float)stu[i].english+(float)stu[i].mathematic+(float)stu[i].chinese)/3;          /*计算平均成绩*/
stu[i].totalgrade=(float)stu[i].aver*0.6+(float)stu[i].mategrade*0.1+(float)stu[i].pindegrade*0.1+(float)stu[i].teachergrade*0.2;    /*计算综合测评成绩*/
            printf("\t\t\t平均成绩=%4.1f\n",stu[i].aver);               /*输出平均成绩*/
            printf("\t\t\t总成绩=%4.1f\n",stu[i].totalgrade);        /*输出总成绩*/
save();    }

    printf("是否继续录入,继续选Y,退出选N\n");
scanf("%s",&m);
if(m==Y)  input();
if(m==N)  exit(0);

return 0;

}









void show()                                                   /*定义查看函数*/
{   
        
        int a,i;
         FILE*fp;
         if((fp=fopen("filename","w"))==NULL)       /*打开输入文件*/
         {printf("不能打开文件!\n");
         exit(0);
         }
        printf("\t学号\t姓名\t性别\t地址\t电话号码\t英语\t数学\t语文\t品德分\t同学互评分\t教师评分\t平均成绩\t总成绩\n");
        for(i=0;i<n;i++)                                          /*输出所有的学生信息*/
        {
            printf("%10s\t%s\t%2s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%3.1f\t\t%6.1f\n",stu[i].num,stu[i].name,
            stu[i].sex,stu[i].adress,stu[i].phonenum,stu[i].english,stu[i].mathematic,stu[i].chinese,stu[i].pindegrade,stu[i].mategrade,stu[i].teachergrade,stu[i].aver,stu[i].totalgrade);
        }
        fclose(fp);                         /*关闭文件*/
        printf("\n\n\n\t\t\t按任意键返回菜单");
        { scanf("%s",&a); return;}
   
   
}






void numquary()                                        //定义学号查询函数
{   
    int i,a,b,m;
    printf("*********************************学号查询***************************************\n");
    printf("请输入要查询的学号:\n");
    scanf("%d",&m);
printf("学号\t姓名\t性别\t地址\t电话号码\t语文\t英语\t数学\t测试平均分\t同学互评分\t教师评分\t综合评分\n");
    for(i=0;i<n;i++)
    if(m==stu[i].num)   
printf("%4d\t%s\t%s\t%s\t%6.2f\t%6.2f\t%6.2f\t%6.2f\t%6.2f\t%6d\t%s\n",
stu[i].num,stu[i].name,stu[i].sex,stu[i].adress,stu[i].chinese,stu[i].english,stu[i].mathematic,stu[i].aver,stu[i].mategrade,stu[i].teachergrade,stu[i].totalgrade);
    for(i=0;i<5;i++)
        if(m==stu[i].num)
        { printf("\n\n\n\n\n\n");
          printf("\t\t\t1.继续查询\n");
          printf("\t\t\t2.返回上一级菜单\n");
          printf("\t\t\t0.退出系统\n");
          printf("请选择下一步操作:(0-2)\n");
    scanf("%d",&a);
    if(a==0) exit(0);
    if(a==1) numquary();
    if(a==2) return;
        }
    printf("该学号不存在!\n");
         printf("\n\n\n\n\n\n");
          printf("\t\t\t1.继续查询\n");
         printf("\t\t\t2.返回子菜单\n");
          printf("\t\t\t0.退出系统\n");
          printf("请选择下一步操作:(0-2)\n");
    scanf("%d",&b);
    if(b==0) exit(0);
    if(b==1) numquary();
    if(b==2) return;

}







void namequary()                                    //定义按姓名查询的函数
{
    int i,a,b,m;
  
    printf("*********************************姓名查询***************************************\n");
    printf("请输入要查询的姓名:\n");
    scanf("%s",&m);
printf("学号\t姓名\t性别\t地址\t电话号码\t语文\t英语\t数学\t测试平均分\t同学互评分\t教师评分\t综合评分\n");
    for(i=0;i<n;i++)
    if(m==stu[i].name)
   
printf("%4d\t%s\t%s\t%s\t%6.2f\t%6.2f\t%6.2f\t%6.2f\t%6.2f\t%6d\t%s\n",
stu[i].num,stu[i].name,stu[i].sex,stu[i].adress,stu[i].chinese,stu[i].english,stu[i].mathematic,stu[i].aver,stu[i].mategrade,stu[i].teachergrade,stu[i].totalgrade);
    for(i=0;i<n;i++)
        if(m==stu[i].name)
        { printf("\n\n\n\n\n\n");
          printf("\t\t\t1.继续查询\n");
          printf("\t\t\t2.返回子菜单\n");
          printf("\t\t\t0.退出系统\n");
          printf("请选择下一步操作:(0-2)\n");
    scanf("%d",&a);
    if(a==0) exit(0);
    if(a==1) namequary();
    if(a==2) return;
}
    printf("该学号不存在!\n");
         printf("\n\n\n\n\n\n");
          printf("\t\t\t1.继续查询\n");
          printf("\t\t\t2.返回子菜单\n");
          printf("\t\t\t0.退出系统\n");
          printf("请选择下一步操作:(0-2)\n");
    scanf("%d",&b);
    if(b==0) exit(0);
    if(b==1) namequary();
    if(b==2) return;
}








int chaxun()
{
 
    int i,j;

    do
            {printf("\n\n\n");
            printf("              |*************编辑子菜单****************|\n");
            printf("              |.......................................|\n");
            printf("              |.........请选择菜单序号(0-2)...........|\n");
            printf("              |         1.按学号查询                  |\n");
             printf("              |         2.按姓名查询                  |\n");
            printf("              |         0.返回上级菜单                |\n");
            scanf("%d",&i);
            switch(i)
            {case 0:return(n);break;
            case 1:numquary();break;
            case 2:namequary();break;
            default:printf("输入错误,请重新输入(只有5次机会!)");break;}
            }while(j!=5);
return 0;}







int Delete_record()
{
    int s;
int i,j;
printf("\t\t\t请输入所要删除数据的学号:");      /*交互式问寻*/
scanf("%s",&s);
for(i=0;i<n;i++)                               //
if(s!=stu[i].num)
{printf("未找到数据,返回主界面!\n");
return(n);}
   else for(j=i;j<n-1;j++)                  /*删除操作*/
     stu[j]=stu[j+1];
      printf("\t\t\t删除结束!\n");          /*返回成功信息*/
      return(n-1);
}








int add()          //定义添加函数
{      
      
    int i;
  char s;
printf("\t\t\t请输入所要添加的学号:\n");
scanf("%s",&s);

for(i=0;i<n;i++)
if(s==stu[i].num)   //查找判断
{printf("该学生已存在,请重新输入!");
return(n);
}
else input();
 return(n-1);
}






int modify()       //定义修改函数
{
int i;
char s;
printf("请输入要修改的学号\n");
scanf("%s",&s);
for(i=0;i<n;i++)
if(s==stu[i].num)                  //查找判断
{printf("%4d\t%s\t%s\t%s\t%6.2f\t%6.2f\t%6.2f\t%6.2f\t%6.2f\t%6d\t%s\n",
stu[i].num,stu[i].name,stu[i].sex,stu[i].adress,stu[i].chinese,stu[i].english,stu[i].mathematic,stu[i].aver,stu[i].mategrade,stu[i].teachergrade,stu[i].totalgrade);
printf("请输入语文成绩:\n");
scanf("%s",stu[i].chinese);
printf("请输入英语成绩:\n");
scanf("%s",stu[i].english);
printf("请输入数学成绩:\n");
scanf("%s",stu[i].mathematic);
 printf("请输入品德成绩:\n");
scanf("%s",stu[i].pindegrade);
printf("请输入同学互评分成绩:\n");
scanf("%s",stu[i].mategrade);
 printf("请输入教师评分成绩:\n");
scanf("%s",stu[i].teachergrade);
}
else{ printf("未找到数据,返回子菜单!");
return 0;}
return(n-1);}










int update()                      //定义更新函数
{
    int i,j;
    do
    {
      printf("\n\n\n");
            printf("              |*************编辑子菜单****************|\n");
            printf("              |.......................................|\n");
            printf("              |.........请选择菜单序号(0-2)...........|\n");
            printf("              |         1.添加学生信息                |\n");
             printf("              |         2.修改学生信息                |\n");
            printf("              |         0.返回上级菜单                |\n");
            scanf("%d",&i);
            switch(i)
            {case 0:return(n);break;
            case 1:add();break;
            case 2:modify();break;
            default:printf("输入错误,请重新输入(只有5次机会!)");break;}
            }while(j<5);
return 0;}

   






int main()
{
    int x,y;
    do                                           //显示一个简易菜单
    {
    printf("          |*****************************************************|\n");
    printf("          |                    学生测评系统                     |\n");
    printf("          |*****************************************************|\n");
    printf("          |                    1.录入学生信息                   |\n");
    printf("          |                    2.浏览学生信息                   |\n");
    printf("          |                    3.查询学生信息                   |\n");
    printf("          |                    4.更新学生信息                   |\n");
    printf("          |                    5.删除学生信息                   |\n");
    printf("          |                    6.保存                           |\n");
    printf("          |                    7.退出                           |\n");
    printf("          |*****************************************************|\n");
    printf(":请选择(1-7):\n");
    scanf("%d",&x);                             //接受用户的选择
   
        switch(x)                               //调用对应的函数
        {    case 1:input();break;
            case 2:show();break;
            case 3:chaxun();break;                     
            case 4:update();break;
            case 5:Delete_record();break;
            case 6: save();break;
            case 7:break;
            default:{printf("选择错误,请重新输入(只有5次机会!)\n");}break;}
    }while(y<5);

return 0;
}
            

做一个温暖的女子,不倾城,不倾国,只倾其所有过我想过的生活
2012-06-18 13:23
忱罅斯潋旎
Rank: 2
等 级:论坛游民
帖 子:35
专家分:10
注 册:2012-6-3
收藏
得分:0 
回复 28楼 hellovfp
为什么我的电脑编译的时候没有提示有警告啊?

做一个温暖的女子,不倾城,不倾国,只倾其所有过我想过的生活
2012-06-18 14:06
快速回复:哪位大神可以帮我改改!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033862 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved