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;
}
相关推荐
lili-felicity3 分钟前
CANN性能调优与实战问题排查:从基础优化到排障工具落地
开发语言·人工智能
独自破碎E5 分钟前
【BISHI15】小红的夹吃棋
android·java·开发语言
进阶小白猿17 分钟前
Java技术八股学习Day33
java·开发语言·学习
执风挽^1 小时前
Python基础编程题2
开发语言·python·算法·visual studio code
Z9fish1 小时前
sse哈工大C语言编程练习20
c语言·开发语言·算法
萧鼎2 小时前
Python 包管理的“超音速”革命:全面上手 uv 工具链
开发语言·python·uv
Anastasiozzzz2 小时前
Java Lambda 揭秘:从匿名内部类到底层原理的深度解析
java·开发语言
刘琦沛在进步2 小时前
【C / C++】引用和函数重载的介绍
c语言·开发语言·c++
机器视觉的发动机3 小时前
AI算力中心的能耗挑战与未来破局之路
开发语言·人工智能·自动化·视觉检测·机器视觉
HyperAI超神经3 小时前
在线教程|DeepSeek-OCR 2公式/表格解析同步改善,以低视觉token成本实现近4%的性能跃迁
开发语言·人工智能·深度学习·神经网络·机器学习·ocr·创业创新