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

📄 b_7_2.cpp

📁 C++应用教程原码,里面包含该书中有十三章内容的代码,详细具体
💻 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 + -