【C++】类与对象作业改良版

这篇博客探讨了C++中的类与对象的高级应用,通过修改后的job1.cpp、Rectangle.cpp和Rectangle.h文件展示了如何实现更复杂的矩形操作。内容涵盖了类的设计、对象的实例化以及成员函数的使用,旨在提升对C++面向对象编程的理解。
摘要由CSDN通过智能技术生成

job1.cpp

#include <iostream>
#include "Rectangle.h"

using namespace std;


int main(){
    double width,height;
    Rectangle r1;
    cout << "输出第一个缺省的矩形对象的信息:"<<endl;
    r1.display();

    cout << "请输入矩形的宽度和高度:";
    cin >> width >> height;
    Rectangle r2(width , height);
    cout << "输出第二个缺省的矩形对象的信息:"<<endl;
    r2.display();

    return 0;
}

Rectangle.cpp

//
// Created by 63400 on 2021/10/14.
//

#include <iostream>
#include "Rectangle.h"
using namespace std;

int Rectangle::count = 0;
Rectangle::Rectangle(double width, double height) {
    this->width = width;
    this->height = height;
    count++;
}
Rectangle::~Rectangle(){
    count--;
}
double Rectangle::getWidth(){
    return width;
}
double Rectangle::getHeight(){
    return height;
}
void Rectangle::setWidth(double width){
    thi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值