第七题代码:
#include <iostream>
#include <cmath> // 包含sqrt函数
int main() {
// 定义变量
double a_squared, b_squared;
double total_area;
// 根据题目,9 * a^2 = 180
a_squared = 180 / 9;
// 计算 b^2 = (9/8) * a^2
b_squared = (9.0 / 8.0) * a_squared;
// 计算两个小正方形面积和两大正方形面积
double small_squares_area = 2 * a_squared;
double large_squares_area = 2 * b_squared;
// 计算总面积
total_area = small_squares_area + large_squares_area;
// 输出结果
std::cout << "两个小正方形的面积总和: " << small_squares_area << " 平方米" << std::endl;
std::cout << "两个大正方形的面积总和: " << large_squares_area << " 平方米" << std::endl;
std::cout << "水池的总面积: " << total_area << " 平方米" << std::endl;
return 0;
}
第八题代码:
#include <iostream>
int main() {
// 定义变量
int original_width = 24; // 原始上方宽度
int reduced_width = 20; // 通道拐弯减少后的宽度
int channel_width; // 向下通道的宽度
int filled_length; // 填补后形成的连续长方形的长度
int new_width = 4; // 填补后形成的连续长方形的宽度(题目已给出)
int airport_area; // 国际机场面积
// 计算向下通道的宽度
channel_width = original_width - reduced_width;
// 计算填补后形成的连续长方形的长度
// 注意:这里的10、4和8都是题目中给出的与填补相关的数值
filled_length = original_width + (10 - channel_width) + (channel_width + 8);
// 计算国际机场面积
airport_area = filled_length * new_width;
// 输出结果
std::cout << "向下通道的宽度: " << channel_width << " 千米" << std::endl;
std::cout << "填补后形成的连续长方形的长度: " << filled_length << " 千米" << std::endl;
std::cout << "国际机场面积: " << airport_area << " 平方千米" << std::endl;
return 0;
}