首页 > 其他分享 >实验任务五

实验任务五

时间:2022-09-28 18:36:06浏览次数:44  
标签:const double length times width 任务 实验 Rectangle

#include<iostream>
#include<iomanip>
using namespace std;
class Rectangle
{
public:
    Rectangle(double length = 2.0, double width = 1.0);
    Rectangle(const Rectangle& obj);
    ~Rectangle() = default;
    double len()const;
    double wide()const;
    double area()const;
    double circumference()const;
    void resize(double times);
    void resize(double times, double w_times);
private:
    double _length;
    double _width;
};

Rectangle::Rectangle(double length, double width)
{
    _length = length;
    _width = width;
}

Rectangle::Rectangle(const Rectangle& obj)
{
    _length = obj._length;
    _width = obj._width;
}

double Rectangle::len()const
{
    return _length;
}

double Rectangle::wide()const
{
    return _width;
}

double Rectangle::area()const
{
    return _length * _width;
}

double Rectangle::circumference()const
{
    return _length * 2 + _width * 2;
}
void Rectangle::resize(double times)
{
    _length *=times;
    _width *=times;
}

void Rectangle::resize(double times, double w_times)
{
    _length*=times;
    _width *=w_times;
}

void output(const Rectangle& rect)
{
    cout << "矩形信息:\n";
    cout << fixed << setprecision(2);
    cout << "长:    " << rect.len() << endl;
    cout << "宽:    " << rect.wide() << endl;
    cout << "面积:  " << rect.area() << endl;
    cout << "周长:  " << rect.circumference() << endl<<endl;
}
int main()
{
    Rectangle rect1;
    output(rect1);

    Rectangle rect2(10, 5);
    output(rect2);

    Rectangle rect3(rect1);
    rect3.resize(2);
    output(rect3);

    rect3.resize(5, 2);
    output(rect3);
    system("pause");
    return 0;
}

 

标签:const,double,length,times,width,任务,实验,Rectangle
From: https://www.cnblogs.com/xelfin/p/16739166.html

相关文章

  • Linux定时任务详解
    crond定时任务详解crond是Linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,可以在无需人工干预的情况下运行作业。我的环境是3A服务器搭建centos7.9,延......
  • Linux定时任务详解
    crond定时任务详解crond是Linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,可以在无需人工干预的情况下运行作业。我的环境是3A服务器搭建centos7.......
  • 实验3:OpenFlow协议分析实践
    一、实验目的能够运用wireshark对OpenFlow协议数据交互过程进行抓包;能够借助包解析工具,分析与解释OpenFlow协议的数据包交互过程与机制。二、实验环境下载虚拟机......
  • 实验2:Open vSwitch虚拟交换机实践与实验环境安装配置
    实验2:OpenvSwitch虚拟交换机实践一、实验目的能够对OpenvSwitch进行基本操作;能够通过命令行终端使用OVS命令操作OpenvSwitch交换机,管理流表;能够通过Mininet的Pytho......
  • 实验1 C语言开发环境使用和数据类型、运算符、表达式
    #include<iostream>#include<string>#include<vector>intmain(){usingnamespacestd;strings1;//创建一个string对象strings2{"cplusplus"};//......
  • 实验3 OpenFlow协议分时实践
    基础实验抓包分析step1:搭建拓扑并配置相应IPstep2:Pingall并抓包step3:分析(1)hello包表示含义:控制器6633端口发送“我最高能支持OpenFlow1.0”信息给交换机43826端口......
  • 实验1.1熟悉string和vector
    #include<iostream>#include<string>#include<vector>intmain(){usingnamespacestd;strings1;strings2{"cplusplus"};strings3{s2};......
  • 实验3:OpenFlow协议分析实践
    拓扑#!/usr/bin/envpythonfrommininet.netimportMininetfrommininet.nodeimportController,RemoteController,OVSControllerfrommininet.nodeimportCPULi......
  • 实验1 类和对象(1)
    实验目的通过实践,加深对类、对象的理解,能够解释类的抽象、封装所指,能够描述什么是类的接口能够使用C++语法规则正确定义、实现、测试类能够使用C++语法规则正确创建对......
  • 实验2:Open vSwitch虚拟交换机实践
    实验2:OpenvSwitch虚拟交换机实践一、实验目的能够对OpenvSwitch进行基本操作;能够通过命令行终端使用OVS命令操作OpenvSwitch交换机,管理流表;能够通过Mininet的Pyth......