一个学生管理系统的程序
要求给这个程序增加计算:各科平均分和各科及格率的功能
有大侠有空帮小弟加几笔吗?谢谢!! 大热天啊,请吃
~~~~~~~~~~~~~~~~~~~在线等~~~~~~~~~~~~~~~~~~~~
程序如下:
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <iostream>
#define max 100
/////////////////////////////////////
/////strcut stu
struct stu //学生资料结构体
{
char name[10];
int num;
int sex; //男=0,女=1
float x,y,z,score;
int number;
};
//////////////////////////////////////////
///////student.cpp
int count=0;
int temp=0;
class student //学生类
{
private:
stu data[max];
char start_del;
public:
void input(char *ch1,int num,int sex,float x,float y,float z); //输入
void find(int num); //查找
void del(int num); //删除
int check_num(int num) //确定没有重复学号
{
int m=0;
while(m<=count)
if(num==data[m++].num)
break;
if(m>count)
return 0;
else
return 1;
}
int check_sex(int sex)
{
if(sex!=0 && sex!=1)
return 1;
else
return 0;
}
void taxis(); //总分排序
void show(); //输出
};
void student::input(char *ch1,int num,int sex,float x,float y,float z)
{
strcpy(data[count].name,ch1);
data[count].num=num;
data[count].sex=sex;
data[count].x=x; data[count].y=y; data[count].z=z;
count++;
}
void student::find(int num)
{
int m=0;
while(m<=count)
if(num==data[m++].num)
break;
if(m>count)
{
cout << "很抱歉,没有该学号的学生" << endl;
start_del='n';
getch();
}
else
{
temp=count; count=m; start_del='y';
cout << "该学生的资料为" <<endl
<< "序号\t姓名\t学号\t性别\t高数\t英语\t计算机" << endl;
show();
count=temp; getch();
}
}
void student::del(int num)
{
char chose;
find(num);
if(start_del=='y')
{
cout << "确实要删除该学生资料? Y/N" << endl;
cin >> chose;
if(chose=='y'||chose=='Y')
{
int m=0;
while(m<=count)
if(num==data[m++].num)
break;
temp=count; count=m;
while(count<temp)
{
strcpy(data[count-1].name,data[count].name); data[count-1].num=data[count].num;
data[count-1].sex=data[count].sex; data[count-1].x=data[count].x;
data[count-1].y=data[count].y; data[count-1].z=data[count].z;
count++;
}
count=temp-1;
cout << "该学生资料已删除" << endl;
}
else
cout << "学生资料未删除" << endl;
getch();
}
}
void student::taxis()
{
int x,y,array[max];
int change;
for(x=0;x<count;x++)
array[x]=data[x].score=data[x].x+data[x].y+data[x].z;
for(x=0;x<count-1;x++)
for(y=0;y<count-1-x;y++)
if(array[y]<array[y+1])
{
change=array[y];
array[y]=array[y+1];
array[y+1]=change;
}
cout << "总分\t姓名\t学号\t性别\t高数\t英语\t计算机" << endl;
for(x=0;x<count;x++)
for(y=0;y<count;y++)
if(array[x]==data[y].score)
{
cout << data[y].score << "\t" << data[y].name << "\t"
<< data[y].num << "\t" << data[y].sex << "\t"
<< data[y].x << "\t" << data[y].y << "\t"
<< data[y].z << endl;
}
getch();
}
void student::show()
{
cout << count << "\t" << data[count-1].name << "\t"
<< data[count-1].num << "\t" << data[count-1].sex << "\t"
<< data[count-1].x << "\t" << data[count-1].y << "\t"
<< data[count-1].z << endl;
}
/////////////////////
//main.cpp
void main()
{
student st;
char *ch1,chose;
int num,find,del,sex;
float x,y,z;
while(1)
{
system("cls");
cout << " ------------------------学生管理系统------------------------" <<endl
<< "1.输入学生资料 2.输出学生资料 3.查找 4.删除 5.总分排序 6.退出" << endl << endl;
cin >> chose;
if(chose=='6') break;
switch(chose)
{
case '1':
{
cout << "请输入学生姓名\t学号\t性别\t高数\t英语\t计算机成绩" << endl;
ch1=new char[];
cin >> ch1 >> num;
while(st.check_num(num))
{
cout << "学号重复,请重新输入" << endl;
cin >> num;
}
cin >> sex;
while(st.check_sex(sex))
{
cout << "性别错误,请重新输入" << endl;
cin>> sex;
}
cin>> x >> y >> z;
st.input(ch1,num,sex,x,y,z);
}break;
case '2':
{
temp=count; count=1;
cout << "序号\t姓名\t学号\t性别\t高数\t英语\t计算机" << endl;
while(count<=temp)
{
st.show(); count++;
}
count--; getch();
}break;
case '3':
{
cout << "请输入你要查找学生的学号" << endl;
cin >> find;
st.find(find);
}break;
case '4':
{
cout << "请输入你要删除的学生学号" << endl;
cin >> del;
st.del(del);
}break;
case '5':
{
st.taxis();
}break;
default:
{
cout << "输入错误!!!,请重新输入" << endl;
getch();
}
}
}
cout << "感谢你的使用\n" <<endl;
getch();
}
[此贴子已经被作者于2006-9-1 13:56:03编辑过]