当前位置:编程学习 > C/C++ >>

水资源开发利用——兴利调节模拟计算法

[cpp] 
//兴利调节模拟计算.cpp 
//通过额定供水量(此程序中为固定值)求有效库容 
//或通过有效库容求额定供水量(求得结果为定值) 
//来水过程已知,从已经划分好水利年的入库流量读取 
//用水保证率已知 
#include "stdafx.h" 
#include <fstream> 
#include<iostream> 
#include<iomanip> 
 
int T;//系列资料长度,单位:年 
int DestroyYear, DestroyMonth;//用水不足,破坏 
double  M,//额定用水流量系列,单位:m/s 
    Vx;//兴利库容,单位:(m/s*月) 
double P,//用水保证率 
    S[13],//兴利库容存水量,单位:(m/s*月) 
    X[12],//来水流量系列,单位:m/s 
    D[12];//库泄流量(实际用水量+超过最大过水能力的弃水)系列,单位:m/s 
int Judge;//判断数 
double Value, Left, Right;//待求值及其阈值 
int Num;//试算次数 
 
void main() 

    using namespace std; 
    ofstream outfile; 
    outfile.open("outfile.txt"); 
    cout<<"输入系列长度(年):"<<endl; 
    cin>>T; 
    cout<<"求有效库容请输入,求额定用水流量输入:"<<endl; 
    cin>>Judge; 
    cout<<"请输入已知的效库容(m/s*月)或额定用水流量的值:"<<endl; 
    if(Judge == 0)//求有效库容 
    { 
        cin>>M; 
        outfile<<setw(10)<<"有效库容"<<setw(10)<<"供水保证率"<<endl; 
    } 
    if(Judge == 1) //额定用水流量 
    { 
        cin>>Vx; 
        outfile<<setw(10)<<"额定用水流量"<<setw(10)<<"供水保证率"<<endl; 
    } 
    cout<<"输入待求值的下限:"<<endl; 
    cin>>Left; 
    cout<<"输入待求值的上限:"<<endl; 
    cin>>Right; 
    cout<<"输入试算次数:"<<endl; 
    cin>>Num; 
    for(int n = 0; n <= Num; n++) 
    {//等差试算有效库容 
        ifstream infile_X; 
        infile_X.open("infile_X.txt"); 
        Value = (Right - Left)/Num*n + Left; 
        if(Judge == 0) Vx = Value; 
        else M = Value; 
        S[0] = DestroyYear = 0; 
        for(int year = 0; year < T; year++) 
        { 
            DestroyMonth = 0; 
            for(int t = 0; t < 12; t ++) 
            {//读入已按水利年分配的月来水流量 
                infile_X>>X[t]; 
                if(S[t]+X[t] < M) 
                {//破坏月 
                    D[t] = S[t]+X[t]; 
                    DestroyMonth++; 
                } 
                else  
                    if (S[t]+X[t]< M + Vx) 
                    D[t] = M;//正常供水段,未蓄满 
                    else D[t] = S[t] + X[t] - Vx;//加大泄水段,已蓄满 
                S[t + 1] = S[t] + X[t] - D[t]; 
                if(t == 11) S[0] = S[t + 1]; 
            }      www.zzzyk.com
            if(DestroyMonth > 0) DestroyYear++; 
        } 
        infile_X.close(); 
        P = 1 - (double)DestroyYear/T; 
        outfile<<setw(10)<<Value<<setw(10)<<P<<endl;       
    } 
    outfile.close(); 

输入文件:"infile_X.txt"
717 615 265 1500 215 162 191 136 107 104 120 312
545 1540 410 873 1510 1110 621 288 165 85 130 450
483 592 590 958 236 182 797 369 115 190 127 133
783 1440 1600 2860 1480 142 195 91 139 100 159 341
262 957 2310 446 652 336 106 112 52 56 96 146
584 1340 390 479 641 228 161 75 44 140 226 205
717 844 652 1010 1450 85 85 203 322 148 95 153
417 1600 631 936 1130 507 791 128 77 65 244 368
746 708 789 276 154 122 157 398 218 110 117 240
430 525 1260 1210 130 187 90 270 65 46 60 766
568 371 442 389 227 138 421 728 257 167 114 272
540 1250 1500 506 545 361 425 504 316 106 88 85
953 1470 813 1630 1240 119 464 619 247 300 179 479
1290 1150 2090 747 543 584 623 311 120 93 94 139
636 490 626 310 511 630 690 151 169 86 121 123
684 282 872 395 162 70 484 138 72 60 186 369
493 2010 1650 11

补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,