主题:各位大哥,大姐,帮我改一下程序,行不?
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <dos.h>
#define N 10
#define PAGE 2
#define PRINT1 printf("\n 姓名 性别 年龄 系别 专业 班级\n")
#define PRINT2 printf("\n %6s%8s%8d%8s%8s%8d",student[i].name,student[i].sex,student[i].age,student[i].department,student[i].profession,student[i].classes)
#define PRINT3 printf("\n 学号 职务 成 绩 出生日期 地址 电话\n")
#define PRINT4 printf("\n %6d%6s%4d%2d%2d%2d%2d-%2d-%8d%6s%8d\n",student[i].num,student[i].plants,student[i].exam.chinese,student[i].exam.math,student[i].exam.english,aver[i],student[i].birthday.year,student[i].birthday.month,student[i].birthday.date,student[i].add,student[i].telephone)
int sum;
float aver[20]; /*记录学生的人数*/
struct data
{ int year;
int month;
int date;
};
struct score
{ int chinese;
int math;
int english;
};
struct student_type
{ char name[20];
char sex[10];
int age;
char department[20]; /*系别*/
char profession[20]; /*专业*/
int classes;
int num;
char plants[20];
struct score exam;
struct data birthday;
char add[20];
double telephone;
}student[N];
/*保存信息*/
save_message(int sum)
{ FILE *fp;
int i;
if((fp=fopen("student.txt"," wb"))==NULL)
{ printf("读信息错误!\n");
return;
}
for(i=0;i<=sum;i++)
if(fwrite(&student[i],sizeof(struct student_type),1,fp)!=1)
printf("写信息错误!\n");
fclose(fp);
}
/*输入信息*/
input_message()
{ int i=0;
char choice;
int flag;
aver[i]=(float)(student[i].exam.chinese+student[i].exam.math+student[i].exam.english)/3.0;
window(1,1,80,25);
clrscr();
printf("\n\n 输入学生信息(最多为 %d个) \n",N);
printf(" _________________________________");
do
{
printf("\n 第%d个的学生信息",i+1 );
printf("\n 学生姓名:");
scanf ("%s",student[i].name);
printf(" 学生性别:");
scanf ("%s",student[i].sex);
printf(" 学生年龄:");
scanf ("%d",&student[i].age);
printf(" 学生系别:");
scanf ("%s",&student[i].department);
printf(" 学生专业:");
scanf ("%s",&student[i].profession);
printf(" 学生班级:");
scanf ("%d",&student[i].classes);
printf(" 学生学号:");
scanf ("%d",&student[i].num);
printf(" 学生职务:");
scanf ("%s",&student[i].plants);
printf(" 学生成绩:");
printf("语文:");
scanf ("%d",&student[i].exam.chinese);
printf(" 数学:");
scanf ("%d",&student[i].exam.math);
printf(" 英语:");
scanf ("%d",&student[i].exam.english);
printf(" 平均成绩:%f",aver);
printf(" 出生日期(yyyy-mm-dd): ");
scanf("%d-%d-%d",&student[i].birthday.year,&student[i].birthday.month,&student[i].birthday.date);
printf(" 家庭地址: ");
scanf("%s",student[i].add);
printf(" 学生电话:");
scanf ("%d",&student[i].telephone);
printf("\n您还想继续吗?(Y/N) ");
choice=getch();
if(choice=='y'||choice=='Y')
{ printf("\n 继续!\n");
clrscr();
i++;
flag=1;
}
else flag=0;
}while(flag==1);
printf("\n 第%d 个学生的信息已经输入完毕!\n",i+1 );
sum=i+1;
printf("\n 按任意键返回主菜单!");
bioskey(0);
}
/*读取信息*/
read_message()
{ FILE *fp;
int i=0;
window(1,1,80,25);
if((fp=fopen("student.txt","rb"))==NULL)
{ printf("\n\n *****现在,还没有任何学生的信息, 按任意键返回主菜单!*****\n");
return 0;
}
while(feof(fp)!=1)
{ fread(&student[i],sizeof(struct student_type),1,fp);
if(student[i].num==0) break;
else i++;
}
fclose(fp);
return(i);
}
output_message()
{ int i=0,page=1;
int j=0;
window(1,1,80,25);
clrscr();
printf("\n\n ----学生管理信息---- 第%d页\n\n", page);
printf(" ---------------------------------");
do
{ if(student[i].num!=0)
{ j++;
if(j%PAGE!=0)
{ PRINT1;
PRINT2;
PRINT3;
PRINT4;
}
else
{ PRINT1;
PRINT2;
PRINT3;
PRINT4;
if(student[i+1].num!=0)
{ printf("按任意键继续!");
bioskey(0);
clrscr();
printf("\n\n --学生管理信息-- 第%d页\n\n ",++page);
printf(" ----------------------------");
PRINT1;
}
}
}
i++;
}while(student[i].num!=0);
printf("按任意键退出!");
bioskey(0);
}
insert_message()
{ int i=sum;
int flag=0;
char choice;
aver[i]=(float)(student[i].exam.chinese+student[i].exam.math+student[i].exam.english)/3.0;
clrscr();
printf("\n\n 插入学生信息\n");
do
{ student[i].num=++sum;
printf("\n 新生学号: %d ",student[i].num);
printf("\n 姓名:");
scanf ("%s",&student[i].name);
printf("\n 性别:");
scanf ("%s",&student[i].sex);
printf("\n 年龄:");
scanf ("%d",&student[i].age);
printf("\n 系别:");
scanf ("%s",&student[i].department);
printf("\n 专业:");
scanf ("%s",&student[i].profession);
printf("\n 班级:");
scanf ("%d",&student[i].classes);
printf("\n 学号:");
scanf ("%d",&student[i].num);
printf("\n 职务:");
scanf ("%s",&student[i].plants);
printf("\n 学生成绩:");
printf("语文:");
scanf ("%d",&student[i].exam.chinese);
printf(" 数学:");
scanf ("%d",&student[i].exam.math);
printf(" 英语:");
scanf ("%d",&student[i].exam.english);
printf("\n 平均成绩:%f",aver);
printf("\n 出生日期(yyyy-mm-dd):");
scanf ("%d-%d-%d",&student[i].birthday.year,&student[i].birthday.month,&student[i].birthday.date);
printf("\n 电话:");
scanf ("%d", &student[i].telephone);
printf("\n 地址:");
scanf ("%s",student[i].add);
printf("\n 您还想继续吗?(Y/N)");
choice=getch();
if(choice=='y'||choice=='Y')
{ printf("\n 继续!\n");
i++;
flag=1;
}
else flag=0;
}while(flag==1);
printf("\n 按任意键退出!");
bioskey(0);
}
#include <graphics.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <dos.h>
#define N 10
#define PAGE 2
#define PRINT1 printf("\n 姓名 性别 年龄 系别 专业 班级\n")
#define PRINT2 printf("\n %6s%8s%8d%8s%8s%8d",student[i].name,student[i].sex,student[i].age,student[i].department,student[i].profession,student[i].classes)
#define PRINT3 printf("\n 学号 职务 成 绩 出生日期 地址 电话\n")
#define PRINT4 printf("\n %6d%6s%4d%2d%2d%2d%2d-%2d-%8d%6s%8d\n",student[i].num,student[i].plants,student[i].exam.chinese,student[i].exam.math,student[i].exam.english,aver[i],student[i].birthday.year,student[i].birthday.month,student[i].birthday.date,student[i].add,student[i].telephone)
int sum;
float aver[20]; /*记录学生的人数*/
struct data
{ int year;
int month;
int date;
};
struct score
{ int chinese;
int math;
int english;
};
struct student_type
{ char name[20];
char sex[10];
int age;
char department[20]; /*系别*/
char profession[20]; /*专业*/
int classes;
int num;
char plants[20];
struct score exam;
struct data birthday;
char add[20];
double telephone;
}student[N];
/*保存信息*/
save_message(int sum)
{ FILE *fp;
int i;
if((fp=fopen("student.txt"," wb"))==NULL)
{ printf("读信息错误!\n");
return;
}
for(i=0;i<=sum;i++)
if(fwrite(&student[i],sizeof(struct student_type),1,fp)!=1)
printf("写信息错误!\n");
fclose(fp);
}
/*输入信息*/
input_message()
{ int i=0;
char choice;
int flag;
aver[i]=(float)(student[i].exam.chinese+student[i].exam.math+student[i].exam.english)/3.0;
window(1,1,80,25);
clrscr();
printf("\n\n 输入学生信息(最多为 %d个) \n",N);
printf(" _________________________________");
do
{
printf("\n 第%d个的学生信息",i+1 );
printf("\n 学生姓名:");
scanf ("%s",student[i].name);
printf(" 学生性别:");
scanf ("%s",student[i].sex);
printf(" 学生年龄:");
scanf ("%d",&student[i].age);
printf(" 学生系别:");
scanf ("%s",&student[i].department);
printf(" 学生专业:");
scanf ("%s",&student[i].profession);
printf(" 学生班级:");
scanf ("%d",&student[i].classes);
printf(" 学生学号:");
scanf ("%d",&student[i].num);
printf(" 学生职务:");
scanf ("%s",&student[i].plants);
printf(" 学生成绩:");
printf("语文:");
scanf ("%d",&student[i].exam.chinese);
printf(" 数学:");
scanf ("%d",&student[i].exam.math);
printf(" 英语:");
scanf ("%d",&student[i].exam.english);
printf(" 平均成绩:%f",aver);
printf(" 出生日期(yyyy-mm-dd): ");
scanf("%d-%d-%d",&student[i].birthday.year,&student[i].birthday.month,&student[i].birthday.date);
printf(" 家庭地址: ");
scanf("%s",student[i].add);
printf(" 学生电话:");
scanf ("%d",&student[i].telephone);
printf("\n您还想继续吗?(Y/N) ");
choice=getch();
if(choice=='y'||choice=='Y')
{ printf("\n 继续!\n");
clrscr();
i++;
flag=1;
}
else flag=0;
}while(flag==1);
printf("\n 第%d 个学生的信息已经输入完毕!\n",i+1 );
sum=i+1;
printf("\n 按任意键返回主菜单!");
bioskey(0);
}
/*读取信息*/
read_message()
{ FILE *fp;
int i=0;
window(1,1,80,25);
if((fp=fopen("student.txt","rb"))==NULL)
{ printf("\n\n *****现在,还没有任何学生的信息, 按任意键返回主菜单!*****\n");
return 0;
}
while(feof(fp)!=1)
{ fread(&student[i],sizeof(struct student_type),1,fp);
if(student[i].num==0) break;
else i++;
}
fclose(fp);
return(i);
}
output_message()
{ int i=0,page=1;
int j=0;
window(1,1,80,25);
clrscr();
printf("\n\n ----学生管理信息---- 第%d页\n\n", page);
printf(" ---------------------------------");
do
{ if(student[i].num!=0)
{ j++;
if(j%PAGE!=0)
{ PRINT1;
PRINT2;
PRINT3;
PRINT4;
}
else
{ PRINT1;
PRINT2;
PRINT3;
PRINT4;
if(student[i+1].num!=0)
{ printf("按任意键继续!");
bioskey(0);
clrscr();
printf("\n\n --学生管理信息-- 第%d页\n\n ",++page);
printf(" ----------------------------");
PRINT1;
}
}
}
i++;
}while(student[i].num!=0);
printf("按任意键退出!");
bioskey(0);
}
insert_message()
{ int i=sum;
int flag=0;
char choice;
aver[i]=(float)(student[i].exam.chinese+student[i].exam.math+student[i].exam.english)/3.0;
clrscr();
printf("\n\n 插入学生信息\n");
do
{ student[i].num=++sum;
printf("\n 新生学号: %d ",student[i].num);
printf("\n 姓名:");
scanf ("%s",&student[i].name);
printf("\n 性别:");
scanf ("%s",&student[i].sex);
printf("\n 年龄:");
scanf ("%d",&student[i].age);
printf("\n 系别:");
scanf ("%s",&student[i].department);
printf("\n 专业:");
scanf ("%s",&student[i].profession);
printf("\n 班级:");
scanf ("%d",&student[i].classes);
printf("\n 学号:");
scanf ("%d",&student[i].num);
printf("\n 职务:");
scanf ("%s",&student[i].plants);
printf("\n 学生成绩:");
printf("语文:");
scanf ("%d",&student[i].exam.chinese);
printf(" 数学:");
scanf ("%d",&student[i].exam.math);
printf(" 英语:");
scanf ("%d",&student[i].exam.english);
printf("\n 平均成绩:%f",aver);
printf("\n 出生日期(yyyy-mm-dd):");
scanf ("%d-%d-%d",&student[i].birthday.year,&student[i].birthday.month,&student[i].birthday.date);
printf("\n 电话:");
scanf ("%d", &student[i].telephone);
printf("\n 地址:");
scanf ("%s",student[i].add);
printf("\n 您还想继续吗?(Y/N)");
choice=getch();
if(choice=='y'||choice=='Y')
{ printf("\n 继续!\n");
i++;
flag=1;
}
else flag=0;
}while(flag==1);
printf("\n 按任意键退出!");
bioskey(0);
}