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;}
展开
3个回答
展开全部
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"
才对吧?没有看其他错误
展开全部
char [5]是存储一个字符串
char 是存一个字符
还有你贴的程序
school schoo('Leo',"male",20); 这个里面错误用了单引号,但是你那个图片不是单引号呢
char 是存一个字符
还有你贴的程序
school schoo('Leo',"male",20); 这个里面错误用了单引号,但是你那个图片不是单引号呢
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
teacher(const string na,char se,int ag,string ti,string co):
这个参数2改成string
这个参数2改成string
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询