- #include <iostream>
- using namespace std;
- class rec
- {
- const int length;
- int width;
- public:
- rec (int length):length(length){};
- void set_width(int W);
- int get_length();
- int get_width();
- void show();
- };
- void rec::set_width(int W)
- {
- width=W;
- }
- int rec::get_length()
- {
- return length;
- }
- int rec::get_width()
- {
- return width;
- }
- void rec::show()
- {
- int l,s;
- l=2*(length+width);
- s=length*width;
- cout<<"周长:"<<l<<endl;
- cout<<"面积:"<<s<<endl;
- }
- int main()
- {
- rec s(6);
- s.set_width(5);
- int a=s.get_width();
- int b=s.get_length();
- cout<<a<<endl;
- cout<<b<<endl;
- s.show();
- return 0;
- }
复制代码
- #include <iostream>
- using namespace std;
- class y
- {
- int &R;
- public:
- y(int &R):R(R){};
- void show();
- };
- void y::show()
- {
- double PI=3.14;
- double l,s;
- l=2*PI*R;
- s=PI*R*R;
- cout<<"周长:"<<l<<endl;
- cout<<"面积:"<<s<<endl;
- }
- int main()
- {
- int r=4;
- y s(r);
- s.show();
- return 0;
- }
复制代码
- #include <iostream>
- using namespace std;
- class car
- {
- string se;
- string brand;
- int speed;
- public:
- car(string a,string b,int c):se(a),brand(b),speed(c){};
- void display();
- void acc(int a);
- };
- void car::display()
- {
- cout<<se<<endl;
- cout<<brand<<endl;
- cout<<speed<<endl;
- }
- void car::acc(int a)
- {
- speed=a;
- }
- int main()
- {
- string a,b;
- getline(cin,a);
- getline(cin,b);
- car s(a,b,50);
- s.display();
- s.acc(80);
- return 0;
- }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |