项目十一练习2
作者:互联网
题目:
某无线通信设备ODU设备, 具有以下功能:
- 查看发射功率, 设置发射功率
- 查看发射频率, 设置发射频率
- 查看带宽, 修改带宽
- 查看设备概述(各指标的值)
后来对该产品做了升级, 研发了ODU330产品,
这个产品, 新增加了以下功能:
- 查看当前的误码率
- 查看误码率告警门限
- 设置误码率告警门限
代码实现:
1. ODU类
头文件
#pragma once
#include <string>
using namespace std;
class ODU
{
public:
ODU();
ODU(float transmissionPower, float transmissionFrequency, float bandwidth);
void setTransmissionPower(float transmissionPower);
void setTransmissonFrequency(float transmissonFrequency);
void setBandwidth(float bandwidth);
float getTransmissionPower() const;
float getTransmissonFrequency() const;
float getBandwidth() const;
string description() const;
protected:
float transmissionPower; //发射功率
float transmissonFrequency; //发射频率
float bandwidth; //带宽
};
实现方法
#include <sstream>
#include "ODU.h"
ODU::ODU()
{
transmissionPower = 0.0;
transmissonFrequency = 0.0;
bandwidth = 0.0;
}
ODU::ODU(float transmissionPower, float transmissionFrequency, float bandwidth)
{
this->transmissionPower = transmissionPower;
this->transmissonFrequency = transmissionFrequency;
this->bandwidth = bandwidth;
}
void ODU::setTransmissionPower(float transmissionPower)
{
this->transmissionPower = transmissionPower;
}
void ODU::setTransmissonFrequency(float transmissonFrequency)
{
this->transmissonFrequency = transmissonFrequency;
}
void ODU::setBandwidth(float bandwidth)
{
this->bandwidth = bandwidth;
}
float ODU::getTransmissionPower() const
{
return transmissionPower;
}
float ODU::getTransmissonFrequency() const
{
return transmissonFrequency;
}
float ODU::getBandwidth() const
{
return bandwidth;
}
string ODU::description() const
{
stringstream ret;
ret << "OCU的发射功率是: " << transmissionPower << " 发射频率是: " << transmissonFrequency << " 带宽是: " << bandwidth;
return ret.str();
}
2. ODU330类
头文件
#pragma once
#include <sstream>
#include "ODU.h"
class OUD330 : public ODU
{
public:
OUD330(float transmissionPower, float transmissionFrequency, float bandwidth, float bar, int alarmThreshold);
void setAlarmThreshold();
float getBar() const;
int getAlarmThreshold() const;
string description() const;
private:
float bar; //误码率
int alarmThreshold; //告警门限
};
方法实现
#include "OUD330.h"
OUD330::OUD330(float transmissionPower, float transmissionFrequency, float bandwidth, float bar, int alarmThreshold):
ODU(transmissionPower, transmissionFrequency, bandwidth)
{
this->bar = bar;
this->alarmThreshold = alarmThreshold;
}
void OUD330::setAlarmThreshold()
{
}
float OUD330::getBar() const
{
return bar;
}
int OUD330::getAlarmThreshold() const
{
return alarmThreshold;
}
string OUD330::description() const{
stringstream ret;
ret << "OCU330的发射功率是: " << transmissionPower << " 发射频率是: " << transmissonFrequency << " 带宽是: " << bandwidth
<< " 误码率:" << bar << " 告警门限:" << alarmThreshold;
return ret.str();
}
调用
#include <iostream>
#include "ODU.h"
#include "ODU330.h"
int main(){
ODU o1(1000.5,300.12,40);
ODU O2;
O2.setTransmissionPower(2019.22);
O2.setTransmissonFrequency(2021.05);
O2.setBandwidth(21);
cout << o1.description() << endl;
cout << O2.description() << endl;
OUD330 odu(1000.53,230.71,23,0.000005,3);
OUD330 odu2;
odu2.setTransmissionPower(1998.03);
odu2.setTransmissonFrequency(1997.12);
odu2.setBandwidth(25);
odu2.setAlarmThreshold(20);
cout << odu.description() << endl;
cout << odu2.description() << endl;
return 0;
}
标签:十一,练习,const,transmissionPower,项目,float,ODU,bandwidth,OUD330 来源: https://blog.csdn.net/jjswift/article/details/114903367