地震监测系统(简单实现)
#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 2022-07-25 11:25 会飞的鱼-blog 阅读(17) 评论(0) 编辑 收藏 举报 来源
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现