Pseudo Code Examples
Pseudo Code Examples
2. ProNet wholesalers sells 50 KG bags of potatoes. The price per bag is dependent on the number of are sold.
Determine the total price depending on the number of bags sold.
Amount of bags
Price per bag
15
Rs.1250
6 25
Rs.1000
More than 26
Rs. 800
Main
prompt for no_of_bags
get no_of_bags
if (no_of_bags >50)then
print "Sorry we are out of stock"
price_per_bag = 000
else
if ( no_of_bags > 26) then
price_per_bag = 800
elseif(no_of_bags > 6) then
price_per_bag =1000
elseif(no_of_bags <= 5 )then
price_per_bag =1250
else
print "Invalid number"
endif
endif
total_price = no_of_bags * price_per_bag
print "No Of Bags ",no_of_bags,"Price Per Bag",price_per_bag,"Total: "
,total_price
End
3. The charge for domestic energy (electricity) consumption is calculated as on the following table. An
application has to be created to calculate the total charge based on the electricity consumption.
Units
7.85
10.00
27.75
54.00
Main
prompt for units
get units
if (units >124)then
total_charge = units * 54
elseif (units > 93 ) then
total_charge = 62 * 7.85 + 31* 10 +(units-93)* 27.75
elseif (units > 62 ) then
total_charge = 62 * 7.85 +(units-62)* 10
elseif(units <= 62) then
total_charge = units * 7.85
else
print "invalid units"
endif
print "Bill Amount Is :", total_charge
End
4. ProNet postal delivery services needs to calculate the total cost of delivering a parcel. ProNet delivery
charges are based on the weight of the package is on following table
Weight of the package
Charge per Kg
Rs. 1,000
2Kg 6 Kg
Rs. 2,000
6Kg 10Kg
Rs. 3,000
Rs. 3,500
Main
prompt for weight
get weight
if (weight > 10)then
total_cost = weight * 3500
elseif (weight > 6 ) then
total_cost = weight * 3000
elseif (weight >= 2 ) then
total_cost = weight * 2000
elseif(weight < 2) then
total_cost = weight * 1000
else
print "invalid units"
endif
print "Total chrage Is :", total_cost
End
5. Application has to be created to calculate the total cheque processing fee for a fictitious bank. Bank charges
a base fee of Rs. 1000 per month, plus the following cheque fees based on the number of cheques
Number of cheques
Charge
21 39 cheques
40 59 cheques
60 or more
Main
prompt for noOfCheque
get noOfCheque
if (noOfCheque >= 60)then
total_cost = (noOfCheque * 40)+ 1000
elseif (noOfCheque >=40 ) then
total_cost = (noOfCheque * 60)+ 1000
elseif (noOfCheque >= 20 ) then
total_cost = (noOfCheque * 40)+ 1000
elseif(noOfCheque < 20) then
total_cost = (noOfCheque * 100)+ 1000
else
print "invalid units"
endif
print "Total chrage Is :", total_cost
End
6. A student enrolled for an undergraduate course can take one to four subjects per semester. Obtain the
number of subjects and mark for each subject, calculate and display the total and the average of the subjects
attempted that semester.
Main
prompt for noOfSubjects
get noOfSubjects
if (noOfSubjects < 1 or noOfSubjects > 4) then
print " No of Subjects can be 1- 4"
else
counter = 1
total = 0
average = 0
while ( counter <= noOfSubjects)
prompt for marks
get marks
total = total + marks
average = total / counter
counter = counter + 1
endwhile
Print " Total",total,"Average",average
endif
End
7. An average calculator should be created to accept a set of numbers terminated by zero, calculate the
average of the given set of numbers
Main
prompt for how_many_numbers_in_the_set
get how_many_numbers_in_the_set
count = 1
total=0
while(count<= how_many_numbers_in_the_set )
prompt for number
get number
check = number % 10
if((check==0)) then
total = total + number
count = count + 1
else
print "number not terminated by Zero"
count =count-1
endif
endwhile
average = total/count
print "Total: " ,total
print "Average: " ,average
End