zoefun 2015-07-21 09:37 采纳率: 100%
浏览 1735
已采纳

求大神帮我看看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的,应该怎么改呢,怎么调通程序呢,小白真的不会了。大神们请帮帮忙。

  • 写回答

5条回答 默认 最新

  • zoefun 2015-07-21 11:17
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥15 pyqt信号槽连接写法
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。