E0289问题,没有与参数列表匹配的构造函数

刚学继承,发现容易会出现小错误,例如如何完美的打出一个漂亮的代码,还有调试很久的小问题。

EG:

编写一个学生和教师数据输入和显示程序

编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班号和成绩,教师数据有编号、姓名、职称和部门。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

要求将编号、姓名输入和显示设计成一个类person,并作为学生数据操作类student和教师数据操作类teacher的基类。

#include <iostream>
#include <string>
using namespace std;
class person {
	string num;
	string name;
public:
	person(string nu, string na) {
		num = nu;
		name = na;
	}
	void set(string nu, string na) {
		num = nu;
		name = na;
	}
	void print()
	{
		cout << "编号:" << num << endl;
		cout << "姓名:" << name << endl;
	}
};
class student:public person{
private :
	string ban;
	double score;
	
public:
	student(string nu, string na,string ba, double sco):person(nu,na) {
		ban = ba;
		score = sco;
	}
	void sprint()
	{
		person::print();
        cout << "班号:" << ban << endl;
		cout << "成绩:" << score << endl;
	}
};
class teacher:protected person {
	string zhi;
	string bu;
	
public:
	teacher(string nu1, string na1, string n1, string n11) :person (nu1, na1)
	{
		zhi = n1;
		bu = n11;
	}
	void tprint()
	{
		print();
		cout << "职称:" << zhi << endl;
		cout << "成绩:" << bu << endl;
	}
};
int main()
{
	string num;
	string name;
	cout << "输入一个学生数据: " << endl;
	string ban;
	double score;
	
	cin >> num >> name >> ban >> score;
	student stu(num, name, ban, score);
	
	cout << "输入一个教师数据: " << endl;
	string ban1;
	string   score1;//参数定义有问题,会使整个传参过程无法进行,所以出现错误。及无与其对应的构造参数,例如我的问题是因为定义了一个double类型
	cin >> num >> name >> ban1 >> score1;
	teacher t(num, name, ban1, score1);
	cout << "显示一个学生数据: " << endl;
	stu.sprint();
	cout << "显示一个教师数据: " << endl;
	t.tprint();
	return 0;
}

这个类型的问题可能不止一个,慢慢攒起来吧!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值