如何解决需要帮助解决 C++ 问题中的继承问题
我有一个关于继承的 C++ 问题:
编写一个程序,该程序具有一个带有数据成员seats_first_class、seats_second_class 和seats_ac_2tier 的类Train 以及用于设置和显示数据的成员函数。 派生一个类 Reservation,它具有数据成员 booked_first_class、booked_second_class 和 booked_ac_2tier,并具有预订和取消门票和显示状态的功能。
这是我写的代码
https://onlinegdb.com/CTAdFBM_C
#include <iostream>
using namespace std;
class Train
{
protected :
int seats_first_class,seats_second_class,seats_ac_2tier;
public :
//Train(int a,int b,int c) : seats_first_class(a),seats_second_class(b),seats_ac_2tier(c){}
//Train() : seats_first_class(0),seats_second_class(0),seats_ac_2tier(0){}
void Read()
{
cout<<"Enter the seats in 1st class..."; cin>>seats_first_class; cout<<endl;
cout<<"Enter the seats in 2nd class..."; cin>>seats_second_class; cout<<endl;
cout<<"Enter the seats in AC 2 tier..."; cin>>seats_ac_2tier; cout<<endl;
}
void Disp()
{
cout<<"The number of seats in booked by you in 1st class are "<<seats_first_class<<endl;
cout<<"The number of seats in booked by you in 2nd class are "<<seats_second_class<<endl;
cout<<"The number of seats in booked by you in AC 2 tier class are "<<seats_ac_2tier<<endl;
}
};
class Reservation : public Train
{
protected :
bool booked_first_class=0,booked_second_class=0,booked_ac_2tier=0;
public :
bool evaluvate_seat()
{
char ch;
cout<<"Have you booked tickets for 1st class\n"; cin>>ch;
if(ch='y')
return booked_first_class=true;
cout<<"Have you booked tickets for 2nd class\n"; cin>>ch;
if(ch='y')
return booked_second_class=true;
cout<<"Have you booked tickets for AC 2 tier\n"; cin>>ch;
if(ch='y')
return booked_ac_2tier=true;
}
void status_disp(bool a)
{
if(a==true)
cout<<"Status : Reserved"<<endl;
else
cout<<"Status : Not Reserved"<<endl;
}
void cancel_seat()
{
int n;
cout<<"Enter the the type of compartment you want to delete\n"; cin>>n;
switch(n)
{
case 1:
cout<<"Cancelling your ticket in 1st class"<<endl;
booked_first_class=false;
break;
case 2:
cout<<"Cancelling your ticket in 2nd class"<<endl;
booked_second_class=false;
break;
case 3:
cout<<"Cancelling your ticket in AC 2 tier class"<<endl;
booked_ac_2tier=false;
break;
}
}
};
int main()
{
Reservation r1,r2;//Train t1,t2;
r1.Read(); r2.Read();
r1.Disp(); r2.Disp();
r1.evaluvate_seat(); r1.status_disp(Resevation :: evaluvate_seat());
r2.cancel_seat(); r2.status_disp(Resevation :: evaluvate_seat());
return 0;
}
这些是我面临的错误:
main.cpp:76:38: error: ‘Resevation’ has not been declared
r1.evaluvate_seat(); r1.status_disp(Resevation :: evaluvate_seat());
^~~~~~~~~~
main.cpp:77:35: error: ‘Resevation’ has not been declared
r2.cancel_seat(); r2.status_disp(Resevation :: evaluvate_seat());
编辑: 我试图纠正一些错误,但仍然没有成功使代码无错误。任何人的帮助都是非常可观的
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。