应用需求:
代码实现:
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;
}