C++--

 1、

 

#include <iostream>

   
using namespace std;
class Rec
{
    int length;
    int width;
public:
   void  set_length(int l);
    void set_width(int h);
    int get_length();
    int get_width();
    void show();
};
void Rec::set_length(int l)
{
    length=l;
}
void Rec::set_width(int h)
{
    width=h;
}

   
int Rec::get_length()
{
    return length;
}
int Rec::get_width()
{
    return width;
}
void Rec::show()
{
    cout << "周长=" << (length+width)*2 << endl;
}

   
int main()
{
    Rec p1;
    p1.set_length(10);
    p1.set_width(8);
    p1.show();

   
    return 0;
}

 

 2、

 

#include <iostream>

   
using namespace std;
class j
{
    double r;
public:
    double PI=3.14;
    void set_r(double re);
    double get_r();
    void show();
};
void j::set_r(double re)
{
    r=re;
}
double j::get_r()
{
    return  r;
}
void j::show()
{
    cout << "周长=" << 2*PI*r << endl;
    cout << "面积=" << PI*r*r << endl;
}
int main()
{
    j p1;
    p1.set_r(4);
    p1.show();
    cout << "Hello World!" << endl;
    return 0;
}

  

 

3、 

 

 

#include <iostream>

   
using namespace std;
class car
{
    string brand;
    string color;
    int speed;
public:
    void display(string brand_a,string color_a,int speed_a);
    void show();
};
void car::display(string brand_a, string color_a, int speed_a)
{
    brand=brand_a;
    color=color_a;
    speed=speed_a;
}
void car::show()
{
    cout << "brand=" << brand <<endl;
    cout << "color=" << color << endl;
    cout << "speed=" << speed << endl;
}
int main()
{
    car p1;
    p1.display("荣耀汽车","黑外内棕",50);
    p1.show();
    cout << "Hello World!" << endl;
    return 0;
}

 

 思维导图

相关推荐

  1. <span style='color:red;'>C</span>

    C

    2024-04-29 03:00:04      26 阅读
  2. <span style='color:red;'>C</span>++--

    C++--

    2024-04-29 03:00:04      13 阅读
  3. C++

    2024-04-29 03:00:04       8 阅读
  4. ccccc‘cccccccccccc‘ccc

    2024-04-29 03:00:04       17 阅读
  5. CC++,C# 的区别

    2024-04-29 03:00:04       33 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-29 03:00:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-29 03:00:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-29 03:00:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-29 03:00:04       18 阅读

热门阅读

  1. 分布式架构搭建

    2024-04-29 03:00:04       7 阅读
  2. 商城数据库88张表练习85~88

    2024-04-29 03:00:04       13 阅读
  3. 洛谷 P3810 【模板】三维偏序(陌上花开)

    2024-04-29 03:00:04       12 阅读