福州seo网站优化,毕业网站设计代做,长春亚泰吧,上海发布微博(1)确定所求长方形的长和宽。 (2)确定计算长方形的周长和面积的公式并计算。 (3)输出计算结果。 (1)以面向过程程序设计思想编码。 #include using namespace std; void main(){ int perimeter,area; int length20,width10; perimeter2*(lengthwidth); arealength* width; cou…(1)确定所求长方形的长和宽。 (2)确定计算长方形的周长和面积的公式并计算。 (3)输出计算结果。 (1)以面向过程程序设计思想编码。 #include using namespace std; void main(){ int perimeter,area; int length20,width10; perimeter2*(lengthwidth); arealength* width; cout“perimeter”perimeterendl; cout“area”areaendl; } 2.以面向对象的程序设计方式思考 #include using namespace std; class Rectangle { public: Rectangle(float w0,float 10) { widthw;lengthl; } void GetArea() {cout’ areawidthlength endl;} void GetPerim() {cout“perimeter” 2(widthlength)endl;} private:float width,length; } void main() { Rectangle a( 10,20);/定义长方形类的个变量 a, 即实例化-个特殊的长方形对象a它的长是20宽是 10/ a.GetPerim();//调用a对象的两个方法 a.GetArea(); } 面向过程注重算法面向对象注重共同属性和行为。