c01a.cpp

来自「此文件可以能帮你求体积」· C++ 代码 · 共 53 行

CPP
53
字号
// c01a.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <iostream.h>
#include <math.h>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

double Cylinder( double r, double h );
double Sphere( double r );
double Rectangle( double l, double w, double h );

int main(int argc, char* argv[])
{
	double radius, height;
	cout << "请输入圆柱体的半径和高:\n";
	cin >> radius >> height;
	double volume = Cylinder( radius, height );
	cout << "该圆柱体的体积为:" << volume << endl;

	cout << "请输入球半径:\n";
	cin >> radius;
	double areaOfSphere = Sphere( radius );
	cout << "该球面的面积为:" << areaOfSphere << endl;

	double length, width;
	cout << "请输入长方体的长、宽、高:\n";
	cin >> length >> width >> height;
	volume = Rectangle( length, width, height );
	cout << "该长方体的体积为:" << volume << endl;

	return 0;
}

double Cylinder( double r, double h )
{
	return r * r * M_PI * h;
}

double Sphere( double r )
{
	return 4 * r * r * M_PI;
}

double Rectangle( double l, double w, double h )
{
	return l * w * h;
}

⌨️ 快捷键说明

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