[Cpp]
// Average annual traffic and Annual Extreme flood. h
Void NianJunZhi ()
{
Using namespace std;
Ofstream outfile;
Outfile. open ("outfile_yearq_cmdtxt ");
Outfile <setw (10) <"year" <setw (10) <"days" <setw (10) <"average annual traffic ";
For (int k = 0; k <J; k ++)
Outfile <setw (7) <"maximum" <NumJ [k] <"day ";
Outfile <endl;
Ifstream infile;
Infile. open ("infile_DayQ.txt ");
For (int I = 0; I <Y; I ++)
{
Year = StartYear + I;
SumDay [I] = Sum [12]; // Initialization
If (Year = StartYear)
SumDay [I]-= (Sum [StartMonth-1] + StartDate-1 );
If (Year = EndYear)
SumDay [I] = Sum [EndMonth-1] + EndDate;
If (Year % 400 = 0 | (Year % 4 = 0 & Year % 100! = 0 ))
{
If (Year = StartYear & StartMonth <2) SumDay [I] ++;
If (Year = EndYear & EndMonth> 2) SumDay [I] ++;
If (Year! = StartYear & Year! = EndYear) // & amp; SumDay [I] = Sum [12]
SumDay [I] ++; // a leap year with a day added in February
}
YearQ [I] = 0; // Initialization
For (int j = 0; j <SumDay [I]; j ++)
{
Infile> Q [j];
YearQ [I] + = Q [j];
}
YearQ [I]/= SumDay [I];
Outfile <setw (10) <Year <setw (10) <SumDay [I] <setw (10) <YearQ [I];
For (int k = 0; k <J; k ++)
{// Calculate the Annual Extreme flood
MaxYearW [I] [k] = 0; // Initialization
For (int j = 0; j <SumDay [I]-NumJ [k] + 1; j ++)
{
Temp_W = 0; // Initialization
For (int n = 0; n <NumJ [k]; n ++)
Temp_W + = Q [j + n];
If (temp_W> MaxYearW [I] [k])
MaxYearW [I] [k] = temp_W; // (m3/s * month)
}
Outfile <setw (10) <MaxYearW [I] [k];
} Www.2cto.com
Outfile <endl;
}
Infile. close ();
Outfile. close ();
}
By: Superwen_go