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

📄 c55.cpp

📁 此文件可以能帮你求体积
💻 CPP
字号:
// c55.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream.h>


// --------------------------------------------------------------------------
// class Description
class Description
{
public:
	Description( char* info ) : information(info) {}
	
public:
	virtual void Print() { cout << endl << information << endl; }

private:
	char* information;
};

// --------------------------------------------------------------------------
// class Sphere
class Sphere : public Description
{
public:
	Sphere( char* info, float rad ) : Description(info), radius(rad) {}

public:
	void Print()
	{
		Description::Print();
		cout << "radius = " << radius << endl;
	}
	
private:
	float radius;
};

// --------------------------------------------------------------------------
// class Cube
class Cube : public Description
{
public:
	Cube( char* info, float edge ) : Description(info), edgeLength(edge) {}

public:
	void Print()
	{
		Description::Print();
		cout << "edge length = " << edgeLength << endl;
	}

private:
	float edgeLength;
};

// --------------------------------------------------------------------------
Sphere smallBall( "mini", 1.0 );
Sphere beachBall( "plastic", 24.0 );
Sphere planetoid( "moon", 24 );

Cube crystal( "carbon", 24 );
Cube ice( "party", 1.0 );
Cube box( "cardboad", 16.0 );

Description* shapes[] = { &smallBall, &beachBall, &planetoid, &crystal, &ice, &box };

// --------------------------------------------------------------------------
// entrance to main
int main(int argc, char* argv[])
{
	for ( int i = 0; i < sizeof( shapes ) / sizeof( shapes[0] ); ++i )
		shapes[i]->Print();

	cout << endl;
	return 0;
}

⌨️ 快捷键说明

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