用c++解决一个数学问题-求阴影面积_c++


简单粗暴,直接上代码了

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char **argv)
{
cout << "c++ ,求阴影的面积有多大" << endl;

if (argc != 3) {
cout << "请输入长方体的长 宽" << endl;
return -1;
}

double length = strtod(argv[1], NULL);
double high = strtod(argv[2], NULL);

cout << "长方体长为:" << length << endl;
cout << "长方体高为:" << high << endl;

cout << "阴影面积 = (长方体长度 * 长方体宽度 - 两个圆的面积) / 8 * 3 + CDE围城的不规则面积" << endl;
cout << "CDE围成的不规则面积 = AED三角形面积 - AOC面积 - COE面积" << endl;
cout << "问题最后变成求r1角度, r1是三角形AED的顶角" << endl;

double FD = length /2;
double AO = length / 4;
double DE = high / 2;

double AD = 0.5 * sqrt(length * length + high * high);
cout << "AD边长度为:" << AD << endl;
cout << "sin r1=" << DE/AD << endl;
double OB = AO * DE / AD;
cout << "OB的长度为:" << OB << endl;
double AB = sqrt(AO * AO + OB + OB);
cout << "AB的长度为" << AB << endl;
double area_aoc = OB * AB;
cout << "三角形AOC的面积是:" << area_aoc << endl;

//cout << "下面使用反三角函数得出r1的角度" << endl;
//double hu_r1 = asin(DE/AD);
//cout << "r1角度为:" << hu_r1 << endl;

double radian, angle_OAB;
radian=asin(DE/AD);
angle_OAB=radian * 180 / 3.141592653;
cout << "r1角度是:" << angle_OAB << endl;
double angle_COE = 180 - 2 *(90 - angle_OAB);
cout << "角COE是:" << angle_COE << endl;
double area_COE = 3.141592653 * (high * high / 4) * angle_COE / 360;
cout << "扇形COE面积为:" << area_COE << endl;

double area_CDE = FD * DE / 2 - area_aoc - area_COE;
cout << "CDE面积为:" << area_CDE << endl;

cout << "心里阴影面积为:" << 3 * ( length * high - 2 * (3.141592653 * (high / 2 ) * (high / 2)) ) / 8 + area_CDE << endl;
}