C++中继承的简单应用(某无线通信设备 ODU 设备)

应用需求:

在这里插入图片描述
在这里插入图片描述

代码实现:

ODU.h

#pragma once
#include <string>
using namespace std;
class ODU
{
public:
	ODU();
	~ODU();

	float getTxPower() const;
	int getTxFreq() const;
	float getBandWidth() const;

	bool setTxPower(float power);
	bool setTxFreq(int frequency);
	bool setBandWidth(float bandwidth);

	string description();

protected:
	float txPower; // 发射功率
	int txFreq; // 发射频率
	float bandWidth; // 带宽
};


ODU.cpp

#include "ODU.h"
#include <sstream>

ODU::ODU()
{
}

ODU::~ODU()
{
}

float ODU::getTxPower() const
{
    return txPower;
}

int ODU::getTxFreq() const
{
    return txFreq;
}

float ODU::getBandWidth() const
{
    return bandWidth;
}

bool ODU::setTxPower(float power)
{
    this->txPower = power;
    return true;
}

bool ODU::setTxFreq(int frequency)
{
    this->txFreq = frequency;
    return true;
}

bool ODU::setBandWidth(float bandwidth)
{
    this->bandWidth = bandwidth;
    return true;
}

string ODU::description() {
    stringstream ret;
    ret << "发射功率:" << txPower << "\t发射频率:" << txFreq
        << "\t带宽:" << bandWidth;
    return ret.str();
}

ODU330.h

#pragma once
#include <string>
#include "ODU.h"
using namespace std;
class ODU330 : public ODU
{
public:
	ODU330();
	~ODU330();

	float getWarnThreshold() const;
	float getBER() const;

	bool setWarnThreshold(float threshold);

	string description();
private:
	float warnThreshold; // 告警门限
};


ODU330.cpp

#include <sstream>
#include "ODU330.h"

ODU330::ODU330()
{
}

ODU330::~ODU330()
{
}

float ODU330::getWarnThreshold() const
{
	return warnThreshold;
}

float ODU330::getBER() const
{
	return 0.0005;
}

bool ODU330::setWarnThreshold(float threshold)
{
	this->warnThreshold = threshold;
	return true;
}

string ODU330::description()
{
	stringstream ret;
	ret << "发射功率:" << txPower << "\t发射频率:" << txFreq
		<< "\t带宽:" << bandWidth << "\t误码率:" << getBER()
		<< "\t告警门限:" << warnThreshold;
	return ret.str();
}

main.cpp

#include <iostream>
#include "ODU.h"
#include "ODU330.h"

int main() {
	ODU odu1;
	odu1.setBandWidth(500);
	odu1.setTxFreq(114000);
	odu1.setTxPower(45);
	cout << odu1.description() << endl;

	ODU330 odu2;
	odu2.setBandWidth(600);
	odu2.setTxFreq(119000);
	odu2.setTxPower(48);
	odu2.setWarnThreshold(0.0001);
	cout << odu2.description() << endl;

	system("pause");
	return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值