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

📄 container.cpp

📁 一些C++的课件和实验源代码
💻 CPP
字号:
// container.cpp: 
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "container.h"

#include <iostream.h>

//////////////////////////////////////////////////////////////////////
// implementation of the container class.
//////////////////////////////////////////////////////////////////////

container::container(int id, int type)
{
	m_nID	= id;
	m_nType = type;
}

container::~container()
{

}

void container::Show()
{
	cout << "容器号: " << m_nID << endl;
	cout << "容器类型: ";
	switch(m_nType)
	{
	case 0:
		cout << "立方体" << endl;
		break;
	case 1:
		cout << "球体" << endl;
		break;
	case 2:
		cout << "圆柱体" << endl;
		break;
	default:
		break;
	}

	cout << "表面积: " << GetArea() << "\t\t容量: " << GetVolume() << endl;
	cout << endl;
}


//////////////////////////////////////////////////////////////////////
// implementation of the cube class.
//////////////////////////////////////////////////////////////////////
cube::cube(int id, int length):container(id, 0)
{
	m_nLength = length;
}

int cube::GetArea()
{
	return 6 * m_nLength * m_nLength;	
}

int cube::GetVolume()
{
	return m_nLength * m_nLength * m_nLength;
}



//////////////////////////////////////////////////////////////////////
// implementation of the sphere class.
//////////////////////////////////////////////////////////////////////
sphere::sphere(int id, int radius):container(id, 1)
{
	m_nRadius = radius;
}

int sphere::GetArea()
{
	return (int)(4 * 3.1416 * m_nRadius * m_nRadius);
}

int sphere::GetVolume()
{
	return (int)(4  * 3.1416 * m_nRadius * m_nRadius * m_nRadius / 3 );	
}



//////////////////////////////////////////////////////////////////////
// implementation of the cylinder class.
//////////////////////////////////////////////////////////////////////
cylinder::cylinder(int id, int radius, int height):container(id, 2)
{
	m_nRadius = radius;
	m_nHeight = height;
}

int cylinder::GetArea()
{
	return (int)(2 * 3.1416 * m_nRadius * (m_nHeight + m_nRadius));	
}

int cylinder::GetVolume()
{
	return (int)(3.1416 * m_nRadius * m_nRadius * m_nHeight);
}

⌨️ 快捷键说明

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