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

📄 function.cpp

📁 《游戏编程指南》这是一本很好的游戏开发指导教材,并且附有源代码
💻 CPP
字号:
#include <iostream>
   	using namespace std;

float pi=3.14159;

float s_circle(float r);
float v_cylinder(float r, float h);
float v_cone(float r, float h);
float v_all(float stop, float smiddle, float sbottom,float h);

float v_all(float stop, float smiddle, float sbottom,float h)
{
	return (stop+4*smiddle+sbottom)*h/6;
}

float v_cone(float r, float h)
{
	return s_circle(r)*h/3;
}

float v_cylinder(float r, float h)
{
	return s_circle(r)*h;
}
	
float s_circle(float r)
{
	return pi*r*r;
}
	
void main( )
{
	float r,h;
	float st,sm,sb;
	cout<<"这个十分无趣的程序会帮您计算一些几何体的体积"<<endl;
	cout<<endl<<"0代表要计算圆锥体"<<endl;
	cout<<"1代表要计算圆柱体"<<endl;
	cout<<"2代表要计算拟柱体"<<endl;
	cout<<"请选择:";
	int choice;
	cin>>choice;
	cout<<endl;
	switch(choice)
	{
	case 0:
		cout<<"底面半径=?";
		cin>>r;
		cout<<"高=?";
			cin>>h;
		cout<<endl<<"体积="<<v_cone(r,h)<<endl;
			break;
	case 1:
		cout<<"底面半径=?";
		cin>>r;
			cout<<"高=?";
		cin>>h;
			cout<<endl<<"体积="<<v_cylinder(r,h)<<endl;
		break;
		case 2:
			cout<<"上表面的面积=?";
		cin>>st;
		cout<<"中截面的面积=?";
			cin>>sm;
		cout<<"下表面的面积=?";
			cin>>sb;
		cout<<"高=?";
		cin>>h;
		cout<<endl<<"体积="<<v_all(st,sm,sb,h)<<endl;
		break;
		}
}

⌨️ 快捷键说明

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