class Course
{
private:
string cno;
string cname;
string ccollege;
string cdepartment;
int cxuefen;
string coursetype;//基础数据
string cteachername;//任课教师生成//动态生成
string cbanhao;
string cclass;
int czxs;
int czhouci;
string time[2];
int allcapacity;
int sycapacity;
int pcj;
int qmcj;
int zzcj;
string see;//动态生成
//vector<Xuanke> cxk;
//int csno;//选课学生学号
vector<string> csnov;//选课学生列表
map<string,int>m;
public:
Course(string a,string b,string c,string d,int e,string f,string g="无",string h="无",string i="无",int j=0,int k=0,string l="无",string m="无",int n=50,int o=50,int p=0,int q=0,int r=0,string s="是");
Course(){}
string getcno(){return cno;}
void setcno(string a){cno=a;}
string getcname(){return cname;}
void setcname(string a){cname=a;}
string getccollege(){return ccollege;}
void setccollege(string a){ccollege=a;}
string getcdepartment(){return cdepartment;}
void setcdepartment(string a){cdepartment=a;}
int getcxuefen(){return cxuefen;}
void setcxuefen(int a){cxuefen=a;}
string getcoursetype(){return coursetype;}
void setcoursetype(string a){coursetype=a;}//
string getcteacher(){return cteachername;}
void setcteacher(string a){cteachername=a;}
string getcbanhao(){return cbanhao;}
void setcbanhao(string a){cbanhao=a;}
string getcclass(){return cclass;}
void setcclass(string a){cclass=a;}
int getczxs(){return czxs;}
void setczxs(int a){czxs=a;}
int getczhouci(){return czhouci;}
void setczhouci(int a){czhouci=a;}
string gettime1(){return time[0];}
void settime1(string a){time[0]=a;}
string gettime2(){return time[1];}
void settime2(string a){time[1]=a;}
int getallcapacity(){return allcapacity;}
void setallcapacity(int a){allcapacity=a;}
int getsycapacity(){return sycapacity;}
void setsycapacity(int a){sycapacity=a;}
int getpcj(){return pcj;}
void setpcj(int a){pcj=a;}
int getqmcj(){return qmcj;}
void setqmcj(int a){qmcj=a;}
int getzzcj(){return zzcj;}
void setzzcj(int a){zzcj=a;}
string getsee(){return see;}
void setsee(string a){see=a;}
/*string getkehao(int a){return cxk[a].kehao;}
string getbanhao(int a){return cxk[a].banhao;}
string getteachername(int a){return cxk[a].teachername;}
string gettime(int a){return cxk[a].time[2];}
int getzhouci(int a){return cxk[a].zhouci;}
int getqueren(int a){return cxk[a].queren;}*/
friend ostream&operator<<(ostream &os,Course &c);
friend istream&operator>>(istream &is,Course &c);
void cadd(string a);
void serase(int a);
};
Course::Course(string a,string b,string c,string d,int e,string f,string g,string h,string i,int j,int k,string l,string m,int n,int o,int p,int q,int r,string s):cno(a),cname(b),ccollege(c),cdepartment(d),cxuefen(e),coursetype(f)/*,cteachername(g),cbanhao(h),cclass(i),czxs(j),czhouci(k),time[0](l),time[1](m),allcapacity(n),sycapacity(o),pcj(p),qmcj(q),zzcj(r),see(s)*/
{
cteachername=g;
cbanhao=h;
cclass=i;
czxs=j;
czhouci=k;
time[0]=l;
time[1]=m;
allcapacity=n;
sycapacity=o;
pcj=p;
qmcj=q;
zzcj=r;
see=s;
}
/*
cteachername(g),cbanhao(h),cclass(i),czxs(j),czhouci(),;time[0](l),time[1](m),allcapacity(n),sycapacity(o),pcj(p),qmcj(q),zzcj(r),see(s)
cteachername=g;
cbanhao=h;
cclass=i;
czxs=j;
czhouci=k;
time[0]=l;
time[1]=m;
allcapacity=n;
sycapacity=o;
pcj=p;
qmcj=q;
zzcj=r;
see=s;*/
istream&operator>>(istream &is,Course &c)
{
is>>c.cno>>c.cname>>c.ccollege>>c.cdepartment>>c.cxuefen>>c.coursetype;
return is;
}
ostream&operator<<(ostream &os,Course &c)
{
vector<string>::iterator it;
os<<c.cno<<"\t"<<c.cname<<"\t"<<c.ccollege<<"\t"<<c.cdepartment<<"\t"<<c.cxuefen<<"\t"<<c.coursetype<<"\t";
os<<c.cteachername<<"\t"<<c.cbanhao<<"\t"<<c.cclass<<"\t"<<c.czxs<<"\t"<<c.czhouci<<"\t"<<c.time[0]<<c.time[1]<<"\t"<<c.allcapacity<<"\t"<<c.sycapacity<<"\t"<<c.pcj<<"\t"<<c.qmcj<<"\t"<<c.zzcj<<"\t"<<c.see<<"\t";
for(it=c.csnov.begin();it!=c.csnov.end();it++)
{
os<<*it;
}
return os;
}
void Course::cadd(string a)//学号
{
csnov.push_back(a);
m.insert(make_pair(a,csnov.size()-1));
}
/*void Course::serase(int a)//序号
{
map<string,int>::iterator cit;
vector<string>::iterator it=csnov.begin();
for(cit=m.begin();cit!=m.end();cit++)
{
if(cit->second==a)
{
int index=cit->second;
csnov.erase(it+index);
}
}
}*/
class Teachercaozuo
{
protected:
//Teacher teacher;
//vector<Xuanke2>txuanke;
vector<Course>tcourse;
//vector<Course>iterator::tcit;
map<string,int>tccollege;
map<string,int>tcdepartment;
map<string,int>tcname;
public:
Teachercaozuo(/*Teacher a*/)/*:teacher(a)*/{load();}
void search1(string a);
void search2(string a);
void search3(string a);
void reselect(string mingcheng,string banhao,string banji,string sj1,string sj2,int zc,/*string shi,*/int xs,string tname);
void load();
void save1();
//void save2();
~Teachercaozuo(){save1();}
};
void Teachercaozuo::load()
{
Course c;
ifstream infile("2018211179-course.txt");
if(!infile){cout<<0;};
while(!infile.eof())
{
infile>>c;
tcourse.push_back(c);
tccollege.insert(make_pair(c.getccollege(),tcourse.size()-1));
tcdepartment.insert(make_pair(c.getcdepartment(),tcourse.size()-1));
tcname.insert(make_pair(c.getcname(),tcourse.size()-1));
}
infile.close();
}
void Teachercaozuo::save1()
{
ofstream outfile;
if(!outfile){cout<<2;}
outfile.open("2018211179-course2.txt");
vector<Course>::iterator it;
for(it=tcourse.begin();it!=tcourse.end();it++)
{
outfile<<*it<<endl;
cout<<*it;
}
outfile.close();
}
void Teachercaozuo::search1(string a)//学院
{
map<string,int>::iterator it;
it=tccollege.find(a);
if(it==tccollege.end())
return;
else
{
cout<<tcourse[it->second]<<endl;
}
}
void Teachercaozuo::search2(string a)//专业
{
map<string,int>::iterator it;
it=tcdepartment.find(a);
if(it==tcdepartment.end())
return ;
else
{
cout<<tcourse[it->second]<<endl;
}
}
void Teachercaozuo::search3(string a)//名字
{
map<string,int>::iterator it;
it=tcname.find(a);
if(it==tcname.end())
return ;
else
{
cout<<tcourse[it->second]<<endl;
}
}
void Teachercaozuo::reselect(string mingcheng,string banhao,string banji,string sj1,string sj2,int zc,/*string shi,*/int xs,string tname)
{
string a,b,c,d,e,g;
int f;
map<string,int>::iterator it;
it=tcname.find(mingcheng);
if(it==tcname.end())
{
cout<<"输入选课名字没找到";
}
else
{
//cout<<tcourse[it->second]<<endl;//限制
//a=tcourse[it->second].getcno();
b=banhao;
c=banji;
d=sj1;
e=sj2;
f=zc;
//g=shi;
/*struct Xuanke2 xk2={a,b,c,{d,e},f,g};
teacher.tadd(xk2);
teacher.settnum(teacher.gettnum()+1);
teacher.setzxs(xs);*/
tcourse[it->second].setcteacher(tname);
tcourse[it->second].setcbanhao(b);
tcourse[it->second].setcclass(c);
tcourse[it->second].setczxs(xs);
tcourse[it->second].setczhouci(f);
tcourse[it->second].settime1(d);
tcourse[it->second].settime2(e);
tcourse[it->second].setsycapacity(tcourse[it->second].getsycapacity()-1);
}
}
就像这样 我course 类中构造函数的默认值(默认参数)编译输出后出现一堆数字 这是咋回事啊,用set函数修改一部分默认参数后到是正常了没出现数字