?? 11_3.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 + -