ICT/2022/139

R.S.R. Ranathunga

 Tutorial 04 & 05(Pseudocode)

1. Generate students repot as shown below. 

Index Number Name Mathematics Physics Chemistry Total Average Grade

 In this task list, for each student you must input marks of three subjects. Students’ grade is determined according to following criteria: 
• Average >= 90%: Grade A 
• Average >= 80%: Grade B 
• Average >= 70%: Grade C 
• Average >= 60%: Grade D 
• Average >= 40%: Grade E  
• Average < 40%: Grade F 

1) What output do you need to generate? Display a student report -Index number, Name, Mathematics 
subject marks as M, Physics subject marks as P, Chemistry subject marks as C , Total, Average, Grade 

2) What input do you have/ need? Index number, Name, Mathematics subject marks as M, Physics subject marks as P, Chemistry subject marks as C 

3) What form will it be in? Index number as String, Name as Text, Mathematics subject marks as Integer, Physics subject marks as integer, Chemistry subject marks as integer 

4) Will the program have a list of tasks that needs to be done repeatedly (LOOP)? Yes 

Loop control variable- n 
Initial value of the loop control variable- n=1 
Loop control condition- n<=S 
Repetitive statements- Display Index number, Name, M, P, C, Total, Average, Grade Display “\n” Increment the loop control variable- n=n+1 



Pseudocodes 

BEGIN 
SET Total=0 
SET Average=0 
SET Grade=0 
SET n=0 
SET S=X 
DISPLAY("Index Number \t Name \t Mathematics \t Physics \t Chemistry \t Total \t Average \t Grade") DISPLAY "\n" DISPLAY("_____________________________________________________________ _______________________________") 

DISPLAY "\n" 
WHILE n<=S 
INPUT Index number 
INPUT Name 
INPUT M 
INPUT P 
INPUT C 
Total=(M+P+C) 
Average=Total/3 
IF Average>=90 THEN 
Grade=A ELSE 
IF Average>=80 THEN 
Grade=B ELSE 
IF Average>=70 THEN 
Grade=C ELSE 
IF Average>=60 THEN 
Grade=D ELSE 
IF Average>=40 THEN 
Grade=E ELSE 
Grade=F 
DISPLAY Index+"\t"number+"\t"Name+"\t"M+"\t"P+"\t"C+"\t"Total+"\t"Average+"\t"Grade DISPLAY “\n” 
END IF  
END ELSE IF 
END ELSE IF 
END ELSE IF 
END ELSE IF 
n=n+1 
END WHILE 
END 

Algorithm 
BEGIN 
DECLARE variable as Total 
DECLARE variable as Average 
DECLARE variable as Grade 
DECLARE variable as n 
DECLARE variable as S 
SET Total to 0 
SET Average to 0 
SET Grade to 0 
SET n to 0 
SET S to X 
DISPLAY("Index Number \t Name \t Mathematics \t Physics \t Chemistry \t Total \t Average \t Grade") DISPLAY “\n” 
WHILE n equal or lower than S 
GET values for Index number, Name, M, P, C 
CALCULATE Total by multiplying M,P and C 
CALCULATE Average, dividing Total by 3 
IF, Average is equal or greater than 90,then A assign to Grade 
ELSE IF, Average is equal or greater than 80,then B assign to Grade 
ELSE IF, Average is equal or greater than 70,then C assign to Grade 
ELSE IF, Average is equal or greater than 60,then D assign to Grade 
ELSE IF, Average is equal or greater than 40,then E assign to Grade 
ELSE Average is lower than 40,then F assign to Grade 
DISPLAY Index+"\t"number+"\t"Name+"\t"M+"\t"P+"\t"C+"\t"Total+"\t"Average+"\t"Grade DISPLAY “\n” 
END IF 
END ELSE IF 
END ELSE IF 
END ELSE IF 
END ELSE IF 
ADD 1 to n 
END WHILE 
END 

2. Assume a village has 20 houses. Input electricity unit charges and calculate total electricity bill according to the following criteria: 

• For first 50 units Rs. 0.50/unit 

• For next 100 units Rs. 0.75/unit 

• For next 100 units Rs. 1.20/unit 

• For unit above 250 Rs. 1.50/unit 

 An additional surcharge of 20% is added to the bill The output should be as follows: 

 Serial Number: House Address Units Surcharge Amount to be paid 

1) What output do you need to generate? Display total electricity bill -Serial number , House address , Unit charges as Units, Surcharge ,Amount to be paid as Total Bill 

2) What input do you have/ need? 

Unit charges as Units, 

Serial Number, 

House Address 

3) What form will it be in? Unit charges as Integer, Serial Number as String, House Address as String 

4) Will the program have a list of tasks that needs to be done repeatedly (LOOP)? Yes 

Loop control variable- Count 

Initial value of the loop control variable- Count=1 

Loop control condition- Count<=20 

Repetitive statements-Surcharge=Bill*(20/100) Total Bill= Bill + Surcharge Display Serial number, House address, Units, Surcharge, Total Bill Display “\n” 

Increment the loop control variable- Count=Count+1 

5) What are the other major tasks of the program? 

Declare a variable as Bill, Set value as 0 

Declare a variable as Total Bill, Set value as 0 

Declare a variable as Surcharge, Set value as 0 

Declare a variable as Count, Set value as 1 

Display “Serial Number:”, “House Address”, “Units”, “Surcharge”, “Amount to be paid” 




Pseudocode 

BEGIN 

SET Bill=0 

SET Total_Bill=0 

SET Surcharge=0 

SET Count=1 

DISPLAY(“Serial Number \t House Address \t Units \t Surcharge \t Amount to be paid”) 

DISPLAY “\n” 

WHILE Count<=20 

INPUT Units 

INPUT Serial Number 

INPUT House Address 

IF Units>250 THEN Bill=220+(Units-250) *1.5 

ELSE IF Units>150 THEN Bill=100+(Units-150) *1.2 

ELSE IF Units>50 THEN Bill=25+(Units-50) *0.75 

ELSE Bill=Units * 0.5 

Surcharge=Bill*(20/100) 

Total_Bill=Bill + Surcharge 

Display Serial number+"\t"House+"\t"address+"\t"Units+"\t"Surcharges+"\t"Total_Bill 

Display “\n” 

END IF 

END ELSE IF 

END ELSE IF Count=Count+1 

END WHILE 

END 


Algorithm 

BEGIN 

DECLARE a variable as Bill 

DECLARE a variable as Total Bill 

DECLARE a variable as Surcharge 

DECLARE a variable as Count 

SET Bill to 0 SET Total_Bill to 0 

SET Surcharge to 0 SET Count to 1 

DISPLAY (“Serial Number \t House Address \t Units \t Surcharge \t Amount to be paid”) 

DISPLAY “\n” 

WHILE Count is equal of lower than 20 Get values for Units, Serial Number, House Address 

IF Units is greater than 250, THEN Bill=220+(Units-250) *1.5 

ELSE IF Units is greater than 150, THEN Bill=100+(Units-150) *1.2 

ELSE IF Units is greater than 50, THEN Bill=25+(Units-50) *0.75 

ELSE Bill=Units * 0.5 

Surcharge=Bill*(20/100) 

Total Bill=Bill + Surcharge 

Display Serial number+"\t" House+"\t" address+"\t" Units+"\t" Surcharges+"\t" Total_Bill 

Display “\n” 

END IF 

END ELSE IF 

END ELSE IF 

ADD 1 to Count 

END WHILE 

END 










Comments