| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 8113 人关注过本帖, 4 人收藏
标题:花了两个星期编好的学生成绩管理程序-->feng1256转移
只看楼主 加入收藏
303770957
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:838
专家分:2125
注 册:2005-9-10
收藏(4)
 问题点数:0 回复次数:36 
花了两个星期编好的学生成绩管理程序-->feng1256转移

//***************************************************************************************************************************
//程序清单:
#include <iostream.h>
#include <iomanip.h>
#include <fstream>
#include <vector>
#include <malloc.h>
#include <stdlib.h>
#include <string>
#include <process.h>
#include <stdio.h>
#define NULL 0
int const Q=20;
#define LEN sizeof(struct student)
using namespace std;
int n=0; //定义一个全局变量统计学生人数
//——--------->定义一个学生考试信息的结构体
struct student
{
char name[Q]; //用来存放姓名的
char sex[Q]; //用来存放性别的
long int id; //用来存放准考证号的
int score[4]; //用来存放分数的
int total; //用来存放总分数的
struct student *next;
};
//student向量容器
vector <student> stu;
//-------------->学生类
class Information
{
public:
Information() ; //构造函数.
~Information() ; //析构函数.
student *creat();//建立链表函数。
void output(student *head);
int count(student *head);//定义函数count()统计考生总数
student *insert(student*head);//指针函数*insert()用来添加考生信息.
student *cancel(student *head,long int num);//指针函数*cancel()用来删除考生信息.
student *find(student *head,long int num); //指针函数*find()用来查找考生信息.
void paixu(student *head);//定义paixu()函数将考生的总分从大到小排列并输出
void average( student *head);//求学生成绩的平均分的函数
void save(student *head);//保存函数
student *Read();//读取函数
private:
student *p1,*p2,*p3,*head,st;
};
Information::Information()
{cout<<" ******************************************************************************\n";
cout<<" ------------------------<<欢迎您使用学生成绩管理系统>>------------------------\n";
cout<<" ******************************************************************************\n\n";
}
Information::~Information()
{ cout<<" ******************************************************************************\n";
cout<<" ------------------------<<谢谢您使用学生成绩管理系统>>------------------------\n";
cout<<" ******************************************************************************\n";
}
//------------>建立链表函数
student *Information::creat(void)
{//定义一个指向struct student的结构体指针函数*creat()用来增加考生信息.
char ch[Q];n=0; //用来存放姓名的
p1=p2=(student *)malloc(LEN);//调用malloc()函数用来开辟一个新的存储单元
cout<<" -------------<<请建立学生考试信息表,在姓名处键以 ! 结束输入。>>--------------"<<endl;
cout<<" 姓名:";
cin>>ch;
head=NULL; //给指针head赋初值
while (strcmp(ch,"!")!=0)
{//调用字符比较函数strcmp()用来判断是否继续输入
p1=(student *)malloc(LEN);//调用malloc()函数用来开辟一个新的存储单元
strcpy(p1->name,ch); //将循环结构前面输入的姓名复制到结构体名为p1的数组name中
cout<<" 性别:";
cin>>p1->sex;
cout<<" 准考证号(8位):";
cin>>p1->id;
cout<<" 数学成绩:";
cin>>p1->score[0];
cout<<" 物理成绩:";
cin>>p1->score[1];
cout<<" 英语成绩:";
cin>>p1->score[2];
cout<<" C语言成绩:";
cin>>p1->score[3];
p1->total=p1->score[0]+p1->score[1]+p1->score[2]+p1->score[3];//计算总分
if(n==0)head=p1;//如果是输入第一组学生考试信息就将指针p1赋给指针head
else p2->next=p1;//否则将p1赋给p2所指结构体的next指针
p2=p1;//将指针p1赋给指针p2
n++; //将n的值加1
cout<<" 姓名:";
cin>>ch;//将输入的姓名存放到字符数组ch中
}
p2->next=NULL;//将p2所指结构体的next指针重新赋空值
return (head);//将输入的第一组学生考试信息返回
}
//--------------->定义output()函数将考生的信息从头指针所指内容开始输出
void Information::output(student *head)
{

if(head==NULL) cout<<" 这是一个空表,请先输入考生成绩.\n";
else{
cout<<"-------------------------------------------------------------------------------\n";
cout<<" *学生考试成绩信息表*\n";
cout<<"-------------------------------------------------------------------------------\n";
cout<<"准考证号 姓 名 性别 数学 物理 英语 C++ 平均分 总分\n";
cout<<"-------------------------------------------------------------------------------\n";
p1=head;//将头指针赋给p
do
{
cout<<setw(8)<<p1->id
<<setw(9)<<p1->name
<<setw(8)<<p1->sex
<<setw(8)<<p1->score[0]
<<setw(9)<<p1->score[1]
<<setw(9)<<p1->score[2]
<<setw(9)<<p1->score[3]
<<setw(9)<<p1->total/4.0
<<setw(9)<<p1->total<<endl;
cout<<"-------------------------------------------------------------------------------\n";
p1=p1->next;//将下一组考生信息的next指针赋给p
}while(p1!=NULL);//若指针p非空则继续,目的是把所有的考生信息都传给指针p然后输出.
}
}
//------------>统计学生人数的函数
int Information::count(struct student *head)//定义函数count()统计考生总数
{
if(head==NULL)return(0);//若指针head为空返回值为0
else return(1+count(head->next));//函数的递归调用
}
//----------->插入学生的成绩的函数
student *Information::insert( student *head)
//插入新结点定义一个指向struct student的结构体指针函数*insert()用来添加考生信息.
{

cout<<"\t----------------<<请输入新增学生成绩信息>>----------------\n"<<endl;
p1=(student *)malloc(LEN); //使p1指向插入的新结点
cout<<" 准考证号(8位):";
cin>>p1->id; //将输入的准考证号存放到p1所指结构体的数组id中
cout<<" 姓名:";
cin>>p1->name; //将输入的姓名存放到结构体名为p1的数组name中
cout<<" 性别:";
cin>>p1->sex;
cout<<" 数学成绩:";
cin>>p1->score[0];//将输入的数学成绩存放到p1所指结构体的数组score中
cout<<" 物理成绩:";
cin>>p1->score[1];//将输入的物理成绩存放到p1所指结构体的数组score中
cout<<" 英语成绩:";
cin>>p1->score[2];//将输入的英语成绩存放到p1所指结构体的数组score中
cout<<" C语言成绩:";
cin>>p1->score[3];//将输入的C语言成绩存放到p1所指结构体的数组score中
p1->total=p1->score[0]+p1->score[1]+p1->score[2]+p1->score[3];//计算总分
p2=head;//将头指针赋给p2
if(head==NULL) //若没调用次函数以前的头指针head为空
{
head=p1;p1->next=NULL;
}//则将p1赋给头指针head并将p1所指结构体成员指针next赋空值
else
{
while((p1->id>p2->id)&&(p2->next!=NULL))
{
p3=p2;//p3指向原p2指向的结点
p2=p2->next;
}//p2后移一个结点
if(p1->id<=p2->id)
{
if(head==p2)
{
p1->next=head;
head=p1;
} //插入到第一个结点之前
else
{
p3->next=p1;
p1->next=p2;
} //插入到p3所指结点之后
}
else
{
p2->next=p1;
p1->next=NULL;
} //插入到尾结点之后
}
n++;//将学生人数加1
cout<<"\t----------------<<你输入的学生信息已经成功插入>>----------------"<<endl;
return (head);
}
//------------>删除函数
student *Information::cancel(student *head,long int num)//定义一个指向struct student的结构体指针函数*delete()用来删除考生信息.
{

if(head==NULL)//若调用次函数以前的头指针head为空
{
return(head);
}
else
{
p1=head;//否则将头指针赋给p1
while(num!=p1->id&&p1->next!=NULL)//寻找要删除的结点当p1所指的学生准考证号不是输入的学生准考证号并且p1所指的next指针不为空
{
p2=p1;
p1=p1->next;
}//p2指向原p1指向的结点p1后移一个结点
if(num==p1->id)//如果输入的学生准考证号是p1所指的学生准考证号//结点找到后删除
{
if(p1==head) head=p1->next;//如果head指针和p1指针相等则将下一个结点赋给指针head
else
p2->next=p1->next;//否则将p1所指结点赋给p2所指结点将要删除的学生信息跳过去
cout<<" 删除准考证号为"<<num<<"的学生\n";
n--;//将学生人数减1
}
return(head);//将头指针返回
}
}
//------------>查找函数
student *Information::find(student *head,long int num)
//定义一个指向struct student的结构体指针函数*find()用来查找考生信息.
{

if(head==NULL)//若调用次函数以前的头指针head为空
{
cout<<" 这是一个空表,请先输入考生成绩.\n";
return(head);
}
else
{
p1=head;//否则将头指针赋给p1
while(num!=p1->id&&p1->next!=NULL)
//寻找结点当p1所指的学生准考证号不是输入的学生准考证号并且p1所指的next指针不为空
{
p1=p1->next;
}//p2指向原p1指向的结点p1后移一个结点
if(num==p1->id)//如果要查找的学生准考证号是p1所指的学生准考证号
{
cout<<"------------------------------------------------------------------------------\n";
cout<<"准考证号 姓 名 性别 数学 物理 英语 C++ 平均分 总分 \n";
cout<<"------------------------------------------------------------------------------\n";
cout<<setw(8)<<p1->id
<<setw(9)<<p1->name
<<setw(6)<<p1->sex
<<setw(7)<<p1->score[0]
<<setw(7)<<p1->score[1]
<<setw(7)<<p1->score[2]
<<setw(7)<<p1->score[3]
<<setw(10)<<p1->total/4.0
<<setw(7)<<p1->total<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
else
cout<<" 没找到准考证号为"<<num<<"的学生.\n"; //结点没找到
return(head);
}
}
//------------定义paixu()函数将考生的总分从大到小排列并输出
void Information::paixu(student *head)
{
int i,k,m=0,j;
student *p[Q];//定义一个指向struct student的结构体指针数组p
if(head!=NULL)//如果头指针是空则继续
{ m=count(head);
cout<<"------------------------------------------------------------------------------\n";
cout<<" *学生考试成绩统计表*\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<"准考证号 姓 名 性别 数学 物理 英语 C++ 平均分 总分 名次\n";
cout<<"------------------------------------------------------------------------------\n";
p1=head;
for(k=0;k<m;k++)
{
p[k]=p1;
p1=p1->next;
}
for(k=0;k<m-1;k++) //选择排序法
for(j=k+1;j<m;j++)
if(p[k]->total<p[j]->total)
{
p2=p[k];
p[k]=p[j];
p[j]=p2;
} //从大到小排列的指针
for(i=0;i<m;i++)
{
cout<<setw(8)<<p[i]->id
<<setw(9)<<p[i]->name
<<setw(6)<<p[i]->sex
<<setw(7)<<p[i]->score[0]
<<setw(7)<<p[i]->score[1]
<<setw(7)<<p[i]->score[2]
<<setw(7)<<p[i]->score[3]
<<setw(8)<<p[i]->total/4.0
<<setw(7)<<p[i]->total
<<setw(9)<<i+1<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
}
}
//------------>求各科平均分成绩的函数
void Information::average(student *head)
{

int k,m;
float arg1=0,arg2=0,arg3=0,arg4=0;
if(head==NULL)//如果头指针是空则继续
{
cout<<" 这是一个空表,请先输入考生成绩.\n";
}
else
{
m=count(head);
p1=head;
for(k=0;k<m;k++)
{
arg1+=p1->score[0];
arg2+=p1->score[1];
arg3+=p1->score[2];
arg4+=p1->score[3];
p1=p1->next;
}
arg1/=m;arg2/=m;arg3/=m;arg4/=m;
cout<<" *全班单科成绩平均分*\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<" 数学平均分:"<<setw(7)<<arg1
<<" 物理平均分:"<<setw(7)<<arg2
<<" 英语平均分:"<<setw(7)<<arg3
<<" C语言平均分:"<<setw(7)<<arg4<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
}
//------------------->保存函数.
void Information::save(student *head)
{
ofstream out("data.txt",ios::out);
out<<count(head)<<endl;
while(head!=NULL)
{ out<<head->name<<"\t"
<<head->id<<"\t"<<"\t"
<<head->sex<<"\t"
<<head->score[0]<<"\t"
<<head->score[1]<<"\t"
<<head->score[2]<<"\t"
<<head->score[3]<<"\t"
<<head->total<<endl;
head=head->next;
}

}
//———————————>读取函数的实现
student *Information::Read()
{ int i=0;
p1=p2=( student *)malloc(LEN);
head=NULL;
ifstream in("data.txt",ios::out);
in>>i;
if(i==0){cout<<" data.txt 文件中的数据为空,请先输入数据。"<<endl; return 0;}
else {
cout<<" …………………………………………………………………………………………"<<endl;
for(;i>0;i--)
{ p1=(student *)malloc(LEN);
in>>st.name>>st.id>>st.sex
>>st.score[0]>>st.score[1]>>st.score[2]>>st.score[3]
>>st.total;
strcpy(p1->name,st.name);
p1->id=st.id;
strcpy(p1->sex,st.sex);
p1->score[0]=st.score[0];
p1->score[1]=st.score[1];
p1->score[2]=st.score[2];
p1->score[3]=st.score[3];
p1->total=st.total;
if(n==0)head=p1;//如果是输入第一组学生考试信息就将指针p1赋给指针head
else p2->next=p1;//否则将p1赋给p2所指结构体的next指针
p2=p1;//将指针p1赋给指针p2
n++; //将n的值加1
//显示读入数据
cout<<" "<<p1->name<<"\t"
<<p1->id<<"\t"<<"\t"
<<p1->sex<<"\t"
<<p1->score[0]<<"\t"
<<p1->score[1]<<"\t"
<<p1->score[2]<<"\t"
<<p1->score[3]<<"\t"
<<p1->total<<endl;
cout<<" …………………………………………………………………………………………"<<endl;
//
}
cout<<" 数据已经成功读取完毕。"<<endl;
p2->next=NULL;
return (head);
}

}

搜索更多相关主题的帖子: 管理程序 include 学生 int 变量 
2006-03-12 22:18
303770957
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:838
专家分:2125
注 册:2005-9-10
收藏
得分:0 
接上面:
//------------------------------>主函数.
int main(void)
{
Information person;
student *head=NULL;
int choice;
long int i;
do{
cout<<"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓";
cout<<"┃★ ★ ★ 学生成绩管理系统主菜单界面 ★ ★ ★┃";
cout<<"┃★ ★ ★ ♀读取数据请输入数字零♂ ★ ★ ★┃";
cout<<"┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫";
cout<<"┃ ★ ★ ★ ★ ★ ★ ①.输入学生成绩 ★ ★ ★ ★ ★ ★ ┃";
cout<<"┃ ★ ★ ★ ②.显示学生成绩 ★ ★ ★ ┃";
cout<<"┃ ★ ★ ★ ③.排序统计成绩 ★ ★ ★ ┃";
cout<<"┃ ★ ★ ★ ④.查找学生成绩 ★ ★ ★ ┃";
cout<<"┃ ★ ★ ★ ⑤.增加学生成绩 ★ ★ ★ ┃";
cout<<"┃ ★ ★ ★ ⑥.删除学生成绩 ★ ★ ★ ┃";
cout<<"┃ ★ ★ ★ ★ ★ ★ ⑦.安全退出系统 ★ ★ ★ ★ ★ ★ ┃";
cout<<"┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛";
cout<<" 请输入您的选择(0--7):";
cin>>choice;
switch(choice)
{
case 0:head=person.Read();break;
case 1:
head=person.creat();
break;
case 2:
person.output(head);
break;
case 3:
person.paixu(head); person.average(head);
cout<<" 参加考试的学生人数为:"<<person.count(head)<<"人\n";
break;
case 4:
cout<<" 请输入要查找的准考证号(8位):";
cin>>i;
person.find(head,i);
break;
case 5:
head=person.insert(head);
person.output(head);
break;
case 6:
cout<<" 请输入要删除的准考证号(8位):";
cin>>i;
head=person.cancel(head,i);
person.output(head);
break;
case 7:
person.save(head);
break;
default :cout<<" 对不起,您的输入有误,请重新输入。\n";
break;
}
}while(choice!=7);
return 0;
}
///**************************************************************************************************************************

♂ 死后定当长眠,生前何须久睡。♀
2006-03-12 22:19
feng1256
Rank: 4
等 级:贵宾
威 望:14
帖 子:2899
专家分:0
注 册:2005-11-24
收藏
得分:0 
C++  的啊  

叁蓙大山:工謪、稅務、嗣發 抱歉:不回答女人的问题
2006-03-12 22:22
303770957
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:838
专家分:2125
注 册:2005-9-10
收藏
得分:0 

恩,有什么问题么?


♂ 死后定当长眠,生前何须久睡。♀
2006-03-12 22:23
putao2215
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-7-5
收藏
得分:0 

谢谢了

2006-07-05 16:50
robrk
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-7-1
收藏
得分:0 

谢谢了,我想问下按姓名排序怎么编啊?我找了几天都找不到想关的资料!!

2006-07-06 00:24
robrk
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-7-1
收藏
得分:0 

终于找到了,原来用strcmp也可以比较汉字的

2006-07-06 01:12
robrk
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-7-1
收藏
得分:0 

原型:extern int strcmp(char *s1,char * s2);

用法:#include <string.h>

功能:比较字符串s1和s2。

说明:
当s1<s2时,返回值<0
当s1=s2时,返回值=0
当s1>s2时,返回值>0

举例:

// strcmp.c

#include <syslib.h>
#include <string.h>

main()
{
char *s1="Hello, Programmers!";
char *s2="Hello, programmers!";
int r;

clrscr();

r=strcmp(s1,s2);
if(!r)
printf("s1 and s2 are identical");
else
if(r<0)
printf("s1 less than s2");
else
printf("s1 greater than s2");

getchar();
return 0;
}

2006-07-06 01:15
song4
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:38
帖 子:1533
专家分:4
注 册:2006-3-25
收藏
得分:0 
晕了
开学我把我课程设计拿上来

嵌入式 ARM 单片机 驱动 RT操作系统 J2ME LINUX  Symbian C C++ 数据结构 JAVA Oracle 设计模式 软件工程 JSP
2006-07-06 10:20
303770957
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:838
专家分:2125
注 册:2005-9-10
收藏
得分:0 

//***************************************************************************************************************************
//------------>学生成绩管理系统(我将上面的程序又稍做了加工,也给大家贴上来,请多指教!)
//程序清单:
#include <iomanip>
#include <iostream>
#include <fstream>
#include <vector>
#include <malloc.h>
#include <stdlib.h>
#include <string>
#include <process.h>
#include <stdio.h>
#define NULL 0
int const Q=20;
#define LEN sizeof(struct student)
using namespace std;
int n=0; //定义一个全局变量统计学生人数
//——--------->定义一个学生考试信息的结构体
struct student
{
char name[Q]; //用来存放姓名的
char sex[Q]; //用来存放性别的
long int id; //用来存放准考证号的
int score[4]; //用来存放分数的
int total; //用来存放总分数的
struct student *next;
};
//student向量容器
vector <student> stu;
//-------------->学生类
class Information
{
public:
Information() ; //构造函数.
~Information() ; //析构函数.
student *creat();//建立链表函数。
void output(student *head);
int count(student *head);//定义函数count()统计考生总数
student *insert(student*head);//指针函数*insert()用来添加考生信息.
student *cancel(student *head,long int num);//指针函数*cancel()用来删除考生信息.
student *find(student *head,long int num); //指针函数*find()用来查找考生信息.
void paixu(student *head);//定义paixu()函数将考生的总分从大到小排列并输出
void average( student *head);//求学生成绩的平均分的函数
void save(student *head);//保存函数
student *Read();//读取函数
private:
student *p1,*p2,*p3,*head,st;
};
Information::Information()
{cout<<" ******************************************************************************\n";
cout<<" ------------------------<<欢迎您使用学生成绩管理系统>>------------------------\n";
cout<<" ******************************************************************************\n\n";
}
Information::~Information()
{ cout<<" ******************************************************************************\n";
cout<<" ------------------------<<谢谢您使用学生成绩管理系统>>------------------------\n";
cout<<" ******************************************************************************\n";
}
//------------>建立链表函数
student *Information::creat(void)
{//定义一个指向struct student的结构体指针函数*creat()用来增加考生信息.
char ch[Q];n=0; //用来存放姓名的
p1=p2=(student *)malloc(LEN);//调用malloc()函数用来开辟一个新的存储单元
cout<<" -------------<<请建立学生考试信息表,在姓名处键以 ! 结束输入。>>--------------"<<endl;
cout<<" 姓名:";
cin>>ch;
head=NULL; //给指针head赋初值
while (strcmp(ch,"!")!=0)
{//调用字符比较函数strcmp()用来判断是否继续输入
p1=(student *)malloc(LEN);//调用malloc()函数用来开辟一个新的存储单元
strcpy(p1->name,ch); //将循环结构前面输入的姓名复制到结构体名为p1的数组name中
cout<<" 性别:";
cin>>p1->sex;
cout<<" 准考证号(8位):";
cin>>p1->id;
while(cin.fail())
{
cout<<" 对不起您的输入错误,请输入一个正整数: ";
cin.clear();
cin.sync();
cin>>p1->id;
}
cout<<" 数学成绩:";
cin>>p1->score[0];
while(cin.fail())
{
cout<<" 对不起您的输入错误,请输入一个正整数: ";
cin.clear();
cin.sync();
cin>>p1->score[0];
}
cout<<" 物理成绩:";
cin>>p1->score[1];
while(cin.fail())
{
cout<<" 对不起您的输入错误,请输入一个正整数: ";
cin.clear();
cin.sync();
cin>>p1->score[1];
}

cout<<" 英语成绩:";
cin>>p1->score[2];
while(cin.fail())
{
cout<<" 对不起您的输入错误,请输入一个正整数: ";
cin.clear();
cin.sync();
cin>>p1->score[2];
}

cout<<" C语言成绩:";
cin>>p1->score[3];
while(cin.fail())
{
cout<<" 对不起您的输入错误,请输入一个正整数: ";
cin.clear();
cin.sync();
cin>>p1->score[3];
}

p1->total=p1->score[0]+p1->score[1]+p1->score[2]+p1->score[3];//计算总分
if(n==0)head=p1;//如果是输入第一组学生考试信息就将指针p1赋给指针head
else p2->next=p1;//否则将p1赋给p2所指结构体的next指针
p2=p1;//将指针p1赋给指针p2
n++; //将n的值加1
cout<<" 姓名:";
cin>>ch;//将输入的姓名存放到字符数组ch中
}
p2->next=NULL;//将p2所指结构体的next指针重新赋空值
return (head);//将输入的第一组学生考试信息返回
}
//--------------->定义output()函数将考生的信息从头指针所指内容开始输出
void Information::output(student *head)
{

if(head==NULL) cout<<" 这是一个空表,请先输入考生成绩.\n";
else{
cout<<"-------------------------------------------------------------------------------\n";
cout<<" *学生考试成绩信息表*\n";
cout<<"-------------------------------------------------------------------------------\n";
cout<<"准考证号 姓 名 性别 数学 物理 英语 C++ 平均分 总分\n";
cout<<"-------------------------------------------------------------------------------\n";
p1=head;//将头指针赋给p
do
{
cout<<setw(8)<<p1->id
<<setw(9)<<p1->name
<<setw(8)<<p1->sex
<<setw(8)<<p1->score[0]
<<setw(9)<<p1->score[1]
<<setw(9)<<p1->score[2]
<<setw(9)<<p1->score[3]
<<setw(9)<<p1->total/4.0
<<setw(9)<<p1->total<<endl;
cout<<"-------------------------------------------------------------------------------\n";
p1=p1->next;//将下一组考生信息的next指针赋给p
}while(p1!=NULL);//若指针p非空则继续,目的是把所有的考生信息都传给指针p然后输出.
}
}
//------------>统计学生人数的函数
int Information::count(struct student *head)//定义函数count()统计考生总数
{
if(head==NULL)return(0);//若指针head为空返回值为0
else return(1+count(head->next));//函数的递归调用
}
//----------->插入学生的成绩的函数
student *Information::insert( student *head)
//插入新结点定义一个指向struct student的结构体指针函数*insert()用来添加考生信息.
{

cout<<"\t----------------<<请输入新增学生成绩信息>>----------------\n"<<endl;
p1=(student *)malloc(LEN); //使p1指向插入的新结点
cout<<" 准考证号(8位):";
cin>>p1->id;
while(cin.fail())
{
cout<<" 对不起您的输入错误,请输入一个正整数: ";
cin.clear();
cin.sync();
cin>>p1->id; //将输入的准考证号存放到p1所指结构体的数组id中
}
cout<<" 姓名:";
cin>>p1->name; //将输入的姓名存放到结构体名为p1的数组name中
cout<<" 性别:";
cin>>p1->sex;
cout<<" 数学成绩:";
cin>>p1->score[0];
while(cin.fail())
{
cout<<" 对不起您的输入错误,请输入一个正整数: ";
cin.clear();
cin.sync();
cin>>p1->score[0];//将输入的数学成绩存放到p1所指结构体的数组score中
}

cout<<" 物理成绩:";
cin>>p1->score[1];
while(cin.fail())
{
cout<<" 对不起您的输入错误,请输入一个正整数: ";
cin.clear();
cin.sync();
cin>>p1->score[1];//将输入的物理成绩存放到p1所指结构体的数组score中
}

cout<<" 英语成绩:";
cin>>p1->score[2];
while(cin.fail())
{
cout<<" 对不起您的输入错误,请输入一个正整数: ";
cin.clear();
cin.sync();
cin>>p1->score[2];//将输入的英语成绩存放到p1所指结构体的数组score中
}
cout<<" C语言成绩:";
cin>>p1->score[3];
while(cin.fail())
{
cout<<" 对不起您的输入错误,请输入一个正整数: ";
cin.clear();
cin.sync();
cin>>p1->score[3];//将输入的C语言成绩存放到p1所指结构体的数组score中
}
p1->total=p1->score[0]+p1->score[1]+p1->score[2]+p1->score[3];//计算总分
p2=head;//将头指针赋给p2
if(head==NULL) //若没调用次函数以前的头指针head为空
{
head=p1;p1->next=NULL;
}//则将p1赋给头指针head并将p1所指结构体成员指针next赋空值
else
{
while((p1->id>p2->id)&&(p2->next!=NULL))
{
p3=p2;//p3指向原p2指向的结点
p2=p2->next;
}//p2后移一个结点
if(p1->id<=p2->id)
{
if(head==p2)
{
p1->next=head;
head=p1;
} //插入到第一个结点之前
else
{
p3->next=p1;
p1->next=p2;
} //插入到p3所指结点之后
}
else
{
p2->next=p1;
p1->next=NULL;
} //插入到尾结点之后
}
n++;//将学生人数加1
cout<<"\t----------------<<你输入的学生信息已经成功插入>>----------------"<<endl;
return (head);
}
//------------>删除函数
student *Information::cancel(student *head,long int num)//定义一个指向struct student的结构体指针函数*delete()用来删除考生信息.
{

if(head==NULL)//若调用次函数以前的头指针head为空
{
return(head);
}
else
{
p1=head;//否则将头指针赋给p1
while(num!=p1->id&&p1->next!=NULL)//寻找要删除的结点当p1所指的学生准考证号不是输入的学生准考证号并且p1所指的next指针不为空
{
p2=p1;
p1=p1->next;
}//p2指向原p1指向的结点p1后移一个结点
if(num==p1->id)//如果输入的学生准考证号是p1所指的学生准考证号//结点找到后删除
{
if(p1==head) head=p1->next;//如果head指针和p1指针相等则将下一个结点赋给指针head
else
p2->next=p1->next;//否则将p1所指结点赋给p2所指结点将要删除的学生信息跳过去
cout<<" 删除准考证号为"<<num<<"的学生\n";
n--;//将学生人数减1
}
return(head);//将头指针返回
}
}
//------------>查找函数
student *Information::find(student *head,long int num)
//定义一个指向struct student的结构体指针函数*find()用来查找考生信息.
{

if(head==NULL)//若调用次函数以前的头指针head为空
{
cout<<" 这是一个空表,请先输入考生成绩.\n";
return(head);
}
else
{
p1=head;//否则将头指针赋给p1
while(num!=p1->id&&p1->next!=NULL)
//寻找结点当p1所指的学生准考证号不是输入的学生准考证号并且p1所指的next指针不为空
{
p1=p1->next;
}//p2指向原p1指向的结点p1后移一个结点
if(num==p1->id)//如果要查找的学生准考证号是p1所指的学生准考证号
{
cout<<"------------------------------------------------------------------------------\n";
cout<<"准考证号 姓 名 性别 数学 物理 英语 C++ 平均分 总分 \n";
cout<<"------------------------------------------------------------------------------\n";
cout<<setw(8)<<p1->id
<<setw(9)<<p1->name
<<setw(6)<<p1->sex
<<setw(7)<<p1->score[0]
<<setw(7)<<p1->score[1]
<<setw(7)<<p1->score[2]
<<setw(7)<<p1->score[3]
<<setw(10)<<p1->total/4.0
<<setw(7)<<p1->total<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
else
cout<<" 没找到准考证号为"<<num<<"的学生.\n"; //结点没找到
return(head);
}
}
//------------定义paixu()函数将考生的总分从大到小排列并输出
void Information::paixu(student *head)
{
int i,k,m=0,j;
student *p[Q];//定义一个指向struct student的结构体指针数组p
if(head!=NULL)//如果头指针是空则继续
{ m=count(head);
cout<<"------------------------------------------------------------------------------\n";
cout<<" *学生考试成绩统计表*\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<"准考证号 姓 名 性别 数学 物理 英语 C++ 平均分 总分 名次\n";
cout<<"------------------------------------------------------------------------------\n";
p1=head;
for(k=0;k<m;k++)
{
p[k]=p1;
p1=p1->next;
}
for(k=0;k<m-1;k++) //选择排序法
for(j=k+1;j<m;j++)
if(p[k]->total<p[j]->total)
{
p2=p[k];
p[k]=p[j];
p[j]=p2;
} //从大到小排列的指针
for(i=0;i<m;i++)
{
cout<<setw(8)<<p[i]->id
<<setw(9)<<p[i]->name
<<setw(6)<<p[i]->sex
<<setw(7)<<p[i]->score[0]
<<setw(7)<<p[i]->score[1]
<<setw(7)<<p[i]->score[2]
<<setw(7)<<p[i]->score[3]
<<setw(8)<<p[i]->total/4.0
<<setw(7)<<p[i]->total
<<setw(9)<<i+1<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
}
}
//------------>求各科平均分成绩的函数
void Information::average(student *head)
{

int k,m;
float arg1=0,arg2=0,arg3=0,arg4=0;
if(head==NULL)//如果头指针是空则继续
{
cout<<" 这是一个空表,请先输入考生成绩.\n";
}
else
{
m=count(head);
p1=head;
for(k=0;k<m;k++)
{
arg1+=p1->score[0];
arg2+=p1->score[1];
arg3+=p1->score[2];
arg4+=p1->score[3];
p1=p1->next;
}
arg1/=m;arg2/=m;arg3/=m;arg4/=m;
cout<<" *全班单科成绩平均分*\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<" 数学平均分:"<<setw(7)<<arg1
<<" 物理平均分:"<<setw(7)<<arg2
<<" 英语平均分:"<<setw(7)<<arg3
<<" C语言平均分:"<<setw(7)<<arg4<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
}


♂ 死后定当长眠,生前何须久睡。♀
2006-07-06 22:39
快速回复:花了两个星期编好的学生成绩管理程序-->feng1256转移
数据加载中...
 
   



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

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