面积
代码示例:
1 #include <iostream> 2 3 using namespace std; 4 5 class circle { 6 7 public: 8 void set_r(int rr); 9 double c_circle(); 10 double s_circle(); 11 12 private: 13 int r; 14 }; 15 16 17 void circle::set_r(int rr) { 18 r = rr; 19 } 20 21 double circle::c_circle() { 22 double c = 0; 23 c = r * 3.14 * 2 ; 24 cout << "c = " << c << endl; 25 return c; 26 } 27 28 double circle::s_circle() { 29 double s = 0 ; 30 s = r * r * 3.14; 31 cout << "s = " << s << endl; 32 return s; 33 } 34 35 36 int main(void) { 37 class circle temp; 38 temp.set_r(1); 39 temp.c_circle(); 40 temp.s_circle(); 41 42 system("pause"); 43 44 return 0; 45 }