2.天线参数计算

#pragma warning(disable:4996)
#define _CRT_SECURE_NO_WARNINGS 1
const float c = 3e11;
#include <iostream>
using namespace std;

class Antenna
{
public:
    Antenna(float &f)
    {
        this->f = f;
        this->Lam = c / f;
        this->Lamquarter = this->Lam / 4;
    }
public:
    float Lam;//天线工作波长
    float Lamquarter;//天线工作四分之一波长
    float f;//天线工作的频率
};

class AntennaWG
{
public:
    AntennaWG(float &f,float &er)
    {
        this->f = f;
        this->er = er;
        this->Lam = c / f;
        this->Lamquarter = this->Lam / 4;
        this->Lamg = this->Lam / sqrt(this->er);
        this->Lamgquarter = this->Lamg / 4;
    }
public:
    float er;//介质板介电常数
    float Lam;//天线工作波长
    float Lamquarter;//四分之一的天线工作波长
    float Lamg;//天线导波波长
    float Lamgquarter;//四分之一的天线导波波长
    float f;//天线工作的频率
};

int main()
{
    while( 1 )
    {
        unsigned int project;//要计算的项目
        cout << "------------------------------------------------------------------------" << endl;
        cout << "请输入你要计算的项目:" << endl;
        cout << "输入1计算自由空间波长及四分之一波长;" << endl;
        cout << "输入2计算导波波长和四分之一波长;" << endl;
        cin >> project;
        cout << endl;
        if( (project == 1) || (project == 2) )
        { 
            unsigned int unit;//选择单位
            cout << "请输入你要选择单位:" << endl;
            cout << "输入1选择GHz为单位;" << endl;
            cout << "输入2选择MHz为单位;" << endl;
            cout << "输入3选择KHz为单位;" << endl;
            cout << "输入4选择Hz为单位;" << endl;
            cin >> unit;
            cout << endl;

            if( (unit == 1) || (unit == 2)|| (unit == 3) || (unit == 4) )
            {
                float f;//要计算的频率
                cout << "输入天线的频率f:" << endl;
                cin >> f;
                cout << endl;
                switch( unit )
                {
                    case 1:
                        f = f * (1e9); break;
                    case 2:
                        f = f * (1e6); break;
                    case 3:
                        f = f * (1e3); break;
                    default:
                        break;
                }

                switch( project )
                {
                    case 1:
                    {
                        Antenna antenna(f);
                        cout << "天线的频率f:" << antenna.f << endl;
                        cout << "天线波长Lam = :" << antenna.Lam << endl;
                        cout << "天线的1/4波长Lamquarter = :" << antenna.Lamquarter << endl;
                        break;
                    }

                    case 2:
                    {
                        float er;//介质板的介电常数
                        cout << "输入基板的相对介电常数er:" << endl;
                        cin >> er;
                        cout << endl;
                        AntennaWG antennaWG(f, er);
                        float ANTSimulMdeium = (antennaWG.Lam + antennaWG.Lamg) / 2;
                        cout << "天线的频率f:" << antennaWG.f << endl;
                        cout << "输入基板的相对介电常数er:" << antennaWG.er << endl;
                        cout << "天线波长Lam = :" << antennaWG.Lam << endl;
                        cout << "天线的1/4波长Lamquarter = :" << antennaWG.Lamquarter << endl;
                        cout << "天线导波波长Lamg = :" << antennaWG.Lamg << endl;
                        cout << "天线的1/4导波波长Lamgquarter = :" << antennaWG.Lamgquarter << endl;

                        break;
                    }
                }
            }
            else
            {
                cout << "你小子输入错误了:" << endl;
            }
        }
        else
        {
            cout << "你小子输入错误" << endl;
            continue;
        }
    }

    return 0;
}
posted @ 2022-10-30 14:38  CodeMagicianT  阅读(82)  评论(0编辑  收藏  举报