| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1202 人关注过本帖
标题:求大神帮助修改和完善这个程序
只看楼主 加入收藏
划船不用浆
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-9-7
收藏
 问题点数:0 回复次数:0 
求大神帮助修改和完善这个程序
这个程序有些问题,C++学得不好,希望大神可以帮我完善,或者更改一些主函数,让程序更完整谢谢!!!
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MAXN 35
#define MAX_NAME 256
typedef struct student  //学生信息
{
    int  no;
    char name[MAX_NAME];
    double  english;
    double  math;
    double  Programming;
    double  mark_ave;
    double  mark_tot;
} STUDENT;
/*-----------输入信息子程序---------*/
void input(STUDENT *data, int *len)
{
    int no;
    putchar('\n');
    printf("%s\n", "请输入新的记录,如果需要退出当前菜单请输入0.");
    printf("%s\n", "格式:\n学号 姓名 性别 年龄 年级\n");
    putchar('\n');
    printf("例如:\n");
    printf("1 张三 男 19 大一\n");
    scanf("%d", &no);
    while(no !=0) {
        data[*len].no = no;
        scanf("%s %lf %lf %lf", data[*len].name, &data[*len].english, &data[*len].math,&data[*len].Programming);        data[*len].mark_ave=(data[*len].english+data[*len].math+data[*len].Programming)/3.0;        data[*len].mark_tot=data[*len].english+data[*len].math+data[*len].Programming;
        (*len)++;
        scanf("%d", &no);
    }   
}
/*---------------输出信息子程序---------------*/
void output(STUDENT *data, int len)
{
  int i;
    system("cls");
  printf("%8s", "学号");
  printf("%8s", "姓名");
  printf("%8s", "英语");
  printf("%8s", "数学");
  printf("%10s", "C语言");
  printf("%12s", "平均分");
  printf("%10s", "总分");
  putchar('\n');
  for (i =0; i < 80; i++)
    putchar('=');
  putchar('\n');
  for (i = 0; i< len; i++)
  {
    printf("%8d", data[i].no);
    printf("%8s", data[i].name);
    printf("%8.1lf", data[i].english);
    printf("%8.1lf", data[i].math);
    printf("%10.1lf", data[i].Programming);
    printf("%12.1lf", data[i].mark_ave);
    printf("%10.1lf", data[i].mark_tot);
    putchar('\n');
  }
  for (i =0; i < 80; i++)
    putchar('=');
  putchar('\n');
  printf("按回车键继续.");
  getchar();
  getchar();
}
/*--------------排序子程序------------*/
void sort(STUDENT *data, int len)
{
  int i,j,k;
  STUDENT temp;
  for (i=0; i<len-1; i++) {
    for (k=i, j=i+1; j<len; j++)
      if (data[k].mark_ave > data[j].mark_ave) k=j;
            if (k != i) {
                temp = data[i];
                data[i] = data[k];
                data[k] = temp;
            }
  }
}
/*--------------------搜索子程序-----------------------*/
void find(STUDENT *data, int len)
{
  int find_no, result ;
  int i;
lab: result=0;
         printf("%s\n", "请输入需要查找的学生的学号,退出当前菜单请输入 0.");
         scanf("%d", &find_no);
         if (find_no == 0) return;     /*exit the fine sub program*/
         while( data[result].no != find_no && result < len) result ++;
         if (result >= len ) {
             printf("%s\n", "未查询到相关信息");
             goto lab;
         }
         else {
             system("cls");
             printf("%s\n", "查询信息如下:");
             for (i =0; i < 80; i++)
                 putchar('=');
             putchar('\n');
             printf("%8s", "学号");
             printf("%8s", "姓名");
             printf("%8s", "英语");
             printf("%8s", "数学");
             printf("%10s", "C语言");
             printf("%12s", "平均分");
             printf("%10s", "总分");
             putchar('\n');
             printf("%8d", data[result].no);
             printf("%8s", data[result].name);
             printf("%8.1lf", data[result].english);
             printf("%8.1lf", data[result].math);
             printf("%10.1lf", data[result].Programming);
             printf("%12.1lf", data[result].mark_ave);
             printf("%10.1lf", data[result].mark_tot);
             putchar('\n');
             for (i =0; i < 80; i++)
                 putchar('=');
             putchar('\n');
             goto lab;
         }
}
/*-----------------插入子程序-------------*/
void insert(STUDENT *data, int *len)
{
  int no, pos;
    double english, math, Programming, mark_ave, mark_tot;
    int i;
  char name[MAX_NAME];
lab: printf("%s\n", "输入新的记录,退出当前菜单请输入0.");
         printf("%s\n", "格式:学号 姓名 英语 数学 C语言");
         scanf("%d", &no);
         if (no == 0) return;
         data[*len].no = no;
         scanf("%s %lf %lf %lf", name, &english, &math, &Programming);
         mark_ave=(english+math+Programming)/3.0;
         mark_tot=english+math+Programming;
         pos = 0;
         while ((data[pos].mark_ave < mark_ave) && (pos < *len) )
             pos ++;
         for (i = *len-1; i >= pos; i--)
             data[i+1] = data[i];
         data[pos].no = no;
         strcpy(data[pos].name, name);
         data[pos].english = english;
         data[pos].math = math;
         data[pos].Programming = Programming;
         data[pos].mark_ave = mark_ave;
         data[pos].mark_tot = mark_tot;
         (*len)++;
         goto lab;
}
/*-------------删除子程序--------------*/
void delete_item(STUDENT *data, int *len)
{
  int no, i, pos;
lab: pos=0;
         printf("%s\n", "输入需要删除的学生的学号,退出当前菜单请输入0.");
         scanf("%d", &no);
         if (no == 0) return;
         while( (data[pos].no != no) && (pos < *len) ) pos = pos +1;
         if (pos >= *len) {
             printf("%s\n", "未找到需要删除的学生");
             goto lab;
         }
         else {
             for (i = pos+1;i < *len; i++)
                 data[i-1] = data[i];
             *len = *len -1;
             if (*len == 0) {
                 printf("%s\n", "没有任何记录,请按回车键返回.");
                 getchar();
                 getchar();
                 return;
             }
             goto lab;
         }
}

/*---------------统计子程序------------*/
void stat(STUDENT *data, int len)
{
  int no_59=0, no_69=0, no_79=0, no_89=0, no_100=0;
  int i;
  for (i = 0;i < len; i++) {
    if (data[i].mark_ave <=59) no_59++;
    else if (data[i].mark_ave <=69) no_69++;
        else if (data[i].mark_ave <=79) no_79++;
        else if (data[i].mark_ave <= 89) no_89++;
        else no_100++;
  }
   
}
/*---------------显示信息子程序------------*/
void paint()
{
  int i;
    system("cls");
  printf("%55s\n", "成绩管理系统         \n");
  for (i = 0; i < 80; i++)
    putchar('=');
  putchar('\n');
  printf("             1 输入学生信息                    2 查找学生信息\n");
  printf("             3 按平均分排序                    4 按学号查找\n");
  printf("             5 输入学生成绩                    6 按学号删除\n");
  printf("             7 保存到文件\n");
  printf("             0 退出\n");
    for (i = 0; i<= 79; i++)
    putchar('=');
  putchar('\n');
  printf("%s\n", "请输入各操作对应的序号:");
}
void save(STUDENT *data, int len)//将数据保存到文件
{
    int i;
    FILE *fp;
    fp=fopen("成绩统计表.txt","w");
    fprintf(fp,"%8s", "学号");
  fprintf(fp,"%8s", "姓名");
  fprintf(fp,"%8s", "英语");
  fprintf(fp,"%8s", "数学");
  fprintf(fp,"%10s", "C语言");
  fprintf(fp,"%12s", "平均分");
  fprintf(fp,"%10s\n", "总分");
  fprintf(fp,"========================================================================\n");
  putchar('\n');
  for (i = 0; i< len; i++)
  {
    fprintf(fp,"%8d", data[i].no);
    fprintf(fp,"%8s", data[i].name);
    fprintf(fp,"%8.1lf", data[i].english);
    fprintf(fp,"%8.1lf", data[i].math);
    fprintf(fp,"%10.1lf", data[i].Programming);
    fprintf(fp,"%12.1lf", data[i].mark_ave);
    fprintf(fp,"%10.1lf\n", data[i].mark_tot);
  }
  fprintf(fp,"========================================================================\n");
    fclose(fp);
    printf("文件已保存到\"成绩统计表.txt\"");
    getchar();getchar();
}
/*-----------主程序--------------*/
void main()
{
  STUDENT data[MAXN];
  int len = 0;
  char ctrl_ch;
  paint();
  scanf("%c", &ctrl_ch);
  while (ctrl_ch != '0') {
    switch(ctrl_ch) {
        case '1':
            input(data, &len);
            break;
        case '2':
            output(data, len);
            break;
        case '3':
            sort(data, len);
            break;
        case '4':
            find(data, len);
            break;
        case '5':
            insert(data, &len);
            break;
        case '6':
            delete_item(data, &len);
            break;
        case '7':
            save(data, len);
            break;
        default:
            if (ctrl_ch != '\n') printf("%s\n", "输入错误!");
            break;
    }
    if (ctrl_ch != '\n') paint();
    scanf("%c", &ctrl_ch);
  }
}
搜索更多相关主题的帖子: english include double 子程序 信息 
2016-09-07 10:11
快速回复:求大神帮助修改和完善这个程序
数据加载中...
 
   



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

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