程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> 軟件開發-求大神幫我看看C++代碼

軟件開發-求大神幫我看看C++代碼

編輯:編程綜合問答
求大神幫我看看C++代碼

以下是我的.h頭文件:

 #include <vector>
#include<iostream>
#include <iomanip>
#include <math.h>
#define M_PI  3.14159265359

////////**************定義目標狀態***************////////


typedef struct strTargetState//笛卡爾坐標系位置
{
    double dTargetPostionX;//x
    double dTargetPostionY;//y
    double dTargetPostionZ;//z
}strTargetState;

vector <strTargetState> vTargetState;

//////////*************定義傳感器位置*************///////

typedef struct strSensorLocate//笛卡爾坐標系位置
{
    double dSensorX;//x
    double dSensorY;//y
    double dSensorZ;//z
}strSensorLocate;

strSensorLocate strSensor1;
strSensorLocate strSensor2;
strSensorLocate strSensor3;
strSensorLocate strSensor4;


//////////*************計算極坐標下位置*************//////

typedef struct strTargetPolarCoordinate//極坐標下位置
{
    double dTargetPitch;//俯仰角 phi
    double dTargetAzimuth;//方位角 thita
    double dTargetR;//徑向距離 r
}strTargetPolarCoordinate;

strTargetPolarCoordinate strTargetPolar;

class CHuoPaoSheng721//class declaration
{
public:
    CHuoPaoSheng721(double dIvestiRg,double dFrequency,double dDetectAccur,double dMornitScope,double dDataUpdateRate,
        int nMaxTargetNum,bool bDamageSatus,bool bOnOffControl,double dOriginLongitude,double dOriginLatitude,double dOriginHeight,
        double dL,double dh,double dSoundVelocity):

        m_dIvestiRg(dIvestiRg),
        m_dFrequency(dFrequency),
        m_dDetectAccur(dDetectAccur),
        m_dMornitScope(dMornitScope),
        m_dDataUpdateRate(dDataUpdateRate),
        m_nMaxTargetNum(nMaxTargetNum),
        m_bDamageSatus(bDamageSatus),
        m_bOnOffControl(bOnOffControl),

        m_dOriginLongitude(dOriginLongitude),
        m_dOriginLatitude(dOriginLatitude),
        m_dOriginHeight(dOriginHeight),

        m_dL(dL),//傳感器坐標
        m_dh(dh),

        m_dSoundVelocity(dSoundVelocity)//聲速    
    {
    }//endof CHuoPaoSheng721 構造函數初始化

    ~CHuoPaoSheng721(){}//析構函數

    int get_initia_Para();//系統參數初始化顯示
    int sys_state();//系統工作狀態判斷
    int get_polar();//目標角度量測

private:
    double m_dIvestiRg;//偵查距離
    double m_dFrequency;//傳聲器范圍
    double m_dDetectAccur;//偵查精度
    double m_dMornitScope;//監視范圍
    double m_dDataUpdateRate;//數據更新率
    int   m_nMaxTargetNum;//最大檢測目標數
    bool  m_bDamageSatus;//毀傷狀態 1on 0off
    bool  m_bOnOffControl;//開關機控制 1on 0off

    double m_dOriginLongitude;//坐標原點經度
    double m_dOriginLatitude;//坐標原點緯度
    double m_dOriginHeight;//坐標原點高度

    double m_dL;//傳感器坐標
    double m_dh;

    double m_dSoundVelocity;//聲速
    double m_dr1;//距離
    double m_dr2;
    double m_dr3;
    double m_dr4;

    double m_dtime1;//到達時間
    double m_dtime2;
    double m_dtime3;
    double m_dtime4;
};//end of class CHuoPaoSheng721

以下是頭文件對應的.cpp文件:
#include"stdafx.h"
#include <vector>
#include<iostream>
#include <iomanip>
#include <math.h>
#include "CHuoPaoSheng721.h"
#define M_PI  3.14159265359
using namespace std;

int CHuoPaoSheng721::get_initia_Para()//系統參數初始化顯示
{
    cout<<"偵查距離/(km):"<<setw(8)<<m_dIvestiRg<<endl;
    cout<<"傳聲器頻率范圍/Hz:"<<setw(8)<<m_dFrequency<<endl;
    cout<<"偵查精度(m):"<<setw(8)<<m_dDetectAccur<<endl;
    cout<<"監視范圍:"<<setw(8)<<m_dMornitScope<<endl;
    cout<<"數據更新率:"<<setw(8)<<m_dDataUpdateRate<<endl; 
    cout<<"最大檢測目標數:"<<setw(8)<<m_nMaxTargetNum<<endl;
    return 0;
}//end of get_initia_Para

int CHuoPaoSheng721::sys_state()//系統工作狀態判斷
{
    if ((m_bDamageSatus==1) && (m_bOnOffControl==1))
    {
        cout<<"系統正常可進行有效偵查"<<endl;
    }
    else
    {
        if (m_bDamageSatus==0)
        {
            cout<<"系統毀傷"<<endl;
        }
        if (m_bOnOffControl==0)
        {
            cout<<"系統未開機"<<endl;
        }
    }//end of if
    return 0;
}//end of CParaInitia

int CHuoPaoSheng721::get_polar()
{

//////////*************定義傳感器位置*************/////////


    strSensor1.dSensorX=m_dL;
    strSensor1.dSensorY=0;
    strSensor1.dSensorZ=m_dh;

    strSensor2.dSensorX=-m_dL;
    strSensor2.dSensorY=0;
    strSensor2.dSensorZ=m_dh;

    strSensor3.dSensorX=0;
    strSensor3.dSensorY=-m_dL;
    strSensor3.dSensorZ=m_dh;

    strSensor4.dSensorX=0;
    strSensor4.dSensorY=m_dL;
    strSensor4.dSensorZ=0;

    //  m_vTargetState.push_back(m_vTargetState);目標狀態獲得 壓入數值

///////////**********火炮聲計算************////////////


    for (int i=0;i<vTargetState.size();i++)
    {       
        m_dr1=sqrt(pow(strSensor1.dSensorX-vTargetState[i].dTargetPostionX,2)+pow(strSensor1.dSensorY-vTargetState[i].dTargetPostionY,2)+pow(strSensor1.dSensorZ-vTargetState[i].dTargetPostionZ,2));
        m_dr2=sqrt(pow(strSensor2.dSensorX-vTargetState[i].dTargetPostionX,2)+pow(strSensor2.dSensorY-vTargetState[i].dTargetPostionY,2)+pow(strSensor2.dSensorZ-vTargetState[i].dTargetPostionZ,2));
        m_dr3=sqrt(pow(strSensor3.dSensorX-vTargetState[i].dTargetPostionX,2)+pow(strSensor3.dSensorY-vTargetState[i].dTargetPostionY,2)+pow(strSensor3.dSensorZ-vTargetState[i].dTargetPostionZ,2));
        m_dr4=sqrt(pow(strSensor4.dSensorX-vTargetState[i].dTargetPostionX,2)+pow(strSensor4.dSensorY-vTargetState[i].dTargetPostionY,2)+pow(strSensor4.dSensorZ-vTargetState[i].dTargetPostionZ,2));

        if(((m_dIvestiRg>m_dr1)&&(m_dIvestiRg>m_dr2)&&(m_dIvestiRg>m_dr3)&&(m_dIvestiRg>m_dr4))==0)
        {   
            cout<<"目標超出傳感器探測范圍"<<endl;
            continue;
        }       

        m_dtime1=m_dr1/m_dSoundVelocity;
        m_dtime2=abs(m_dr2-m_dr1)/m_dSoundVelocity;
        m_dtime3=abs(m_dr4-m_dr1)/m_dSoundVelocity;
        m_dtime4=abs(m_dr4-m_dr1)/m_dSoundVelocity;

        strTargetPolar.dTargetAzimuth=atan((m_dtime3-m_dtime4)/m_dtime2)/M_PI*180;
        strTargetPolar.dTargetPitch=acos(m_dSoundVelocity*sqrt(pow(m_dr2,2)+pow(m_dr3-m_dr4,2)/(2*m_dL)));
        strTargetPolar.dTargetR=(pow(m_dL,2)*(m_dtime2-m_dtime3-m_dtime4)-pow(m_dL,2)*sqrt(4*pow(m_dL,2)/pow(m_dSoundVelocity,2)-pow(m_dtime2,2)-pow(m_dtime3-m_dtime4,2)))/(m_dSoundVelocity*(pow(m_dtime2,2)+pow(m_dtime2-m_dtime3-m_dtime4,2)-4*pow(m_dL,2)/pow(m_dSoundVelocity,2)));
    }

    cout<<"目標方位角為:"<<strTargetPolar.dTargetAzimuth<<endl;
    cout<<"目標俯仰角為:"<<strTargetPolar.dTargetPitch<<endl;
    cout<<"目標徑向距為:"<<strTargetPolar.dTargetR<<endl;

    return 0; 
}//end of get_polar

編譯的時候報錯:
--------------------Configuration: huo_pao_sheng721 - Win32 Debug--------------------
Compiling...
CHuoPaoSheng721.cpp
d:\vc6.0\msdev98\myprojects\huo_pao_sheng721\chuopaosheng721.h(17) : error C2143: syntax error : missing ';' before '<'
d:\vc6.0\msdev98\myprojects\huo_pao_sheng721\chuopaosheng721.h(17) : error C2501: 'vector' : missing storage-class or type specifiers
d:\vc6.0\msdev98\myprojects\huo_pao_sheng721\chuopaosheng721.h(17) : error C2143: syntax error : missing ';' before '<'
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(68) : error C2065: 'vTargetState' : undeclared identifier
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(68) : error C2228: left of '.size' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(70) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(70) : error C2228: left of '.dTargetPostionX' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(70) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(70) : error C2228: left of '.dTargetPostionY' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(70) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(70) : error C2228: left of '.dTargetPostionZ' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(71) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(71) : error C2228: left of '.dTargetPostionX' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(71) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(71) : error C2228: left of '.dTargetPostionY' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(71) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(71) : error C2228: left of '.dTargetPostionZ' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(72) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(72) : error C2228: left of '.dTargetPostionX' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(72) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(72) : error C2228: left of '.dTargetPostionY' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(72) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(72) : error C2228: left of '.dTargetPostionZ' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(73) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(73) : error C2228: left of '.dTargetPostionX' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(73) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(73) : error C2228: left of '.dTargetPostionY' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(73) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(73) : error C2228: left of '.dTargetPostionZ' must have class/struct/union type
Error executing cl.exe.

huo_pao_sheng721.exe - 29 error(s), 0 warning(s)

有好多是關於vector的,應該怎麼改呢,怎麼調通程序呢,小白真的不會了。大神們請幫幫忙。

最佳回答:


自己解決了,少了using namespace std; 好笨。。。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved