#include <iostream> #include <iomanip> class rectangle{ public: rectangle(double l=2.00,double w=1.00):length{l },width{w} {}; rectangle(const rectangle& obj):length{obj.length},width{obj.width}{}; ~rectangle()=default; double len() const{return length;} double wide()const{return width;} double area()const{return length*width;} double circumference() const{return (length+width)*2;} void resize (int times); void resize (int l_times,int w_times); private: double length,width; }; void rectangle::resize(int times){ length*=times; width*=times; } void rectangle::resize(int l_times,int w_times){ length*=l_times; width*=w_times; } void output(const rectangle &rect) { using namespace std; cout << "矩形信息: \n"; cout << fixed << setprecision(2); cout<<std::left<<setw(8)<<"长:"<<rect.len()<<endl; cout<<std::left<<setw(8)<<"宽:" <<rect.wide()<<endl; cout<<std::left<<setw(8)<<"面积:" <<rect.area()<<endl; cout<<std::left<<setw(8)<< "周长:"<<rect.circumference()<<endl; cout<<endl; } int main() { rectangle rect1; output(rect1); rectangle rect2(10, 5); output(rect2); rectangle rect3(rect1); rect3.resize(2); output(rect3); rect3.resize(5, 2); output(rect3); }
标签:int,一之,times,width,length,实验,double,rectangle From: https://www.cnblogs.com/dailu666666/p/16749751.html