| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 542 人关注过本帖
标题:江湖救急2.0
取消只看楼主 加入收藏
spike351
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-10-16
收藏
 问题点数:0 回复次数:0 
江湖救急2.0
#include<stdio.h>
#include<string.h>
#include<stdlib.h>





struct student//定义学生资料结构体
{
    int num; //学号
    char name[20]; //姓名
    float score[3]; //3门成绩
    float ave;  //平均成绩
};




void menu(); //显示主菜单
void menu()
{
    printf("\n\n\t ===================================================\n\n");
     printf("\t\t\t\t学员成绩管理\n\n");
     printf("\t\t1.输入学生信息");
     printf("\t\t2.显示学生信息\n\n");
     printf("\t\t3.排序\t");
     printf("\t\t4.查询学生(按学号)\n\n");
     printf("\t\t5.插入学生信息");
     printf("\t\t6.删除学生信息\n\n");
     printf("\t\t0.退出\n\n");
     printf("\t ====================================================\n\n");
}






struct student input(); //输入函数
struct student input() //输入函数
{
   int i;
   double sum=0;
   struct student temp;
printf("\n请输入学号: ");
scanf("%d",&temp.num);
printf("\n请输入姓名: ");
fflush(stdin);
gets(temp.name);
printf("\n请输入数学成绩: ");
scanf("%lf",&temp.score[0]);
printf("\n请输入语文成绩: ");
scanf("%lf",&temp.score[1]);
printf("\n请输入英语成绩: ");
scanf("%lf",&temp.score[2]);
for(i=0;i<3;i++)
{
sum+=temp.score[i];
}
temp.ave=sum/3;
return temp;
}




void display(struct student s[],int total);//显示函数
void display(struct student s[],int total)
{
    system("cls");
    int i;
    printf("\t学号\t姓名\t语文\t数学\t英语\t平均\n\n");
    for(i=0;i<total;i++)
    {
     printf("\t%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n\n",s[i].num,s[i].name,s[i].score[0],s[i].score[1],s[i].score[2],s[i].ave);
    }
}





void sort(struct student s[],int total); //冒泡排序
void sort(struct student s[],int total)
{
int i,j;
struct student temp;
for(i=0;i<total-1;i++)
{
for(j=0;j<total-1-i;j++)
{
if(s[j].ave<s[j+1].ave)
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
}
}




void searchNum(struct student s[],int total);//查询
void searchNum(struct student s[],int total)  
{
int num,i;
printf("\n\t请输入要查询的学号:\n\n\t");
scanf("%d",&num);
printf("\n");
for(i=0;i<total;i++)
{
if(num==s[i].num)
break;
}
if(i<total)
{
printf("\t学号\t姓名\t语文\t数学\t英语\t平均\n\n");
printf("\t%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n\n\t",s[i].num,s[i].name,s[i].score[0],s[i].score[1],s[i].score[2],s[i].ave);
}
else
printf("\t该学号不存在\n\n\t");
}




void insert(struct student s[],int total);
void insert(struct student s[],int total) //插入学生(自动排序)
{
struct student temp;
int i,k;
temp=input();
for(i=0;i<total;i++)
{
if(temp.ave>s[i].ave)
break;
}
k=i;
for(i=total;i>k;i--)
{
s[i]=s[i-1];
}
s[k]=temp;
}





int del(struct student s[],int total); //删除学生
int del(struct student s[],int total) //删除
{
int temp,i,j;
printf("\t请输入要删除的学号: ");
scanf("%d",&temp);
for(i=0;i<total;i++)
{
if(temp==s[i].num)
break;
}
if(i<total)
{
for(j=i;j<total;j++)
{
s[j]=s[j+1];
}
return 1;
}
else
{
return 0;
}
}














void main()
{   
    struct student stu[50];
    int number; //主菜单数字选择健
    int total=0; //total为学生总数
    char ch;
    do
    {
     system("cls"); //清除
     menu();
     scanf("%d",&number); //输入主菜单上的数字
     switch (number)
     {
      case 0:system("cls");
             printf("谢谢你已查寻完毕!下次再见!\n");break;
      case 1:do
             {
              system("cls");
              stu[total]=input();
              total++; //人数+1
              printf("\n是否继续Y/n: ");
              fflush(stdin);
              ch=getchar();
              }while(ch=='Y'||ch=='y');
              printf("\n");
              break;
      case 2:system("cls");
             display(stu,total);//显示
             printf("\n"); break;
      case 3:system("cls");
             sort(stu,total);
             display(stu,total);
             break;
      case 4:searchNum(stu,total);
             break;
      case 5:
          do
        {
            system("cls");
            display(stu,total); //显示
            insert(stu,total); //插入
            total++; //人数+1
            system("cls");
            display(stu,total); //显示
            printf("\n是否继续插入学员Y/y: ");
            fflush(stdin);
            ch=getchar();
            printf("\n");
        }while(ch=='Y'||ch=='y');
            break;
      case 6:do
             {
                system("cls");
                display(stu,total); //显示
                if(del(stu,total)) //删除
                {
                    total--; //人数-1
                    system("cls");
                    display(stu,total); //显示
                }
                else
                {
                    printf("\n\t该学号不存在\n\n\t");
                    system("pause");
                    system("cls");
                    display(stu,total);
                }
                    printf("\n是否继续删除学员Y/y: ");
                    fflush(stdin);
                    ch=getchar();
                printf("\n");
            }while(ch=='Y'||ch=='y');
            break;

    }while(number!=0);
    


}
这是全部的程序,请各位看看那错了,谢谢了,十分的感谢!!!
搜索更多相关主题的帖子: 江湖 
2007-12-24 20:39
快速回复:江湖救急2.0
数据加载中...
 
   



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

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