⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 11_3.cpp

📁 为C++学习者
💻 CPP
字号:
#include<iostream.h>
#include<string.h>
#define Max 20
class Station
{
protected:
	char from[Max];
	char to[Max];
public:
	Station()
	{
		strcpy(from,"");
		strcpy(to,"");
	}
	Station(char f[],char t[])
	{
		strcpy(from,f);
		strcpy(to,t);
	}
	void getdata()
	{
		cout<<"输入起始站	终点站:";
		cin>>from>>to;
	}
	void disp()
	{
		cout<<"从"<<from<<"站到"<<to<<"站";
	}
};
class Mile
{
protected:
	double mile;
public:
	Mile(){mile=0;}
	Mile(double m){mile=m;}
	void getdata()
	{
		cout<<"输入里程:";
		cin>>mile;
	}
	void disp()
	{
		cout<<"是"<<mile<<"公里";
	}
};
class Price:public Station,public Mile
{
	double price;
public:
	Price():Station(),Mile()
	{
		price=0;
	}
	Price(char f[],char t[],double m):Station(f,t),Mile(m)
	{
		price=8+(int)((m-3+0.49)*2)*0.7;
	}
	void getdata()
	{
		Station::getdata();
		Mile::getdata();
		price=8+(int)((mile-3+0.49)*2)*0.7;
	}
	void disp()
	{
		cout<<" ";
		Station::disp();
		Mile::disp();
		cout<<",价格是"<<price<<"元"<<endl;
	}
};
void main()
{
	Price p1;
	p1.getdata();
	Price p2("汽车西站","火车站",33.6);
	cout<<"输出结果为:"<<endl;
	p1.disp();
	p2.disp();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -