某无线通信设备ODU设备, 具有以下功能:
查看发射功率, 设置发射功率,
查看发射频率, 设置发射频率,
查看带宽, 修改带宽,
查看设备概述(各指标的值).
后来对该产品做了升级, 研发了ODU330产品:
这个产品, 新增加了以下功能:
查看当前的误码率.
查看误码率告警门限
设置误码率告警门限
项目思想:建立一个ODU类,再派生出ODU330
先建立一个ODU头文件和源文件
ODU.h
#pragma once
#include<string>
using namespace std;
class ODU
{
public:
float getTxpower();
int getTxfrequency();
int getBandwidth();
bool setTxpower(float Txpower);
bool setTxfrequency(int Txfrequency);
bool setBandwidth(int Bandwidth);
string discaption();
protected:
float Txpower; //发射功率
int Txfrequency; //发射频率
int Bandwidth; //带宽
};
ODU.cpp
#include "ODU.h"
#include<sstream>
float ODU::getTxpower()
{
return Txpower;
}
int ODU::getTxfrequency()
{
return Txfrequency;
}
int ODU::getBandwidth()
{
return Bandwidth;
}
bool ODU::setTxpower(float Txpower)
{
this->Txpower = Txpower;
return true;
}
bool ODU::setTxfrequency(int Txfrequency)
{
this->Txfrequency = Txfrequency;
return true;
}
bool ODU::setBandwidth(int Bandwidth)
{
this->Bandwidth = Bandwidth;
return true;
}
string ODU::discaption()
{
stringstream ret;
ret << "发射功率:" << Txpower
<< "\t发射频率:" << Txfrequency
<< "\t发射带宽:" << Bandwidth << endl;
return ret.str();
}
建立一个ODU330,使其继承ODU的功能
ODU330.h
#pragma once
#include"ODU.h"
class ODU330 :public ODU
{
public:
float getBER(); //误码率
float getWarnthre(); //查看警告门限
bool setWarnthre(float Warnthre); //设置警告门限
string discpation();
private:
float Warnthre;//警告门限
};
ODU330.cpp
#include "ODU330.h"
#include<sstream>
float ODU330::getBER()
{
return 0.005f;
}
float ODU330::getWarnthre()
{
return Warnthre;
}
bool ODU330::setWarnthre(float Warnthre)
{
this->Warnthre = Warnthre;
return true;
}
string ODU330::discpation()
{
stringstream ret;
ret << "发射功率:" << Txpower
<< "\t发射频率:" << Txfrequency
<< "\t发射带宽:" << Bandwidth
<< "\t发射误码率:" << getBER()
<< "\t告警门限:" << Warnthre
<< endl;
return ret.str();
}
再写主函数 对设备进行配置,在输出它的信息
#include<Windows.h>
#include<string>
#include<iostream>
#include"ODU.h"
#include"ODU330.h"
int main() {
ODU odu1;
odu1.setTxpower(45);
odu1.setBandwidth(500);
odu1.setTxfrequency(11400);
cout << odu1.discaption() << endl;
ODU330 odu2;
odu2.setTxpower(69);
odu2.setBandwidth(60);
odu2.setTxfrequency(19400);
odu2.setWarnthre(0.0002);
cout << odu2.discpation();
system("pause");
return 0;
}