#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <iostream>
#include <ctime>
#define max 100
/////////////////////////////////////
/////strcut stu
struct stu //学生资料结构体
{
char name[10];
int num;
char adress[10];
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,char *ch2,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;
}
void taxis(); //总分排序
void show(); //输出
};
void student::input(char *ch1,int num,char *ch2,float x,float y,float z)
{
strcpy(data[count].name,ch1);
data[count].num=num;
strcpy(data[count].adress,ch2);
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;
strcpy(data[count-1].adress,data[count].adress); 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].adress << "\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].adress << "\t"
<< data[count-1].x << "\t" << data[count-1].y << "\t"
<< data[count-1].z << endl;
}
/////////////////////
//main.cpp
void main()
{
student st;
char *ch1,*ch2,chose;
int num,find,del;
float x,y,z;
time_t t;
time(&t);
while(1)
{
system("cls");
cout << "------------------------学生管理系统------------------------" <<endl
<< " 当前系统时间是: " << ctime(&t) << endl
<< "1.输入/添加学生资料 2.输出学生资料 3.查找 4.删除 5.总分排序 6.退出" << endl << endl
<<" 请选择你要的服务(1-6)" << endl;
cin >> chose;
if(chose=='6') break;
switch(chose)
{
case '1':
{
cout << "姓名\t学号\t班级\t高数\t英语\t计算机成绩" << endl;
ch1=new char[]; ch2=new char[];
cin >> ch1 >> num;
while(st.check_num(num))
{
cout << "学号重复,请重新输入" << endl;
cin >> num;
}
cin >> ch2 >> x >> y >> z;
st.input(ch1,num,ch2,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();
}
~~我的明天我知道~~