例子:#include"stdafx.h"#include<iostream>#include<string>using namespace std;class Destination {protected: string from;string to;public: Destination() 展开
例子:#include"stdafx.h"#include<iostream>#include<string>using namespace std;class Destination {protected: string from;string to;public: Destination() { cout<<"输入发话地点,收话地点"; cin>>from>>to;} Destination(string f,string t):from(f),to(t) { }};class Time{private: float hour,minute,second;protected: double time;public: Time() { cout<<"输入通话时间(时 分 秒):";cin>>hour>>minute>>second;time=(double)(hour*3600+minute*60+second);} Time(double t) { time=t;}};class Telephone:public Destination,public Time{double price;public: Telephone() { price=0;} Telephone(string t,double tt):Destination(f,t),Time(tt){}void getprice(){ price=(int)((time+5)/6)*0.06;}void disp(){ cout<<"计费从"<<from<<"到"<<to<<end;cout<<"通话时间是"<<time<<"秒"<<endl;cout<<"话费是"<<price<<"元"<<endl;}};void main(){ Telephone A;A.getprice();A.disp();cout<<endl;Telephone B("AAA","BBB",123);B.getprice();A.disp();} 收起