C++ 代码示例:模拟地球
// 地球代码
#include
// 定义地球类 class Earth { private: double radius; // 地球半径 double mass; // 地球质量 double temp; // 地球平均温度 public: Earth(double r, double m, double t) { radius = r; mass = m; temp = t; } void showInfo() { cout << '地球半径:' << radius << ' km' << endl; cout << '地球质量:' << mass << ' kg' << endl; cout << '地球平均温度:' << temp << ' ℃' << endl; } };
int main() { // 创建地球对象 Earth earth(6371, 5.97e24, 14); // 显示地球信息 earth.showInfo(); return 0; }
原文地址: https://www.cveoy.top/t/topic/l1Sw 著作权归作者所有。请勿转载和采集!