码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • c++day2


     矩形类

    1. #include
    2. using namespace std;
    3. class Rec
    4. {
    5. int length;
    6. int width;
    7. public:
    8. void set_length(int l);
    9. void set_width(int w);
    10. int get_length();
    11. int get_width();
    12. void show();
    13. };
    14. void Rec::set_length(int l){
    15. length=l;
    16. }
    17. void Rec::set_width(int w){
    18. width=w;
    19. }
    20. int Rec::get_length(){
    21. cout<<"请输入长度:";
    22. cin>>length;
    23. return length;
    24. }
    25. int Rec::get_width(){
    26. cout<<"请输入宽度:";
    27. cin>>width;
    28. return width;
    29. }
    30. void Rec::show(){
    31. cout<<"周长:"<<(length+width)*2<
    32. cout<<"面积:"<
    33. }
    34. int main()
    35. {
    36. Rec a;
    37. a.set_length(a.get_length());
    38. a.set_width(a.get_width());
    39. a.show();
    40. return 0;
    41. }

     

     圆类

    1. #include
    2. using namespace std;
    3. class circle
    4. {
    5. int r;
    6. // double PI=3.14;
    7. public:
    8. int set_r(int l);
    9. void show(int r,double PI=3.14);
    10. };
    11. int circle::set_r(int l){
    12. r=l;
    13. return r;
    14. }
    15. void circle::show(int r, double PI){
    16. cout<<"周长:"<<2*r*PI<
    17. cout<<"面积:"<
    18. }
    19. int main()
    20. {
    21. circle a;
    22. a.show(a.set_r(3));
    23. return 0;
    24. }

     Car类

    1. #include
    2. using namespace std;
    3. class Car{
    4. private:
    5. string brand;
    6. string color;
    7. int speed;
    8. public:
    9. void display();
    10. void accelerate(int amount);
    11. void set(string brand,string color,int speed);
    12. };
    13. void Car::display(){
    14. cout<<"brand:"<
    15. cout<<"color:"<
    16. cout<<"speed:"<
    17. }
    18. void Car::accelerate(int amount){
    19. speed+=amount;
    20. }
    21. void Car::set(string brand, string color, int speed){
    22. Car::brand=brand;
    23. this->color=color;
    24. this->speed=speed;
    25. }
    26. int main()
    27. {
    28. Car car;
    29. car.set("geely","white",10);
    30. car.display();
    31. car.accelerate(10);
    32. car.display();
    33. return 0;
    34. }

     

  • 相关阅读:
    1-Maven-settings配置
    五、 通信协议
    车船边缘网关是如何给车辆船只定位的?
    在pandas中使用query替代loc进行高效简洁的条件筛选
    二叉树的遍历(非递归版)
    玉米地里的小鸟
    五、T100固定资产之固定资产盘点管理篇
    CMake 基础学习
    如何设置跨域隔离启用 SharedArrayBuffer
    2022届秋招Java岗高频面试题盘点,老司机也未必全会,真的太卷了
  • 原文地址:https://blog.csdn.net/weixin_44559978/article/details/138166878
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号