当前位置: 首页 > news >正文

微网站 文章地推任务网

微网站 文章,地推任务网,费县做网站,asp网站后台无法编辑作业: 1.整理思维导图 2.整理课上代码 3.把课上类的三个练习题的构造函数写出来 函数全部类内声明,类外定义 定义一个矩形类Rec,包含私有属性length、width,包含公有成员方法: void set_length(int l); //设置长度v…

作业:

1.整理思维导图

2.整理课上代码

3.把课上类的三个练习题的构造函数写出来

函数全部类内声明,类外定义

  1. 定义一个矩形类Rec,包含私有属性length、width,包含公有成员方法:

    1. void set_length(int l); //设置长度
    2. void set_width(int w); //设置宽度
    3. int get_length(); //获取长度,将长度的值返回给调用处
    4. int get_width(); //获取宽度,将宽度的值返回给调用处
    5. void show(); //输出周长和面积
#include <iostream>
using namespace std;class Rec {
private:int length;  // 私有属性:长度int width;   // 私有属性:宽度
public:void setLength(int l);  // 设置长度void setWidth(int w);   // 设置宽度int getLength();        // 获取长度int getWidth();         // 获取宽度void show();            // 输出周长和面积
};void Rec::setLength(int l) {length = l;
}void Rec::setWidth(int w) {width = w;
}int Rec::getLength() {return length;
}int Rec::getWidth() {return width;
}void Rec::show() {cout << "周长: " << 2 * (length + width) << endl;cout << "面积: " << length * width << endl;
}int main() {Rec a;int l, w;cout << "输入长度:";cin >> l;a.setLength(l);cout << "输入宽度:";cin >> w;a.setWidth(w);cout << "矩形的周长和面积为:" << endl;a.show();return 0;
}
  1. 定义一个圆类,包含私有属性半径r,公有成员方法:

    1. void set_r(int r); //获取半径
    2. void show //输出周长和面积,show函数中需要一个提供圆周率的参数PI,该参数有默认值3.14
#include <iostream>
#include <iomanip> // 用于设置输出格式
using namespace std;class Circle {
private:double radius; // 私有属性:半径
public:void setR(double &r);       // 设置圆的半径void show(double PI = 3.14); // 输出周长和面积
};void Circle::setR(double &r) {radius = r;
}void Circle::show(double PI) {double circumference = 2 * PI * radius; // 计算周长double area = PI * radius * radius;     // 计算面积cout << "周长: " << fixed << setprecision(2) << circumference << endl;cout << "面积: " << fixed << setprecision(2) << area << endl;
}int main() {Circle c;     // 创建圆类的对象 cdouble r;cout << "输入圆的半径: ";cin >> r;c.setR(r); // 设置半径cout << "圆的周长和面积为:" << endl;c.show();return 0;
}
  1. 定义一个Car类,包含私有属性,颜色color,品牌brand,速度speed,包含公有成员方法:

    1. void display(); //显示汽车的品牌,颜色和速度
    2. void acc(int a); //加速汽车
    3. set函数,设置类中的私有属性
#include <iostream>
#include <string> // 引入字符串库
using namespace std;class Car {
private:string color; // 汽车颜色string brand; // 汽车品牌int speed;    // 汽车速度
public:void set(string c, string b, int s); // 设置汽车的属性void display();                     // 显示汽车信息void acc(int a);                    // 加速汽车
};void Car::set(string c, string b, int s) {color = c;brand = b;speed = s;
}void Car::display() {cout << "品牌: " << brand << ", 颜色: " << color << ", 速度: " << speed << " km/h" << endl;
}void Car::acc(int a) {speed += a; // 增加速度cout << "加速 " << a << " km/h, 当前速度: " << speed << " km/h" << endl;
}int main() {Car myCar; // 创建Car类的对象myCarmyCar.set("红色", "奥迪", 0); // 设置汽车的初始属性cout << "初始状态:" << endl;myCar.display();myCar.acc(50); // 加速50 km/hmyCar.acc(30); // 再加速30 km/hreturn 0;
}

http://www.ds6.com.cn/news/36128.html

相关文章:

  • 通辽做网站0475seo网页制作公司排名
  • 申请做网站编辑组长的工作设想企业网站模板建站
  • 公司招人去哪个网站成都网站seo服务
  • wordpress的根目录武汉seo优
  • 微信php网站开发流程图上海网络推广外包公司
  • 家装设计培训班哪里有上海专业的seo推广咨询电话
  • 网站开发需要学习什么技术友情链接交换的意义是什么
  • jsp动态网站开发实践教程(第2版)在线培训考试系统
  • 网站卖给做博彩的直通车推广计划方案
  • 太原做企业网站的站长工具seo综合查询 分析
  • 360全景网站建设营销网络图
  • 网站所有权查询福建seo
  • 要做网络推广seo还可以做哪些推广
  • 苹果企业的vi设计seo优化范畴
  • 政府网站建设的研究意义微信广告投放平台
  • 网站怎么做用户体验外贸网站seo
  • strikingly建站工具营销效果分析怎么写
  • 常熟祥云平台网站建设互联网营销师培训教材
  • 如何在国外社交网站上做原单外贸网络营销考试题目及答案2022
  • 美食优秀设计网站百度搜索量怎么查
  • 哪里帮做企业网站整站seo技术
  • 零食网站建设策划书模板汉中网站seo
  • 莱芜网站建设sikesoft北京seo百科
  • 哪个网站能买到做披萨的芝士正宗做外贸推广
  • 网站优化方案书品牌策划公司
  • 建设网站有哪些方法有哪些如何网络推广新产品
  • 运城 网站建设北京seo技术
  • 新余建站公司网络推广是什么工作内容
  • 网站如何做中英文效果试分析网站推广和优化的原因
  • 求网站建设详细过程网站首页关键词如何优化