早教吧 育儿知识 作业答案 考试题库 百科 知识分享

定义一个圆类,计算圆的面积和周长。//定义一个圆类,计算圆的面积和周长。//要求:分别用成员函数#include<iostream>usingnamespacestd;classcylinder{public:friendvoidgetvalue(cylinder&);floatare

题目详情
定义一个圆类,计算圆的面积和周长。//定义一个圆类,计算圆的面积和周长。 //要求:分别用成员函数 #include<iostream> usingnamespacestd; classcylinder { public: friendvoidget_value(cylinder&); floatarea(cylinder&); floatvolume(cylinder&); floatR; private: floath; }; voidget_value(cylinder&) { cout<<"输入半径R和高h:"; } floatarea(cylinder&d) { return(2*3.14*d.R+2*3.14*d.R*d.h); } floatvolume(cylinder&t) { return(3.14*t.R*t.R*t.h); } intmain() {Cylindercylinder1; get_value(cylinder1); cout<<"面积="<<area(cylinder1)<<endl; cout<<"体积="<<volume(cylinder1)<<endl; return0; }
▼优质解答
答案和解析
周长:形成整个圆的那条曲线的长度叫圆的周长。 面积:组成员的那条曲线中的面积,就是圆的面积。