正文

学生成绩管理系统2005-09-21 23:49:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/wojiele/5087.html

分享到:

/*第三方函数库: SGCHN3.0*/
/*该库函数的的一些函数说明
/*  C Head File.

    SGCHN30.h

    Definitions for SGCHN3.0 Run time Library Function.

    Copyright (c) 2004, 2005 SGPRO
    All Rights Reserved.

    Autor: YinShengge 作者: 殷圣鸽

    Version: 3.0
    Build Time: 2004 - 4

    Maintain Time: 2005-5-14
    Maintain Time: 2005-5-19  
*/

extern void  SGCHNinit();
extern char  *getsgchnversion();   /*获得SGCHN版本*/  
extern int   scanformat(char *formats, ...);    /*控制台格式输入  与scanf类似*/
extern int   print(char *formats,...);          /*控制台格式输出  与printf类似*/
extern int   *getsforcon(char *string);         /*从控制台读入一行字符串,存入string*/
extern char  getcharforcon();                 /*从控制台读入一个字符.回显*/
extern int   putsforcon(char *string);             /*控制台输出一行字符*/
extern int   saveconsole(const char *filename);
extern int   sgchnquikstart();  /*SGCHN系统快速启动.*/


#endif
再说明一下 ,函数: saveconsole(const char *filename) 可以将控制台的内容保存到 文件: filename中
changeconsolesize(int size);
*/
程序:
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<dos.h>
#define swap(x,y,t) ((t)=(x),(x)=(y),(y)=(t))
#define N 30
#define C 15
#define ok 1
#define error 0
typedef int status;
typedef struct stud
{
long num;
char name[C];
int  high_math;
int english;
int physics;
int program;
int database;
int total;
int ave;
}student;
student chengji[N];
int number,ave[N];
status assert(int x)
{
if(x>=0&&x<=100)
return ok;
else
return error;
}
status create_chengjilist()
{
int num,i;
print("\n正在创建学生成绩表,请稍等.........\n");
sleep(6);
print("请输入学生的数目(<30):");
scanformat("%d",&num);
while(num>N)
{
print("\n你输入的人数太多!");
print("\n请重新输入:");
scanformat("%d",&num);
}
for(i=0;i<num;i++)
{
print("\n输入第%d个学生的成绩信息:\n",i+1);
print("学号:");
scanformat("%ld",&chengji[i].num);
print("\n姓名:");
scanformat("%s",chengji[i].name);
print("\n高等数学:");
scanformat("%d",&chengji[i].high_math);
while(!assert(chengji[i].high_math))
{
print("\n输入非法格式.");
print("\n请重新输入.");
scanformat("%d",&chengji[i].high_math);
}
print("\n英语:");
scanformat("%d",&chengji[i].english);
while(!assert(chengji[i].english))
{
print("\n输入非法格式.");
print("\n请重新输入.");
scanformat("%d",&chengji[i].english);
}
print("\n物理:");
scanformat("%d",&chengji[i].physics);
while(!assert(chengji[i].physics))
{
print("\n输入非法格式.");
print("\n请重新输入.");
scanformat("%d",&chengji[i].physics);
}
print("\n程序设计:");
scanformat("%d",&chengji[i].program);
while(!assert(chengji[i].program))
{
print("\n输入非法格式.");
print("\n请重新输入.");
scanformat("%d",&chengji[i].program);
}
print("\n数据库:");
scanformat("%d",&chengji[i].database);
while(!assert(chengji[i].database))
{
print("\n输入非法格式.");
print("\n请重新输入.");
scanformat("%d",&chengji[i].database);
}
chengji[i].total=chengji[i].high_math+chengji[i].english+chengji[i].physics+chengji[i].program+chengji[i].database;
chengji[i].ave=chengji[i].total/5;
}
print("\n学生成绩表创建成功!!!\n");
return num;
}
void show(int data)
{
int i;
print("\n学生成绩表的所有信息:\n");
for(i=0;i<data;i++)
{
if(!(chengji[i].name[0]==''))
{
print("\n第%d个学生信息:",i+1);
print("\n学号:");
print("%ld",chengji[i].num);
print("\n姓名:");
print("%s",chengji[i].name);
print("\n高等数学:");
print("%d",chengji[i].high_math);
print("\n英语:");
print("%d",chengji[i].english);
print("\n物理:");
print("%d",chengji[i].physics);
print("\n程序设计:");
print("%d",chengji[i].program);
print("\n数据库:");
print("%d",chengji[i].database);
print("\n总分:");
print("%d",chengji[i].total);
print("\n平均分:");
print("%d",chengji[i].ave);
}
}
}
status search_num(int v,long d)
{
int i;
for(i=0;i<v;i++)
  {
if(chengji[i].num==d)
   break;
   }
if(i==v)
{
print("\n成绩表中不存在该生.");
return;
}
else
{
print("\n查找学生的信息是:\n");
print("\n学号:");
print("%ld",chengji[i].num);
print("\n姓名:");
print("%s",chengji[i].name);
print("\n高等数学:");
print("%d",chengji[i].high_math);
print("\n英语:");
print("%d",chengji[i].english);
print("\n物理:");
print("%d",chengji[i].physics);
print("\n程序设计:");
print("%d",chengji[i].program);
print("\n数据库:");
print("%d",chengji[i].database);
print("\n总分:");
print("%d",chengji[i].total);
print("\n平均分:");
print("%d",chengji[i].ave);
return i;
}
}
void search_name(int s)
{
int i;
char string[C];
print("\n请输入要查找学生的姓名:");
scanformat("%s",string);
for(i=0;i<s;i++)
{
if(!strcmp(string,chengji[i].name))
break;
}
if(i==s)
{
print("\n成绩表中不存在该生.");
return;
}
else
{
print("\n该生的成绩记录:\n");
print("\n学号:");
print("%ld",chengji[i].num);
print("\n姓名:");
print("%s",chengji[i].name);
print("\n高等数学:");
print("%d",chengji[i].high_math);
print("\n英语:");
print("%d",chengji[i].english);
print("\n物理:");
print("%d",chengji[i].physics);
print("\n程序设计:");
print("%d",chengji[i].program);
print("\n数据库:");
print("%d",chengji[i].database);
print("\n总分:");
print("%d",chengji[i].total);
print("\n平均分:");
print("%d",chengji[i].ave);
}
}
void searchlist(int t)
{
int i;
long num;
char ch;
while(1)
{
print("\n1.学号.\n2.姓名");
print("\n你想通过什么查询.请选择:");
scanformat("%d",&i);
switch(i)
{
case 1:
print("\n请输入要查找学生的学号:");
scanformat("%ld",&num);
search_num(t,num);
break;
case 2:
search_name(t);
break;
default:
print("\n非法输入.");
break;
}
print("\n想继续查询吗?Y or N?:");
scanformat("%ch",&ch);
if(ch=='N'||ch=='n')
break;
}
}
void show_menu()
{
print("==================================");
print("\n1.显示成绩表中所有的学生成绩信息.");
print("\n2.查询学生的成绩信息.");
print("\n3.加入学生的成绩信息.");
print("\n4.删除学生的成绩信息.");
print("\n5.显示各科目的平均分.");
print("\n6.显示学生成绩排名情况.");
print("\n7.退出学生成绩管理系统.");
print("\n================================");
print("\n请选择你想要的操作:");
}
status insertlist(int m)
{
char ch;
print("\n请输入加入学生的成绩信息:\n");
while(1)
{
print("\n输入第%d个学生的成绩信息:\n",m+1);
print("学号:");
scanformat("%ld",&chengji[m].num);
print("\n姓名:");
scanformat("%s",chengji[m].name);
print("\n高等数学:");
scanformat("%d",&chengji[m].high_math);
while(!assert(chengji[m].high_math))
{
print("\n输入非法格式.");
print("\n请重新输入.");
scanformat("%d",&chengji[m].high_math);
}
print("\n英语:");
scanformat("%d",&chengji[m].english);
while(!assert(chengji[m].english))
{
print("\n输入非法格式.");
print("\n请重新输入.");
scanformat("%d",&chengji[m].english);
}
print("\n物理:");
scanformat("%d",&chengji[m].physics);
while(!assert(chengji[m].physics))
{
print("\n输入非法格式.");
print("\n请重新输入.");
scanformat("%d",&chengji[m].physics);
}
print("\n程序设计:");
scanformat("%d",&chengji[m].program);
while(!assert(chengji[m].program))
{
print("\n输入非法格式.");
print("\n请重新输入.");
scanformat("%d",&chengji[m].program);
}
print("\n数据库:");
scanformat("%d",&chengji[m].database);
while(!assert(chengji[m].database))
{
print("\n输入非法格式.");
print("\n请重新输入.");
scanformat("%d",&chengji[m].database);
}
chengji[m].total=chengji[m].high_math+chengji[m].english+chengji[m].physics+chengji[m].program+chengji[m].database;
chengji[m].ave=chengji[m].total/5;
print("\n成功的加入一个学生的成绩信息.");
m=m+1;
print("\n想继续吗?Y or n?:");
scanf("%c",&ch);
if(ch=='N'||ch=='n')
return m;
}
}
void deletelist(int n)
{
char ch,string[C];
int i;
long xuehao;
string[0]='\0';
print("\n请输入你想删去的学生的学号:");
scanf("%ld",&xuehao);
print("\n你要删去的学生的信息:\n");
i=search_num(n,xuehao);
print("\n你真的要删去该生的成绩信息吗?Y or N ?:");
scanformat("%c",&ch);
if(ch=='Y'||ch=='y')
{
strcpy(chengji[i].name,string);
print("\n你已经成功的删去了该生的成绩信息!!\n");
return;
}
else
return;
}


void show_average()
{
int sum1=0,sum2=0,sum3=0,sum4=0,sum5=0,i;
print("\n正在计算各科目的平均分,请稍等.........");
sleep(5);
for(i=0;i<number;i++)
if(!(chengji[i].name[0]==' '))
{
sum1+=chengji[i].high_math;
sum2+=chengji[i].english;
sum3+=chengji[i].physics;
sum4+=chengji[i].program;
sum5+=chengji[i].database;
}
print("\n高等数学:%d",sum1/number);
print("\n英语:%d",sum2/number);
print("\n物理:%d",sum3/number);
print("\n程序设计:%d",sum4/number);
print("\n数据库:%d",sum5/number);
}
status search_ave(int average)
{
int i;
for(i=0;i<number;i++)
{
if(chengji[i].name[0]==' ')
continue;
if(ave[i]==average)
{
ave[i]=0;
return i;
}
}
return -1;
}

void search_paiming()
{
int numb[N],i,j,temp,k,m=0;/*??????*/
for(i=0;i<number;i++)
numb[i]=chengji[i].ave;
for(i=number;i>=0;i--)
{
for(j=i-1;j>=0;j--)
if(numb[j]<numb[i])
{
swap(numb[j],numb[i],temp);
i=j;
}
}
print("\n学生成绩排名:\n");
print("名次             学号              姓名           平均分");
for(i=0;i<number;i++)
{
k=search_ave(numb[i]);
if(k>=0&&chengji[k].name[0]!=' ')
{
print("\n第%d名:",m+1);
print("          %ld",chengji[k].num);
print("          %s",chengji[k].name);
print("          %d",chengji[k].ave);
m++;
}
}
print("\n");
}


main()
{
int choice,i;
number=create_chengjilist();
while(1)
{
print("\n");
show_menu();
scanformat("%d",&choice);
switch(choice)
{
case 1:
show(number);
break;
case 2:
searchlist(number);
break;
case 3:
number=insertlist(number);
break;
case 4:
deletelist(number);
break;
case 5:
show_average();
break;
case 6:
for(i=0;i<number;i++)
ave[i]=chengji[i].ave;
search_paiming();
break;
case 7:
saveconsole("student.txt");
return;
default:
print("\n非法输入!");
break;
}
}
}

阅读(10081) | 评论(7)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册