C++程序出错,不能将参数 2 从"const char [5]"转换为"char"

#include<iostream>#include<string>usingnamespacestd;classschool{public:school(constst... #include <iostream>#include <string>using namespace std;class school{public: school(const string na,char se,int ag) {name=na;sex=se;age=ag;} void show() { cout<<"name"<<name<<endl; cout<<"sex:"<<sex<<endl; cout<<"age:"<<age<<endl; }protected: string name;char sex;int age;};class teacher:public school{public: teacher(const string na,char se,int ag,string ti,string co): school(na,se,ag) {title=ti;course=co;} void show() { cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; cout<<"age:"<<age<<endl; cout<<"title:"<<title<<endl; cout<<"course:"<<course<<endl; }protected: string course; string title; };class student:public school{public: student(const string na,char se,int ag,int num,string depa): school(na,se,ag) {number=num;department=depa;} student(string na,char se,int ag); void show() { cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; cout<<"age:"<<age<<endl; cout<<"number:"<<number<<endl; cout<<"department:"<<department<<endl; }protected: int number; string department;};class graduate:public student{public: graduate(const string na,char se,int ag,int num,string depa,string pro): student(na,se,ag),professor(pro){} void show() { cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; cout<<"age:"<<age<<endl; cout<<"number:"<<number<<endl; cout<<"department:"<<department<<endl; cout<<"professor:"<<professor<<endl; }private: string professor;};int main(){ cout<<" 欢迎您来到学生教室档案查询系统"<<endl; int a,i,j; school schoo('Leo',"male",20); student stud("Peter","male",21,3115007170,"Match"); teacher teach("Lily","female",36,"assistant","English"); graduate gradu("Amy","female",24,3212008929,"Match","Jhon"); cout<<endl;loop:cout<<"输入您要查找的对象:"<<endl<<endl<<"1.人员;2.学生;3.教师;4.研究生."<<endl; { cin>>a; if(a==1)schoo.show(); else if(a==2)stud.show(); else if(a==3)teach.show(); else gradu.show(); } cout<<"请问您还要继续查找吗?1.yes 2.no"<<endl; cin>>j; if(j==1)goto loop; else exit(0); return 0;} 展开
 我来答
White_MouseYBZ
2018-11-17 · TA获得超过4万个赞
知道大有可为答主
回答量:2.1万
采纳率:82%
帮助的人:6636万
展开全部
school schoo('Leo',"male",20);
student stud("Peter","male",21,3115007170,"Match");
teacher teach("Lily","female",36,"assistant","English");
graduate gradu("Amy","female",24,3212008929,"Match","Jhon");

以上4句明显与对应类的构造函数的形参类型不匹配,应该是:

school schoo("Leo",'m',20);///'Leo' "male"
student stud("Peter",'m',21,3115007170,"Match");///"male"
teacher teach("Lily",'f',36,"assistant","English");///"female"
graduate gradu("Amy",'f',24,3212008929,"Match","Jhon");///"female"

才对吧?没有看其他错误

mafangsan
2016-06-05 · TA获得超过1.2万个赞
知道大有可为答主
回答量:1万
采纳率:71%
帮助的人:2591万
展开全部
char [5]是存储一个字符串
char 是存一个字符

还有你贴的程序
school schoo('Leo',"male",20); 这个里面错误用了单引号,但是你那个图片不是单引号呢
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
我爱Xyy
2018-11-19 · TA获得超过280个赞
知道小有建树答主
回答量:508
采纳率:76%
帮助的人:124万
展开全部
teacher(const string na,char se,int ag,string ti,string co):
这个参数2改成string
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式