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

📄 c47.cpp

📁 《C++程序设计习题及解答》配套代码VC版
💻 CPP
字号:
// c47.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <iostream.h>

// -----------------------------------------------------------------
class Building
{
public:
	Building( int f, int r, double ft )
	{
		floors = f;
		rooms = r;
		footage = ft;
	}

	void Show()
	{
		cout << " floors: " << floors << endl;
		cout << " rooms: " << rooms << endl;
		cout << " total area: " << footage << endl;
	}

protected:
	int floors;
	int rooms;
	double footage;
};

// -----------------------------------------------------------------
class Housing : public Building
{
public:
	Housing( int f, int r, double ft, int bd, int bth ) : Building( f, r, ft )
	{
		bedrooms = bd;
		bathrooms = bth;
	}

	void Show()
	{
		cout << "\nHOUSING: \n";
		Building::Show();
		cout << " bedrooms: " << bedrooms << "\n";
		cout << " bathrooms: " << bathrooms << endl;
	}

private:
	int bedrooms;
	int bathrooms;
};

// -----------------------------------------------------------------
class OfficeBuilding : public Building
{
public:
	OfficeBuilding( int f, int r, double ft, int ph, int ex ) : Building( f, r, ft )
	{
		phones = ph;
		extinguishers = ex;
	}

	void Show()
	{
		cout << "\nOFFICEBUILDING: \n";
		Building::Show();
		cout << " phones: " << phones << endl;
		cout << " extinguishers: " << extinguishers << endl;
	}

private:
	int phones;
	int extinguishers;
};

// -----------------------------------------------------------------
int main(int argc, char* argv[])
{
	Housing hob( 5, 7, 140, 2, 2 );
	OfficeBuilding oob( 8, 12, 500, 12, 2 );

	hob.Show();
	oob.Show();

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -