📄 b_7_2.cpp
字号:
#include "stdafx.h"
#include <iostream>
#include<iomanip>
#include <string>
using namespace std;
#define Max 20
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 f,string t,double tt)
:Destination(f,t),Time(tt)
{ }
void getprice()
{
price=(int)((time+5)/6)*0.06;
}
void disp()
{
cout<<"计费从"<<from<<"到"<<to;
cout<<", 通话时间是"<<time<<"秒";
cout<<", 话费是"<<price<<"元"<<endl;
}
};
void main()
{
telephone A;
A.getprice();
A.disp();
cout <<endl;
telephone B("AAA","BBB",123);
B.getprice();
B.disp();
cin.get(); cin.get(); //等待结束,以便调测程序,可以删除
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -