📄 大作业1.cpp
字号:
shuttlecock::shuttlecock(char*str1,char*str2,char* n):ball(str1,str2,n)
{number9++;}
void shuttlecock::print()const
{
physical_culture_chooser::print();
cout<<setw(15)<<"shuttlecock\n";
cout<<"the place of class:"<<setw(15)<<"the floor of A1.";
}
//子类3-5
class badmintoon:virtual public ball
{public:
badmintoon(char*,char*,char* );
~badmintoon(){}
virtual void print()const;
static int outnumber10() {return number10;};
private:
static int number10;
};
int badmintoon::number10=0;
badmintoon::badmintoon(char*str1,char*str2,char* n):ball(str1,str2,n)
{number10++;}
void badmintoon::print()const
{
physical_culture_chooser::print();
cout<<setw(15)<<"badmintoon\n";
cout<<"the place of class:"<<setw(15)<<"the floor of A1.";
}
//子类3-6
class volleyball:virtual public ball
{public:
volleyball(char*,char*,char* );
~volleyball(){}
virtual void print()const;
static int outnumber11() {return number11;};
private:
static int number11;
};
int volleyball::number11=0;
volleyball::volleyball(char*str1,char*str2,char* n):ball(str1,str2,n)
{number11++;}
void volleyball::print()const
{
physical_culture_chooser::print();
cout<<setw(15)<<"volleyball\n";
cout<<"the place of class:"<<setw(15)<<"volleyball_ground";
}
struct node
{
physical_culture_chooser *data;
node *next;
};
//建立相应的模板
template <typename lesson>
void add_students(lesson *t,node * &f,node* &r,char*institute,char*name,char* n)
{
node *p=new node;
p->data=new lesson(institute,name,n);
p->next=NULL;
if(f==NULL)
f=r=p;
else
{
r->next=p;
r=r->next;
}
}
char *choose_institute()
{
char *str=new char;
char z;
cout<<setw(45)<<"请选择你所在的学院:"<<endl;
cout<<"A. software engineering"<<'\t'<<'\t'<<"B. law of school"<<endl;
cout<<"C. electronic commerce"<<'\t'<<'\t'<<"D. economy and trade of school"<<endl;
cout<<"E. art of school"<<'\t'<<'\t'<<"F. tour manage of school"<<endl;
cout<<"Choose Institute:";
here:cin>>z;
if(z=='a' || z=='A')
str="Software_Engineering";
else if(z=='b' || z=='B')
str="Law_of_School";
else if(z=='c' || z=='C')
str="Electronic_Commerce";
else if(z=='d' || z=='D')
str="Economy_and_Trade_of_School";
else if(z=='e' || z=='E')
str="Art_of_School";
else if(z=='f' || z=='F')
str="Tour_Manage_of_School";
else
{cout<<"input error!Please chooose again."<<endl;
goto here;}
return (str);
}
void main()
{
char a;
char *n=new char;
char *institute=new char;
char *name=new char;
node* f=NULL,* r=NULL;
ofstream outfile;
fstream F;
F.open("Cross_country_Directional.txt",ios::in | ios::out);
Cross_country_Directional *t1=NULL;
while(F>>institute>>name>>n)
{
add_students(t1,f,r,institute,name,n);
}
F.close();
F.open("radio_direction_finder.txt",ios::in | ios::out);
radio_direction_finder *t2=NULL;
while(F>>institute>>name>>n)
{
add_students(t2,f,r,institute,name,n);
}
F.close();
F.open("sociality_dancing.txt",ios::in | ios::out);
sociality_dancing *t3=NULL;
while(F>>institute>>name>>n)
{
add_students(t3,f,r,institute,name,n);
}
F.close();
F.open("physical_dancing.txt",ios::in | ios::out);
physical_dancing *t4=NULL;
while(F>>institute>>name>>n)
{
add_students(t4,f,r,institute,name,n);
}
F.close();
F.open("gym.txt",ios::in | ios::out);
gym *t5=NULL;
while(F>>institute>>name>>n)
{
add_students(t5,f,r,institute,name,n);
}
F.close();
F.open("table_tennis.txt",ios::in | ios::out);
table_tennis *t6=NULL;
while(F>>institute>>name>>n)
{
add_students(t6,f,r,institute,name,n);
}
F.close();
F.open("football.txt",ios::in | ios::out);
football *t7=NULL;
while(F>>institute>>name>>n)
{
add_students(t7,f,r,institute,name,n);
}
F.close();
F.open("basketball.txt",ios::in | ios::out);
basketball *t8=NULL;
while(F>>institute>>name>>n)
{
add_students(t8,f,r,institute,name,n);
}
F.close();
F.open("shuttlecock.txt",ios::in | ios::out);
shuttlecock *t9=NULL;
while(F>>institute>>name>>n)
{
add_students(t9,f,r,institute,name,n);
}
F.close();
F.open("badmintoon.txt",ios::in | ios::out);
badmintoon *t10=NULL;
while(F>>institute>>name>>n)
{
add_students(t10,f,r,institute,name,n);
}
F.close();
F.open("volleyball.txt",ios::in | ios::out);
volleyball *t11=NULL;
while(F>>institute>>name>>n)
{
add_students(t11,f,r,institute,name,n);
}
F.close();
char *n2=new char;
cout<<setw(49)<<setfill('*')<<"欢迎进入课程选择系统!"<<setw(32)<<setfill('*')<<endl;
cout<<setfill('\0')<<"请输入学生证号:"<<endl;
cin>>n2;
node *temp=f;
bool found=false;
while(temp && !found)
{
if(temp->data->num==n2)
{
found=true;
}
temp=temp->next;
}
if(found==false)
{
cout<<"请输入姓名:"<<endl;
cin>>name;
institute=choose_institute();
cout<<endl;
cout<<"请选择选报的项目:"<<endl;
cout<<"(1)Cross country Directional"<<'\t'<<'\t'<<setw(10)<<"已报人数:"<<Cross_country_Directional::outnumber1()<<endl;
cout<<"(2)radio direction finder"<<'\t'<<'\t'<<setw(10)<<"已报人数:"<<radio_direction_finder::outnumber2()<<endl;
cout<<"(3)sociality dancing"<<'\t'<<'\t'<<'\t'<<setw(10)<<"已报人数:"<<sociality_dancing::outnumber3()<<endl;
cout<<"(4)physical dancing"<<'\t'<<'\t'<<'\t'<<setw(10)<<"已报人数:"<<physical_dancing::outnumber4()<<endl;
cout<<"(5)gym"<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<setw(10)<<"已报人数:"<<gym::outnumber5()<<endl;
cout<<"(6)table tennis"<<'\t'<<'\t'<<'\t'<<'\t'<<setw(10)<<"已报人数:"<<table_tennis::outnumber6()<<endl;
cout<<"(7)football"<<'\t'<<'\t'<<'\t'<<'\t'<<setw(10)<<"已报人数:"<<football::outnumber7()<<endl;
cout<<"(8)basketball"<<'\t'<<'\t'<<'\t'<<'\t'<<setw(10)<<"已报人数:"<<basketball::outnumber8()<<endl;
cout<<"(9)shuttlecock"<<'\t'<<'\t'<<'\t'<<'\t'<<setw(10)<<"已报人数:"<<shuttlecock::outnumber9()<<endl;
cout<<"(a)badmintoon"<<'\t'<<'\t'<<'\t'<<'\t'<<setw(10)<<"已报人数:"<<badmintoon::outnumber10()<<endl;
cout<<"(b)volleyball"<<'\t'<<'\t'<<'\t'<<'\t'<<setw(10)<<"已报人数:"<<volleyball::outnumber11()<<endl;
cin>>a;
switch(a)
{
case '1':
{
add_students(t1,f,r,institute,name,n2);
F.open("Cross_country_Directional.txt",ios::out | ios::ate);
F<<institute<<'\t'<<name<<'\t'<<n2<<'\n';
F.close();
Cross_country_Directional b(institute,name,n2);b.print();
break;
}
case '2':
{
add_students(t2,f,r,institute,name,n2);
outfile.open("radio_direction_finder.txt",ios::out | ios::ate);
outfile<<institute<<'\t'<<name<<'\t'<<n2<<'\n';
outfile.close();
radio_direction_finder b(institute,name,n2);b.print();
break;
}
case '3':
{
add_students(t3,f,r,institute,name,n2);
outfile.open("sociality_dancing.txt",ios::ate);
outfile<<institute<<'\t'<<name<<'\t'<<n2<<'\n';
outfile.close();
sociality_dancing b(institute,name,n2);b.print();
break;
}
case '4':
{
add_students(t4,f,r,institute,name,n2);
outfile.open("physical_dancing.txt",ios::ate);
outfile<<institute<<'\t'<<name<<'\t'<<n2<<'\n';
outfile.close();
physical_dancing b(institute,name,n2);b.print();
break;
}
case '5':
{
add_students(t5,f,r,institute,name,n2);
outfile.open("gym.txt",ios::ate);
outfile<<institute<<'\t'<<name<<'\t'<<n2<<'\n';
outfile.close();
gym b(institute,name,n2);b.print();
break;
}
case '6':
{
add_students(t6,f,r,institute,name,n2);
outfile.open("table_tennis.txt",ios::ate);
outfile<<institute<<'\t'<<name<<'\t'<<n2<<'\n';
outfile.close();
table_tennis b(institute,name,n2);b.print();
break;
}
case '7':
{
add_students(t7,f,r,institute,name,n2);
outfile.open("football.txt",ios::ate);
outfile<<institute<<'\t'<<name<<'\t'<<n2<<'\n';
outfile.close();
football b(institute,name,n2);b.print();
break;
}
case '8':
{
add_students(t8,f,r,institute,name,n2);
outfile.open("basketball.txt",ios::ate);
outfile<<institute<<'\t'<<name<<'\t'<<n2<<'\n';
outfile.close();
basketball b(institute,name,n2);b.print();
break;
}
case '9':
{
add_students(t9,f,r,institute,name,n2);
outfile.open("shuttlecock.txt",ios::ate);
outfile<<institute<<'\t'<<name<<'\t'<<n2<<'\n';
outfile.close();
shuttlecock b(institute,name,n2);b.print();
break;
}
case 'a':
{
add_students(t10,f,r,institute,name,n2);
outfile.open("badmintoon.txt",ios::ate);
outfile<<institute<<'\t'<<name<<'\t'<<n2<<'\n';
outfile.close();
badmintoon b(institute,name,n2);b.print();
break;
}
case 'b':
{
add_students(t11,f,r,institute,name,n2);
outfile.open("volleyball.txt",ios::ate);
outfile<<institute<<'\t'<<name<<'\t'<<n2<<'\n';
outfile.close();
volleyball b(institute,name,n2);b.print();
break;
}
default :cout<<"Input error!"<<'\n';
}
}
else
cout<<"你已经报了!"<<'\n';
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -