0% found this document useful (0 votes)
25 views16 pages

Pseudocode

The pseudocode provides steps to input marks for multiple students into an array, then calculate and output the highest, lowest and average marks. It includes logic to handle an unknown class size by inputting the size. Additional pseudocode is provided to calculate grades (distinction, merit, pass, fail) based on average marks and output results for each student.

Uploaded by

The Basics
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views16 pages

Pseudocode

The pseudocode provides steps to input marks for multiple students into an array, then calculate and output the highest, lowest and average marks. It includes logic to handle an unknown class size by inputting the size. Additional pseudocode is provided to calculate grades (distinction, merit, pass, fail) based on average marks and output results for each student.

Uploaded by

The Basics
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Pseudocode

Q. Write a pseudocode to input some positive numbers and display the total and counting of those
numbers.
Arrays
Same datatype and name for many values

DECLARE mark: ARRAY[0:9] OF INTEGER

mark mark mark mark mark mark mark mark mark mark
5 6 7 100 23 9 1 25 34 76
0 1 2 3 4 5 6 7 8 9

5,6,7,100,23,9,1,25,34,76

DECLARE mark: ARRAY[0:9] OF INTEGER

//Write in an array

OUTPUT “ Enter these values in order 5,6,7,100,23,9,1,25,34,76”

FOR Counter = 0 TO 9

OUTPUT “ Enter the value”

INPUT mark[Counter]

NEXT Counter

//read from an array

FOR Counter = 0 TO 9

OUTPUT mark[Counter]

NEXT Counter

1. Calculate and output highest, lowest, average for a class of 10 students.


mark mark mark mark mark mark mark mark mark mark
5 6 7 100 23 9 1 25 34 76
0 1 2 3 4 5 6 7 8 9

DECLARE mark: ARRAY[0:10] OF INTEGER

Highest= 0

Lowest=100

Total= 0

Counter=0

Classsize=0

Output “Enter the number of students in the class”

Input classSize

FOR counter = 0 to 10

Total=Total+ mark[counter]

If mark[counter] > highest

Then

Highest= mark[counter]

Endif

If mark[counter] < lowest

Then

Lowest = mark[counter]

Endif

NEXT Counter

Output highest

Output lowest

Output total/10
#Calculate and output highest, lowest, average for unknown classsize.
DECLARE mark: ARRAY[0:50] OF INTEGER

Highest= 0

Lowest=100

Total= 0

Counter=0

Classsize=0

Output “Enter the number of students in the class”

Input classSize

FOR counter = 0 to classSize

Total=Total+ mark[counter]

If mark[counter] > highest

Then

Highest= mark[counter]

Endif

If mark[counter] < lowest

Then

Lowest = mark[counter]

Endif

NEXT Counter

Output highest

Output lowest

Output total/classSize
//Declaring all the variables with meaningful names
DECLARE TotalMark : ARRAY[1:50] OF INTEGER
DECLARE AverageMark : ARRAY[1:50] OF INTEGER
DECLARE SubjectCounter, StudentCounter, DistinctionNo, MeritNo, PassNo, FailNo :
INTEGER

CONSTANT Distinction = 70
CONSTANT Merit = 55
CONSTANT Pass = 40

//Inititalising all the variables

DistinctionNo = 0
MeritNo = 0
PassNo = 0
FailNo = 0

FOR StudentCounter = 1 to Classsize


TotalMark[StudentCounter] = 0
NEXT StudentCounter

FOR StudentCounter = 1 to Classsize


FOR SubjectCounter = 1 to SubjectNo
TotalMark[StudentCounter] = TotalMark[StudentCounter] +
StudentMark[StudentCounter , SubjectCounter]/
NEXT SubjectCounter

AverageMark[StudentCounter] = INT((TotalMark[StudentCounter]/SubjectNo)
OUTPUT "Name" , StudentName[StudentCounter]
OUTPUT "Combined Total Mark" , TotalMark[StudentCounter]
OUTPUT "Average Mark" , AverageMark[StudentCounter]

IF AverageMark[StudentCounter] >= Distinction THEN


DistinctionNo = DistinctionNo+1
OUTPUT "Grade Distinction"
ELSE
IF AverageMark[StudentCounter] >= Merit THEN
MeritNo = MeritNo+1
OUTPUT "Grade Merit"
ELSE
IF AverageMark[StudentCounter] >= Pass THEN
PassNo = PassNo+1
OUTPUT "Pass"
ELSE
FailNo = FailNo+1
OUTPUT "FAIL"
ENDIF
ENDIF
ENDIF

NEXT StudentCounter

OUTPUT "Total Number Of Distinctions" , DistinctionNo


OUTPUT "Total Number Of Merit" , MeritNo
OUTPUT "Total Number Of Pass" , PassNo
OUTPUT "Total Number Of Fail" , FailNo
Requirement:
Total points each team - totalling
Type of win- if else
Display name, total points, total number of away, wins, drawn, lost
Name of the with max
Name of the team with min

Provided:
Teamname[leaguesize]
TeamName
Team A Team B Team C Team D Team E
Teampoints[matchno][leaguesize]
Total points(tbc)
Team A 3 2 3 1+2+3……..= total
(1,1) (1,2) (1,3)

Team B Run in first match Run in 2match 1+2+3……..


(2,1) (2,2)

Team C Run in first match Run in 2 match 1+2+3……..


(3,1)

League size

TeamPoints[teamcounter, matchcounter]

Total points - type of win


Matchno- number of matches
Leaguesize - number of teams

Rules: Always make two counters for traversing 2D arrays.


DECLARE TeamCounter : INTEGER
DECLARE MatchCounter : INTEGER

Rule 2: Declare all the variables for which totals need to be displayed.
Output1 : counts the total number of away wins, home wins, drawn matches and lost matches
for each team
Output 2: total points
DECLARE TeamPoints : INTEGER
DECLARE AwayWinNo : INTEGER
DECLARE HomeWinNo : INTEGER
DECLARE DrawNo : INTEGER
DECLARE LostNo : INTEGER

Rule 3: Declare variables for highest and lowest or max and min.

DECLARE HighestPoints : INTEGER


DECLARE LowestPoints : INTEGER
DECLARE TopTeam : INTEGER
DECLARE BottomTeam : INTEGER

Note: Spot the word ‘all’ in the output for declaring array and ‘each’ for declaring variable.

Rule: Constants will be declared for each comparison value like grades or points

Constant awaywin = 3
Constant homewin = 2
Constant drawnmatch = 1
Constant lostmatch = 0

calculates the total points for all matches played for each team
DECLARE ARRAY : TotalPoints[1:leaguesize]

0 0 0 0 0 0 0 0 0
TotalPoints

// Initialization
FOR TeamCounter= 1 to leaguesize
TotalPoints[TeamCounter] = 0
NEXT TeamCounter

awayno, homeno, drawno, lostmatch= 0

Highestpoints = 0
lowestpoint=1000

FOR TeamCounter = 1 to leaguesize //outerloop


awayno, homeno, drawno, lostmatch= 0
FOR Matchcounter = 1 to matchno //innerloop
Totalpoints[TeamCounter]= totalpoint[teamcounter]+ teampoints[teamcounter,
matchcounter]
Case OF Teampoints[teamcounter, matchcounter]
awaywin: awayno=awayno+1
Homewin: homeno=homeno+1
Drawnmatch: drawno=drawno+1
Lostmatch: lostno=lostno+1
EndCase
NEXT Matchcounter
Output “The team name is”, Teamname[teamcounter]
Output “The total points is “, TotalPoints[teamcounter]
Output “Number of away win= “, awayno
Output “Number of home win= “, homeno
Output “Number of draw match= “, drawno
Output “Number of lostmatch= “, lostno
Next TeamCounter

// Check for highest and lowest results


ew

You might also like