prog13.cpp
来自「C++语言程序设计题典」· C++ 代码 · 共 81 行
CPP
81 行
#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 A;
A.getdata();
Price B("关山口","中山公园",32.6);
cout << "输出结果:" << endl;
A.disp();
B.disp();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?