Anda di halaman 1dari 9

# QUESTION 2

I-days,rainfall
P-calculate and display total,average and highest value of rainfall data
O-tot_rainfall,ave_rainfall,high_rainfall

Pseuducode
START
days=1
tot_rainfall=0
high_rainfall=0
print enter the number of days
while(days<=30)
printenter the rainfall data
if(high_rainfall<=rainfall)
high_rainfall=rainfall;
tot_rainfall=tot_rainfall+rainball;
days=days+1
endif
average=tot_rainfall/30
print tot_rainfall,average,high_rainfall
STOP
C++ Statement

#include <iostream>

## using namespace std;

int main()
{
int rainfall,days,tot_rainfall=0,high_rainfall=0;
float average;

## cout<<"Please enter the number of days:";

cin>>days;

while(days<=30){
cin>>rainfall;
if(high_rainfall<=rainfall){
high_rainfall=rainfall;
tot_rainfall=tot_rainfall+rainfall;
days=days+1;}

}
average=tot_rainfall/30;
cout<<"Total rainfall is:"<<tot_rainfall<<endl;
cout<<"Average rainfall is:"<<average<<endl;
cout<<"The highest rainfall is:"<<high_rainfall;

return 0;
}

Question 1
Input-num_guests,day,room_type
Proses-to determine whether the room_type is S or D and day is 1 or 2 and calculate the total room
charges.
Output-tot_charge

Pseudocode

Start
counter=1
tot_charge=0
while(counter<=num_guests)
if(room_type=='S'&&day==1)
tot_charge=tot_charge+200
else
if(room_type=='S'&&day==2)
tot_charge=tot_charge+(200*1.2)
else
if(room_type=='D'&&day==1)
tot_charge=tot_charge+(280*num_guest)
else
tot_charge=tot_charge+(280*1.2*num_guest)
endif
endif
endif
counter=counter+1
print tot_charge
Stop
C++ statement

#include <iostream>

## using namespace std;

int main()
{
int num_guest,day=1||2,tot_charge=0,c=1;
char room_type='S'||'D';
cout<<" please enter the number of guest: ";
cin>>num_guest;
while(c<=num_guest){
cout<<"please enter the room type: ";
cin>>room_type;
cin>>day;
if(room_type=='S'&&day==1)
tot_charge=tot_charge+200;
else
if(room_type=='S'&&day==2)
tot_charge=tot_charge+(280*1.2);
else
if(room_type=='D'&&day==1)
tot_charge=tot_charge+(280*num_guest);
else
tot_charge=tot_charge+(280*1.2*num_guest);
c=c+1;}
cout<<"The total charge is:RM"<<tot_charge;
return 0;
}

QUESTION 3
INPUT-API
PROCESS-To determine the maximum API reading and its corresponding status
OUTPUT-MaxAPI,status
Pseuducode
Start
hour=1
MaxAPI=0
while(hour<=24)
if(MaxAPI<=API)
MaxAPI=API
else
if(MaxAPI <=50)
display the status is good"
else
if(MaxAPI <=100)
display the status is moderate"
else
if(MaxAPI <=200)
display the status is unhealthy"
else
if(MaxAPI <=300)
display the staus is very unhealthy"
else
display the status is hazardous"
endif
endif
endif
endif
endif
hour=hour+1
print maxAPI
Stop

C++ Statement
#include <iostream>
using namespace std;

int main()
{
int API,hour=1,MaxAPI=0;
string status;

## cout <<"please enter the hour: " << endl;

cin>>hour;

while(hour<=24){
cin>> API;
if(MaxAPI<=API)
MaxAPI=API;
else
if(MaxAPI <=50)
status="good";
else
if(MaxAPI <=100)
status="moderate";
else
if(MaxAPI <=200)
status="unhealthy";
else
if(MaxAPI <=300)
status="very unhealthy";
else
status="hazardous";

hour=hour+1;}
cout<<"The maximum API is "<< MaxAPI<<endl;
cout<<"The status is " <<status

return 0;
}

Question 4
INPUT-code,
PROCESS-determine whether the code is K or I or P or Z or not and calculate the totalprice.
OUTPUT-totalprice

Pseuducode

Start
totalKL=0
totalIP=0
totalPP=0
while(code!='Z')
if(code=='K')
totalKL=totalKL+1
totalprice=totalprice+8.00
else
if(code=='I')
totalIP=totalIP+1
totalprice=totalprice+18.00
else
if(code=='P')
totPP=totPP+1
totalprice=totalprice+24.00
else
Print "INVALID CODE"
Display enter destination code
endif
endif
endif
Print totalprice
Stop
C++ Statement
#include <iostream>

## using namespace std;

int main()
{
int totalKL=0,totalIP=0,totPP=0;
float totalprice=0;
char code='K'||'I'||'P'||'Z';
cout<<"Code:\n"<<"Kuala Lumpur(KL)\n"<<"Ipoh
(I)\n"<<"Pulau Pinang(P)\n";
cout<<"enter destination code:";
cin>>code;
while(code!='Z'){
if(code=='K'){
totalKL=totalKL+1;
totalprice=totalprice+8.00;}
else
if(code=='I'){
totalIP=totalIP+1;
totalprice=totalprice+18.00;}
else
if(code=='P'){
totPP=totPP+1;
totalprice=totalprice+24.00;}
else
cout<<"INVALID CODE"<<endl;
cout<<"enter destination code:";
cin>>code;}

## cout<<"Passenger to KL:"<<totalKL<< endl;

cout<<"Passenger to Ipoh:"<<totalIP<<endl;
cout<<"Passenger to Pulau Pinang:"<<totPP<<endl;
cout<<"Total ticket price: RM "<<totalprice;
return 0;
}