C++ day3

复制代码
#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;
}
相关推荐
侃侃_天下19 小时前
最终的信号类
开发语言·c++·算法
echoarts19 小时前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Aomnitrix20 小时前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
每天回答3个问题20 小时前
UE5C++编译遇到MSB3073
开发语言·c++·ue5
伍哥的传说20 小时前
Vite Plugin PWA – 零配置构建现代渐进式Web应用
开发语言·前端·javascript·web app·pwa·service worker·workbox
小莞尔21 小时前
【51单片机】【protues仿真】 基于51单片机八路抢答器系统
c语言·开发语言·单片机·嵌入式硬件·51单片机
我是菜鸟0713号21 小时前
Qt 中 OPC UA 通讯实战
开发语言·qt
JCBP_21 小时前
QT(4)
开发语言·汇编·c++·qt·算法
Brookty21 小时前
【JavaEE】线程安全-内存可见性、指令全排序
java·开发语言·后端·java-ee·线程安全·内存可见性·指令重排序
百锦再1 天前
[特殊字符] Python在CentOS系统执行深度指南
开发语言·python·plotly·django·centos·virtualenv·pygame