Académique Documents
Professionnel Documents
Culture Documents
WEATHER PROGRAM
Given the following weather review for period November 2017 to February 2018, State, Duration and Monthly Rainfall Estimation as follows:
//prototype function
void chooseMenu(short &menu);
void callSel(char *state[], char *tempoh[], int hjnSelmin[], int hjnSelmax[] );
void callMel(char *state[], char *tempoh[], int hjnSelmin[], int hjnSelmax[] );
void callTG(char *state[], char *tempoh[], int hjnSelmin[], int hjnSelmax[] );
void SelMMX(char *state[], char *tempoh[], int hjnSelmin[], int hjnSelmax[] );
void TGMMX(char *state[], char *tempoh[], int hjnTGmin[], int hjnTGmax[] );
void callMel(char *state[], char *tempoh[], int hjnMelmin[], int hjnMelmax[]);
void callExit(int &resp);
void callSignature();
int callError();
bool callRepeat(int no, int menu);
void Summary(char *state[], char *tempoh[], int S1[],int S2[],int M1[],int M2[], int T1[],int T2[]);
//main() function
int main()
{
int menu, no ;
bool resp;
resp = 1;
//repetition statements
while (resp)
{
chooseMenu(menu); //function call for chooseMenu()
//selection statements
switch (menu)
{
case 1 : callSel(state, tempoh, hjnSelmin, hjnSelmax ); //function call for callSel()
resp = callRepeat(no,menu);
break;
case 2 : callMel(state, tempoh, hjnMelmin, hjnMelmax); //function call for callMel()
resp = callRepeat(no,menu);
break;
case 3 : callTG(state, tempoh, hjnTGmin, hjnTGmax); //function call for callTG()
resp = callRepeat(no,menu);
break;
case 4 : Summary(state, tempoh, hjnSelmin, hjnSelmax, hjnMelmin, hjnMelmax,hjnTGmin, hjnTGmax);
resp = callRepeat(no,menu);
break;
case 5 : callExit(resp); //function call for callExit()
break;
default : resp = callError(); //function call for callExit()
resp = callRepeat(no,menu);
break;
}//switch
} //while
callSignature(); //function call for callSignature()
return 0;
}
system("cls");
printf("\t=====================================\n");
printf("\t== WEATHER REVIEW FOR PERIOD ==\n");
printf("\t== November 2017 TO FEBRUARY 2018 ==\n");
printf("\t=====================================\n\n");
printf("\tSelect State\n");
printf("\t[1] Selangor\n");
printf("\t[2] Melaka\n");
printf("\t[3] Terengganu\n");
printf("\t[4] Summary\n");
printf("\t[5] Exit\n\n\n");
scanf("%d",&menu);
printf("\tYou have select number #0%d\n\n",menu);
//function definition for callSel()with no return value that accepts four parameters
void callSel(char *state[], char *tempoh[], int hjnSelmin[], int hjnSelmax[] )
{
int i;
printf ("\tNegeri : %s\n", state[0]);
printf("\n\tTempoh \t Monthly Rainfall Expected (mm)\n");
printf("\n\t====== \t ==============================\n");
for (i = 0; i < MAX ; i++) {
printf("\t%s\t \t%d - %d\n",tempoh[i],hjnSelmin[i],hjnSelmax[i]);
}
printf("\n\n");
}
//function definition for callMel()with no return value that accepts four parameters
void callMel(char *state[], char *tempoh[], int hjnMelmin[], int hjnMelmax[] )
{
int i;
printf ("\tNegeri : %s\n", state[1]);
printf("\n\tTempoh \t Monthly Rainfall Expected (mm)\n");
printf("\n\t====== \t ==============================\n");
for (i = 0; i < MAX ; i++) {
printf("\t%s\t \t%d - %d\n",tempoh[i],hjnMelmin[i],hjnMelmax[i]);
}
printf("\n\n");
}
//function definition for callTG()with no return value that accepts four parameters
void callTG(char *state[], char *tempoh[], int hjnTGmin[], int hjnTGmax[] )
{
int i;
printf ("\tNegeri : %s\n", state[2]);
printf("\n\tTempoh \t Monthly Rainfall Expected (mm)\n");
printf("\n\t====== \t ==============================\n");
for (i = 0; i < MAX ; i++) {
printf("\t%s\t \t%d - %d\n",tempoh[i],hjnTGmin[i],hjnTGmax[i]);
}
printf("\n\n");
}
// function definition for MelMMX() to find the minimum and maximum value of the Rainfall Estimates for
// the state of Melaka and display the values on the screen
void MelMMX(char *state[], char *tempoh[], int hjnMelmin[], int hjnMelmax[] )
{
int i, lowMel, highMel, hold1, hold2;
lowMel = hjnMelmin[0];
for (i = 1; i < MAX ; i++) {
if (hjnMelmin[i] < lowMel){
lowMel = hjnMelmin[i];
hold1 = i;
}
}
highMel = hjnMelmax[0];
for (i = 1; i < MAX ; i++) {
if (hjnMelmax[i] > highMel){
highMel = hjnMelmax[i];
hold2 = i;
}
}
printf("\n\n");
}
// function definition for SelMMX() to find the minimum and maximum value of the Rainfall Estimates for
// the state of Selangor and display the values on the screen
lowSel = hjnSelmin[0];
for (i = 1; i < MAX ; i++) {
if (hjnSelmin[i] < lowSel){
lowSel = hjnSelmin[i];
hold1 = i;
}
}
highSel = hjnSelmax[0];
for (i = 1; i < MAX ; i++) {
if (hjnSelmax[i] > highSel){
highSel = hjnSelmax[i];
hold2 = i;
}
}
printf("\n\n");
}
// function definition for TGMMX() to find the minimum and maximum value of the Rainfall Estimates for //
the state of Terengganu and display the values on the screen
lowTG = hjnTGmin[0];
for (i = 1; i < MAX ; i++) {
if (hjnTGmin[i] < lowTG){
lowTG = hjnTGmin[i];
hold1 = i;
}
}
highTG = hjnTGmax[0];
for (i = 1; i < MAX ; i++) {
if (hjnTGmax[i] > highTG){
highTG = hjnTGmax[i];
hold2 = i;
}
}
printf("\n\n");
}
else
return resp = 1;
}