?? ?
字號(hào):
// 學(xué)生管理程序.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <string.h>
#include <process.h>
class Person
{
friend class Class;
private:
char *name;
char *sex;
int age;
public:
Person();
void setPerson(char *n1, char *n2, int a);
virtual ~Person();
virtual void print();
};
Person::Person()
{
name=new char[10];
sex=new char[10];
age=18;
}
void Person::setPerson(char *n1, char *n2, int a)
{
name =new char[strlen(n1)+1];
sex =new char[strlen(n2)+1];
strcpy(name,n1);
strcpy(sex,n2);
age=a;
}
Person::~Person()
{
delete []name;
delete []sex;
}
void Person::print()
{
cout<<"\n姓名:"<<name<<endl;
cout<<"性別:"<<sex<<endl;
cout<<"年齡:"<<age<<endl;
}
class Teacher: public Person
{
private:
char *post;
int classes;
public:
Teacher();
void setTeacher(char *n1, char *n2, char *n3, int a, int b);
virtual ~Teacher();
virtual void print();
};
Teacher::Teacher()
{
post=new char[10];
classes=0;
}
void Teacher::setTeacher(char *n1, char *n2, char *n3, int a,int b)
{
setPerson(n1, n2, a);
post =new char[strlen(n3)+1];
strcpy(post,n3);
classes=b;
}
Teacher::~Teacher()
{
delete []post;
}
void Teacher::print()
{
Person::print();
cout<<"職稱:"<<post<<endl;
}
class Student: public Person
{
friend Class;
private:
float math, phy, che;
static int totalStudent;
public:
Student();
setStudent(char *n1, char *n2, int a, float c1, float c2, float c3);
virtual ~Student();
void exchange(Student&,Student&);
static int getTotalStudent();
virtual void print();
};
int Student::totalStudent=0;
Student::Student()
{
math=0;
phy=0;
che=0;
totalStudent++;
}
Student::setStudent(char *n1, char *n2, int a, float c1, float c2, float c3)
{
setPerson(n1, n2, a);
math=c1;
phy=c2;
che=c3;
}
void Student::exchange(Student &a,Student &b)
{
Student temp;
temp.math=b.math;
b.math=a.math;
a.math=temp.math;
temp.phy=b.phy;
b.phy=a.phy;
a.phy=temp.phy;
temp.che=b.che;
b.che=a.che;
a.che=temp.che;
}
void Student::print()
{
Person::print();
cout<<"該生成績:"<<endl;
cout<<"數(shù)學(xué):"<<math;
cout<<"\t物理:"<<phy;
cout<<"\t化學(xué):"<<che<<endl;
}
Student::~Student()
{
totalStudent--;
}
int Student::getTotalStudent()
{
return totalStudent;
}
class Class
{
friend class Control;
public:
Class();
~Class();
void creatStu();
void showMath1();
void showMath2();
void showPhy1();
void showPhy2();
void showChe1();
void showChe2();
private:
int sum;
Student *stu;
int classnum;
static int totalClass;
};
int Class::totalClass=0;
void Class::creatStu()
{
totalClass++;
Student::totalStudent+=sum;
stu= new Student[sum];
for(int i=0;i<sum;i++)
{
char *n1=new char[10], *n2=new char[10];
int a;
float c1, c2, c3;
cout<<"\n請(qǐng)輸入第 "<<i+1<<"個(gè)學(xué)生的姓名:";
cin>>n1;
cout<<"請(qǐng)輸入性別:(男/女)";
cin>>n2;
bool flag=true;
while(flag==true)
{
if(strcmp(n2,"男")==0||strcmp(n2,"女")==0)
flag=false;
else
{
cout<<"請(qǐng)重新輸入性別:(男/女)";
cin>>n2;
}
}
cout<<"請(qǐng)輸入年齡:";
cin>>a;
cout<<"請(qǐng)輸入數(shù)學(xué)成績:";
cin>>c1;
cout<<"請(qǐng)輸入物理成績:";
cin>>c2;
cout<<"請(qǐng)輸入化學(xué)成績:";
cin>>c3;
stu[i].setStudent(n1, n2, a, c1, c2, c3);
}
}
Class::Class()
{
classnum=totalClass+1;
cout<<"\n請(qǐng)輸入 "<<classnum<<" 班的人數(shù):";
cin>>sum;
creatStu();
}
Class::~Class()
{
delete []stu;
totalClass--;
}
void Class::showMath1()
{
for(int i=0;i<sum;i++)
{
for(int j=i+1;j<sum;j++)
{
if(stu[i].math<stu[j].math)
stu[i].exchange(stu[i],stu[j]);
}
}
for(int k=0;k<sum;k++)
stu[k].print();
}
void Class::showMath2()
{
for(int i=0;i<sum;i++)
{
for(int j=i+1;j<sum;j++)
{
if(stu[i].math>stu[j].math)
stu[i].exchange(stu[i],stu[j]);
}
}
for(int k=0;k<sum;k++)
stu[k].print();
}
void Class::showPhy1()
{
for(int i=0;i<sum;i++)
{
for(int j=i+1;j<sum;j++)
{
if(stu[i].phy<stu[j].phy)
stu[i].exchange(stu[i],stu[j]);
}
stu[i].print();
}
}
void Class::showPhy2()
{
for(int i=0;i<sum;i++)
{
for(int j=i+1;j<sum;j++)
{
if(stu[i].phy>stu[j].phy)
stu[i].exchange(stu[i],stu[j]);
}
stu[i].print();
}
}
void Class::showChe1()
{
for(int i=0;i<sum;i++)
{
for(int j=i+1;j<sum;j++)
{
if(stu[i].che<stu[j].che)
stu[i].exchange(stu[i],stu[j]);
}
stu[i].print();
}
}
void Class::showChe2()
{
for(int i=0;i<sum;i++)
{
for(int j=i+1;j<sum;j++)
{
if(stu[i].che>stu[j].che)
stu[i].exchange(stu[i],stu[j]);
}
stu[i].print();
}
}
class Control
{
public:
void menu();
~Control();
void showInfo(Class);
private:
int classAll,teacAll;
Teacher *teac;
Student *stu;
Class *clas;
};
void Control::showInfo(Class classtemp)
{
stu=classtemp.stu;
for(int i=0;i<classtemp.sum;i++)
{
stu[i].print();
}
}
Control::~Control()
{
delete []stu;
delete []teac;
delete []clas;
}
void Control::menu()
{
label1:
cout<<"*************學(xué)生成績管理系統(tǒng)*****************"<<endl;
cout<<"1.創(chuàng)建"<<endl;
cout<<"2.查詢"<<endl;
cout<<"3.退出"<<endl;
int a;
cout<<"請(qǐng)選擇(1-3):";
cin>>a;
label2:
switch(a)
{
case 1:
cout<<"-----------------------"<<endl;
cout<<"1.輸入班級(jí)信息"<<endl;
cout<<"2.輸入老師信息"<<endl;
cout<<"3.放棄(返回上一層)"<<endl;
int b;
cout<<"請(qǐng)選擇(1-3):";
cin>>b;
switch(b)
{
case 1:
if(classAll>0)
cout<<"班級(jí)已經(jīng)創(chuàng)建!"<<endl;
else
{
cout<<"總共幾個(gè)班?";
cin>>classAll;
clas= new Class[classAll];
}
goto label2;
case 2:
if(teacAll>0)
cout<<"教師已經(jīng)創(chuàng)建!"<<endl;
else
{
cout<<"總共多少個(gè)教師?";
cin>>teacAll;
teac= new Teacher[teacAll];
for(int i=0;i<teacAll;i++)
{
char *n1=new char[10], *n2=new char[10], *n3=new char[10];
int a, b;
cout<<"\n請(qǐng)輸入第 "<<i+1<<"個(gè)老師的姓名:";
cin>>n1;
cout<<"請(qǐng)輸入性別:(男/女)";
cin>>n2;
bool flag=true;
while(flag==true)
{
if(strcmp(n2,"男")==0||strcmp(n2,"女")==0)
flag=false;
else
{
cout<<"請(qǐng)重新輸入性別:(男/女)";
cin>>n2;
}
}
cout<<"請(qǐng)輸入年齡:";
cin>>a;
cout<<"請(qǐng)輸入班級(jí):";
cin>>b;
cout<<"請(qǐng)輸入教師職稱:";
cin>>n3;
teac[i].setTeacher(n1, n2, n3, a, b);
}
}
goto label2;
case 3:
goto label1;
default:
cout<<"請(qǐng)按要求重新輸入!"<<endl;
goto label2;
}
case 2:
label3:
cout<<"-----------------------"<<endl;
cout<<"請(qǐng)輸入要查詢的內(nèi)容:"<<endl;
cout<<"1.老師信息(包含職稱)"<<endl;
cout<<"2.學(xué)生信息(包含成績)"<<endl;
cout<<"3.系統(tǒng)內(nèi)人員構(gòu)成"<<endl;
cout<<"4.放棄(返回上一層)"<<endl;
int d;
cout<<"請(qǐng)選擇(1-4):";
cin>>d;
switch(d)
{
case 1:
if(teacAll<0)
cout<<"\n老師尚未創(chuàng)建!"<<endl;
else
{
cout<<"老師:"<<endl;
for(int j=0;j<teacAll;j++)
teac[j].print();
cout<<"\n共有"<<teacAll<<"個(gè)老師。"<<endl;
}
goto label3;
case 2:
label4:
cout<<"-----------------------"<<endl;
cout<<"1.按各班數(shù)學(xué)成績從高到低排序"<<endl;
cout<<"2.按各班數(shù)學(xué)成績從低到高排序"<<endl;
cout<<"3.按各班物理成績從高到低排序"<<endl;
cout<<"4.按各班物理成績從低到高排序"<<endl;
cout<<"5.按各班化學(xué)成績從高到低排序"<<endl;
cout<<"6.按各班化學(xué)成績從低到高排序"<<endl;
cout<<"7.放棄(返回上一層)"<<endl;
int e;
cout<<"請(qǐng)選擇(1-7):";
cin>>e;
switch(e)
{
case 1:
if(classAll<0)
cout<<"\n學(xué)生尚未創(chuàng)建!"<<endl;
else
{
for(int i=0;i<classAll;i++)
{
cout<<"\n"<<i+1<<"班的學(xué)生:"<<endl;
clas[i].showMath1();;
}
}
goto label4;
case 2:
if(classAll<0)
cout<<"\n學(xué)生尚未創(chuàng)建!"<<endl;
else
{
for(int i=0;i<classAll;i++)
{
cout<<"\n"<<i+1<<"班的學(xué)生:"<<endl;
clas[i].showMath2();
}
}
goto label4;
case 3:
if(classAll<0)
cout<<"\n學(xué)生尚未創(chuàng)建!"<<endl;
else
{
for(int i=0;i<classAll;i++)
{
cout<<"\n"<<i+1<<"班的學(xué)生:"<<endl;
clas[i].showPhy1();
}
}
goto label4;
case 4:
if(classAll<0)
cout<<"\n學(xué)生尚未創(chuàng)建!"<<endl;
else
{
for(int i=0;i<classAll;i++)
{
cout<<"\n"<<i+1<<"班的學(xué)生:"<<endl;
clas[i].showPhy2();
}
}
goto label4;
case 5:
if(classAll<0)
cout<<"\n學(xué)生尚未創(chuàng)建!"<<endl;
else
{
for(int i=0;i<classAll;i++)
{
cout<<"\n"<<i+1<<"班的學(xué)生:"<<endl;
clas[i].showChe1();
}
}
goto label4;
case 6:
if(classAll<0)
cout<<"\n學(xué)生尚未創(chuàng)建!"<<endl;
else
{
for(int i=0;i<classAll;i++)
{
cout<<"\n"<<i+1<<"班的學(xué)生:"<<endl;
clas[i].showChe2();
}
}
goto label4;
case 7:
goto label3;
default:
cout<<"請(qǐng)按要求重新輸入!"<<endl;
goto label4;
}
case 3:
cout<<"-----------------------"<<endl;
if(classAll<0)
cout<<"\n學(xué)生尚未創(chuàng)建!"<<endl;
else
{
cout<<"\n共有"<<Student::getTotalStudent()/2<<"個(gè)學(xué)生。"<<endl;
cout<<"\n共有"<<classAll<<"個(gè)班級(jí)。"<<endl;
}
if(teacAll<0)
cout<<"\n老師尚未創(chuàng)建!"<<endl;
else
cout<<"\n共有"<<teacAll<<"個(gè)老師。"<<endl;
goto label3;
case 4:
goto label1;
default:
cout<<"請(qǐng)按要求重新輸入!"<<endl;
goto label3;
}
case 3:
exit(1);
default:
cout<<"請(qǐng)按要求重新輸入!"<<endl;
goto label1;
}
}
void main(int argc, char* argv[])
{
Control con;
con.menu();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -