C++ day3

打印 上一主题 下一主题

主题 905|帖子 905|积分 2715





  1. #include <iostream>
  2. using namespace std;
  3. class rec
  4. {
  5.     const int length;
  6.     int width;
  7. public:
  8.     rec (int length):length(length){};
  9.     void set_width(int W);
  10.     int get_length();
  11.     int get_width();
  12.     void show();
  13. };
  14. void rec::set_width(int W)
  15. {
  16.     width=W;
  17. }
  18. int rec::get_length()
  19. {
  20.     return length;
  21. }
  22. int rec::get_width()
  23. {
  24.     return width;
  25. }
  26. void rec::show()
  27. {
  28.     int l,s;
  29.     l=2*(length+width);
  30.     s=length*width;
  31.     cout<<"周长:"<<l<<endl;
  32.     cout<<"面积:"<<s<<endl;
  33. }
  34. int main()
  35. {
  36.     rec s(6);
  37.     s.set_width(5);
  38.     int a=s.get_width();
  39.     int b=s.get_length();
  40.     cout<<a<<endl;
  41.     cout<<b<<endl;
  42.     s.show();
  43.     return 0;
  44. }
复制代码
 

  1. #include <iostream>
  2. using namespace std;
  3. class y
  4. {
  5.     int &R;
  6. public:
  7.     y(int &R):R(R){};
  8.     void show();
  9. };
  10. void y::show()
  11. {
  12.     double PI=3.14;
  13.     double l,s;
  14.     l=2*PI*R;
  15.     s=PI*R*R;
  16.     cout<<"周长:"<<l<<endl;
  17.     cout<<"面积:"<<s<<endl;
  18. }
  19. int main()
  20. {
  21.     int r=4;
  22.     y s(r);
  23.     s.show();
  24.     return 0;
  25. }
复制代码
 


  1. #include <iostream>
  2. using namespace std;
  3. class car
  4. {
  5.     string se;
  6.     string brand;
  7.     int speed;
  8. public:
  9.     car(string a,string b,int c):se(a),brand(b),speed(c){};
  10.     void display();
  11.     void acc(int a);
  12. };
  13. void car::display()
  14. {
  15.     cout<<se<<endl;
  16.     cout<<brand<<endl;
  17.     cout<<speed<<endl;
  18. }
  19. void car::acc(int a)
  20. {
  21.     speed=a;
  22. }
  23. int main()
  24. {
  25.     string a,b;
  26.     getline(cin,a);
  27.     getline(cin,b);
  28.     car s(a,b,50);
  29.     s.display();
  30.     s.acc(80);
  31.     return 0;
  32. }
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

麻花痒

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表