看板 LTJH-94306 關於我們 聯絡資訊
#include <iostream> using namespace std; class Rectangle { public: Rectangle(); float perimeter(); float area(); void set(); void get(); private: float length,width; }; Rectangle::Rectangle() { length=1.0; width=1.0; }; float Rectangle::perimeter() { return 2*(length+width); }; float Rectangle::area() { return length*width; } void Rectangle::set() { do{ cout << "Please input length:"; cin >> length; cout << "Please input width:"; cin >> width; }while(length >= 20.0 || width >= 20.0 || length <= 0.0 || width <= 0.0); }; void Rectangle::get() { cout << "length:" << length << endl; cout << "width:" << width << endl; }; int main () { Rectangle r; r.set(); r.get(); cout << "perimeter:" << r.perimeter() << endl; cout << "area:" << r.area() << endl; cout << endl; system("pause"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.138.3.10
a2364983:7aC7J 11/06 08:38