fqy131314

地震监测系统(简单实现)

#include <iostream>
#include <string>
#include <cmath>
#include <Windows.h>
#include <fstream>

using namespace std;

const double THRESHOLD=1.5;
double sy_check(double arr[],int length,int n)
{
    double XSqrt=0;
    for(int i=0;i<n;i++)
    {
        XSqrt+=pow(arr[length-i],2);
    }
    
    return XSqrt/n;
}

int main(void)
{
    string filename;
    ifstream fin;
    int num,long_window=0,weight_window=0;
    double time_cr=0,*sensor=NULL,weight_power=0,long_power=0;
    double ratio;

    cout<<"Please input your file name:";
    cin>>filename;

    fin.open(filename.c_str());

    if(fin.fail())
    {
        cout<<"Enter file of name"<<endl;
        exit(-1);
    }else
    {
        fin>>num>>time_cr;
        
        if(num>=0)
        {
            sensor=new double[num];

            for(int i=0;i<num;i++)
            {
                fin>>sensor[i];
            }
        
            cout<<"请输入长时间:"<<endl;
            cin>>long_window;

            cout<<"请输入短时间:"<<endl;
            cin>>weight_window;

            for(int i=long_window-1;i<num;i++)
            {
                long_power=sy_check(sensor,i,long_window);
                weight_power=sy_check(sensor,i,weight_window);
                
                ratio=weight_power/long_power;

                if(ratio>THRESHOLD)
                {
                    cout<<"Possible event at"<<time_cr*i<<"seconds\n";
                }

                
            }
            //这条语句要在for外面
            delete[] sensor;
        }

        
            
            fin.close();

    }

    system("pause");
    return 0;
}

运行结果:

posted on   会飞的鱼-blog  阅读(17)  评论(0编辑  收藏  举报  

相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示