C++_面向对象编程_练习(仅仅适合小白写写, 有兴趣可以写写)

某无线通信设备ODU设备, 具有以下功能:
在这里插入图片描述

  1. 查看发射功率, 设置发射功率.
  2. 查看发射频率, 设置发射频率.
  3. 查看带宽, 修改带宽.
  4. 查看设备概述(个指标的值).

后来对该产品做了升级, 研发成了ODU330产品:
在这里插入图片描述

这个产品, 新增加了以下功能:

  1. 查看当前的误码率.
  2. 查看误码率告警门限
  3. 设置误码率告警门限

参考:
OUD.h

#pragma once
#include <string>

class ODU
{
public:
	ODU();
	~ODU();

	float get_tx_power();
	int get_tx_freq();
	float get_band_width();

	bool set_tx_power(float tx_power);
	bool set_tx_freq(int tx_freq);
	bool set_band_width(float band_width);

	std::string description();

protected:
	float tx_power; /* 发射功率 */
	int tx_freq; /* 发射频率 */
	float band_width; /* 带宽, 单位: M*/
};

ODU.cpp

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

using namespace std;

ODU::ODU()
{
}

ODU::~ODU()
{
}

float ODU::get_tx_power()
{
	return tx_power;
}

int ODU::get_tx_freq()
{
	return tx_freq;
}

float ODU::get_band_width()
{
	return band_width;
}

bool ODU::set_tx_power(float tx_power)
{
	this->tx_power = tx_power;
	return true;
}

bool ODU::set_tx_freq(int tx_freq)
{
	this->tx_freq = tx_freq;
	return true;
}

bool ODU::set_band_width(float band_width)
{
	this->band_width = band_width;
	return true;
}

std::string ODU::description()
{
	stringstream ret;
	ret << "发射功率:" << tx_power << "\t发射功率:" << tx_freq
		<< "\t带宽:" << band_width;
	return ret.str();
}

ODU330.h

#pragma once
#include "ODU.h"
#include <string>

using namespace std;

class ODU330 :public ODU
{
public:
	ODU330();
	~ODU330();

	float get_warn_threshold(); /* 获取告警门限 */
	bool set_warn_threshold(float warn_threshold); /* 设置告警门限*/
	float get_error_rate(); /* 获取当前的误码率 */
	string description(); /* 描述 */

private:
	float warn_threshold; /* 告警门限 */

};

ODU330.cpp

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

using namespace std;

ODU330::ODU330()
{
}

ODU330::~ODU330()
{
}

float ODU330::get_warn_threshold()
{
	return warn_threshold;
}

bool ODU330::set_warn_threshold(float warn_threshold)
{
	this->warn_threshold = warn_threshold;
	return true;
}

float ODU330::get_error_rate()
{
	return 0.00005f; /* 模拟值 */
}

string ODU330::description()
{
	stringstream ret;
	ret << "发射功率: " << get_tx_power() << "\t发射频率:" << get_tx_freq()
		<< "\t带宽:" << get_band_width() << "\t误码率:" << get_error_rate()
		<< "\t告警门限:" << get_warn_threshold();
	return ret.str();
}

main.cpp

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

using namespace std;

int main()
{
	ODU odu1;
	odu1.set_band_width(500);
	odu1.set_tx_freq(114000);
	odu1.set_tx_power(45);
	cout << odu1.description() << endl;

	ODU330 odu2;
	odu2.set_band_width(600);
	odu2.set_tx_freq(119000);
	odu2.set_tx_power(48);
	odu2.set_warn_threshold(0.0001);
	cout << odu2.description() << endl;

	system("pause");
	return 0;
}

运行环境: vs2019
运行结果:
在这里插入图片描述

结语:

学到的知识要, 多复习, 多总结, 多敲. 需要时间的积累, 才能引起质的改变. 自己写不出来的永远是别人的.

分享一下我的技巧: 代数法把具体的数字带进去, 看看能能能找到规律(掌握思想).
还有就是画图, 也很重要. 用笔画出来, 把数代进去, 方法虽然笨, 但真的很实用, 好记忆不如烂笔头!!!

我是小白, 如果存在问题, 欢迎大神给予评判指正.
错了不可怕, 可怕的是找不出bug

今日是: 2020年5月3日, (由于疫情的原因)在家里整天坐在电脑前, 眼神逐渐从大到小.写博客, 就当写写日记吧!!!,

希望给个赞: 反正你又不亏, 顺便而已

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值