软件开发-求大神帮我看看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.0msdev98myprojectshuo_pao_sheng721chuopaosheng721.h(17) : error C2143: syntax error : missing ';' before '<'
d:vc6.0msdev98myprojectshuo_pao_sheng721chuopaosheng721.h(17) : error C2501: 'vector' : missing storage-class or type specifiers
d:vc6.0msdev98myprojectshuo_pao_sheng721chuopaosheng721.h(17) : error C2143: syntax error : missing ';' before '<'
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(68) : error C2065: 'vTargetState' : undeclared identifier
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(68) : error C2228: left of '.size' must have class/struct/union type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(70) : error C2109: subscript requires array or pointer type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(70) : error C2228: left of '.dTargetPostionX' must have class/struct/union type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(70) : error C2109: subscript requires array or pointer type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(70) : error C2228: left of '.dTargetPostionY' must have class/struct/union type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(70) : error C2109: subscript requires array or pointer type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(70) : error C2228: left of '.dTargetPostionZ' must have class/struct/union type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(71) : error C2109: subscript requires array or pointer type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(71) : error C2228: left of '.dTargetPostionX' must have class/struct/union type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(71) : error C2109: subscript requires array or pointer type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(71) : error C2228: left of '.dTargetPostionY' must have class/struct/union type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(71) : error C2109: subscript requires array or pointer type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(71) : error C2228: left of '.dTargetPostionZ' must have class/struct/union type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(72) : error C2109: subscript requires array or pointer type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(72) : error C2228: left of '.dTargetPostionX' must have class/struct/union type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(72) : error C2109: subscript requires array or pointer type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(72) : error C2228: left of '.dTargetPostionY' must have class/struct/union type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(72) : error C2109: subscript requires array or pointer type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(72) : error C2228: left of '.dTargetPostionZ' must have class/struct/union type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(73) : error C2109: subscript requires array or pointer type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(73) : error C2228: left of '.dTargetPostionX' must have class/struct/union type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(73) : error C2109: subscript requires array or pointer type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(73) : error C2228: left of '.dTargetPostionY' must have class/struct/union type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.cpp(73) : error C2109: subscript requires array or pointer type
D:VC6.0MSDev98MyProjectshuo_pao_sheng721CHuoPaoSheng721.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; 好笨。。。

解决方案二:

你的vector没有加类型,例如:
把vector vTargetState;
改成:vector vTargetState;

解决方案三:

你每个结构体都缺少后花括号 }
怎么搞的。

解决方案四:

请大神帮我看看这段代码
求数据结构大神帮我看看程序!!谢谢!!!
大神帮我看看错了吗??

解决方案五:

大神们,看过来啊~~~···

解决方案六:

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

结构体加个别名试试

时间: 2024-10-31 15:34:09

软件开发-求大神帮我看看C++代码的相关文章

java类的问题-软件开发求大神解答!!

问题描述 软件开发求大神解答!! 如何编写一个java程序,让qq邮箱里面的邮件自动下载到一个指定的文件夹,求各位朋友帮帮忙,需要用到哪些技术 解决方案 用你的程序读取qq,然后下载文件夹,用eclipse等编程软件 解决方案二: 问题是如何读取呢有没有什么建议啊

设计-求大神帮我看一下代码哪里有问题,这是用verilog写的sdram的数据模块

问题描述 求大神帮我看一下代码哪里有问题,这是用verilog写的sdram的数据模块 `timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 12:07:50 04/20/2016 // Design Name: // Module Name: datage

jsp-JSP传给action的是字符串类型,转换数据类型,让getlist()接收,求大神帮帮忙写下代码

问题描述 JSP传给action的是字符串类型,转换数据类型,让getlist()接收,求大神帮帮忙写下代码 JSP传给action的是字符串类型,怎么转换数据类型,然后让getlist()接收,求各位大神帮帮忙写下代码~ 如果能够给解释一下,那就千恩万谢啦 解决方案 可以通过强制转换在前面加上int 解决方案二: gongWenLeiBieList = dao.getList(Integer.parseInt(mingCheng));

求大神帮看一段代码不怎么理解

问题描述 是ADO.NET这一块的相关代码了.程序是声名一个配置文件.然后在程序中调用它.最后显示数据库中的相关数据.虽然我看代码也知道运行的结果但不知道这是什么样一个十字路口.stringdp=ConfigurationManager.AppSettings["provider"];stringcnStr=ConfigurationManager.AppSettings["cnStr"];这两段代码也是以前没见过的,但是看着不难理解应该就是提取配件文件中的值.其中

disk-求大神帮我运行这个代码,操作系统磁盘的直接读写。不知道错误的原因是不是因为没有软盘,

问题描述 求大神帮我运行这个代码,操作系统磁盘的直接读写.不知道错误的原因是不是因为没有软盘, #include //说明sdk的头文件 //#include"floppy.h" #include #include typedef struct disk //Disk是结构体指针 { HANDLE floppyDisk; DISK_GEOMETRY theSupportedGeometry; }*Disk; //以下为程序中用到的四个函数 Disk openfloppy(char dr

用java开发一个安卓客户端在线交流APP,是怎么实现添加好友的?求大神帮我看看这段代码。

问题描述 用java开发一个安卓客户端在线交流APP,是怎么实现添加好友的?求大神帮我看看这段代码. private void submit() { dialog = ProgressDialog.show(this, "提示", "处理中.."); new AsyncTask() { @Override protected String doInBackground(String... params) { String urlString = AppConstan

软件-优盘读取不出来,求大神帮我解决下,谢谢

问题描述 优盘读取不出来,求大神帮我解决下,谢谢 我优盘插别人电脑上能显示,我插自己的显示不了,别人优盘插我电脑上能显示,在驱动人生这个 软件上能显示外部驱动,但就是不显示优盘 解决方案 首先你打开控制面板,找到添加硬件,然后插入你自己的UPAN,然后下添加硬件下一步,跟着提示走,或者自己选择USB某个硬件驱动 解决方案二: 查看电脑的usb接口是都有问题,插入鼠标是否能用

求解答-做web开发,让我在通知管理加一个级别选择字段和排序字段,求大神帮帮忙~

问题描述 做web开发,让我在通知管理加一个级别选择字段和排序字段,求大神帮帮忙~ 级别就是紧急和一般:排序就是按照1.2.3.4...排序.我做的是web开发,系统通知管理的界面,然后紧急通知,首页的通知变红. 解决方案 数据库中通知表中增加这样一个字段,然后在添加通知的时候,将这个字段管理起来,然后前台aspx页面在显示的时候读取该字段,然后让新闻内容变颜色不就可以了嘛

php嵌套循环分类怎么写---求大神帮帮忙呀!

问题描述 php嵌套循环分类怎么写---求大神帮帮忙呀! 鼠标悬停的时候,自动显示大分类下的小分类.(JS已经写出来了,就是php部分不会嵌套) <li class="nav-sub" data-tips="sub-school"> <a href="<{:U('Product/products')}>" class="tit">销售与支持</a> <div class=&