|
#include <iostream.h><br/> class rect{<br/> private:<br/> float x,y;<br/> public:<br/> void set(float a,float b);<br/> float peri();<br/> float area();<br/> };<br/> void rect::set(float a=0,float b=0)<br/> {<br/> x=a;<br/> y=b;<br/> cout<<"四边形的长: ";<br/> cin>>x;<br/> cout<<"四边形的宽: ";<br/> cin>>y; <br/> }<br/> float rect::peri()<br/> {<br/> float z;<br/> z=2*x+2*y;<br/> return z;<br/> }<br/> float rect::area()<br/> {<br/> float z;<br/> z=x*y;<br/> return z;<br/> }<br/> void main()<br/> {<br/> rect ob;<br/> ob.set();<br/> cout<<"四边形的周长:"<<ob.peri()<<endl;<br/> cout<<"面积为:"<<ob.area()<<endl;<br/> }<br/> |
|