You are on page 1of 9

Programming

Pascal
Problem Solving
Phase
Defining Diagram
INPUT PROCESSING OUTPUT
House Names: House_funds $140,000 Total_points
house[i] i 1 to 4 low_house_nam
House points: Read house[i] e
points [i] Read points[i] low_house_poin
Calculate total points ts
Total_points points[i]+ high_house_na
Total_points me
Determine the house with the high_house_poi
highest and lowest points nts
Calculate funds for the house high_house_fun
with the highest and lowest ds
points low_house_fun
low_house_funds 17% of ds
House_funds
high_house_funds 45% of
House_funds
Print Total_points
Print House name, points and
house funds

Algorithm without Steps


Algorithm Fund_Distribution

{This algorithm accepts the names and points scored for each house,
calculates the total points amassed, determines the house with the house and
lowest points, calculates the percentage of funds that go to the houses with the
highest and lowest points, outputs the total points scored and the names and
points of the two houses and the respective amounts earned.}

{Created by: Jayda Hunte}


[Date Created: 31.01.15}

Var
house: array[1..4]of string { Declaration of arrays}
points: array[1..4]of integer
Total_points: integer {Declaration of variables}
i: integer
low_house_points, high_house_points: integer
high_house_name, low_house_name: integer
high_house_funds, low_house_funds, house_funds: real

START
high_house_funds 0 {Initializing of variables}
low_house_funds 0
high_house_points 0
low_house_points 9999 {Variable initialized to value greater
than house
Total_points 0 points}
house_funds $140,000 {Variable initialized to value of house
fund}
high_house_name
low_house_name

For i 1 to 4 DO {For loop used to initialize the arrays}


House[i]
Points[i] 0
Endfor
For i 1 to 4 DO {For loop used to display 4 houses and
respective
Start points and funds earned}

Print Enter house name {Prompts user to enter house name into
the array}
read house [i]
Print Enter points scored by house {Prompts user to enter points
scored
read points [i] by each house into the array}

While points[i] < 0 Do {Condition: While the values in the array


points[i]
are greater than zero the algorithm
continues
else displays, This Value is invalid}

Print This value is invalid


Print Enter points scored by house {Prompts user to enter points scored
read points [i] by each house into the array}

Endwhile
Total_points points[i] + Total_points {Calculating the total points
amassed}
If points[i] > high_house_points Then {This IF statement works out
the house
high_house_points points[i] with the highest points }
high_house_house house[i]
Endif

If points[i] < low_house_points Then {This IF statement works out


the house
low_house_points points[i] with the lowest points}
low_house_name house[i]
Endif
high_house_funds (45/100) * 140,000 {Calculates the funds allocated
to
low_house_funds (17/100) *140,000 highest and lowest house]
Stop
Print The total points scored is, Total_points
{The total points scored
displayed}
Print high_house_name, is the highest house and earned,
high_house_points and gained, high_house_funds, from the sports fund
{The highest house, the points they scored and the
amount of cash received from the sports fund displayed}

Print low_house_name, is the lowest house and earned,


low_house_points and gained, low_house_funds, from the sports fund
{The lowest house, the points they scored and the amount
of cash received from the sports fund
displayed}
STOP
Program Fund_Distribution;

{This algorithm accepts the names and points scored for each house, calculates the total points
amassed, determines the house with the house and lowest points, calculates the percentage of funds
that go to the houses with the highest and lowest points, outputs the total points scored and the
names and points of the two houses and the respective amounts earned.}

{Created by: Jayda Hunte}

{Date Created: 31.01.15}

Var

house: array[1..4]of string;


points: array[1..4]of integer;
Total_points: integer;
i:integer;
low_house_points, high_house_points: integer;
high_house_name, low_house_name: string;
high_house_funds, low_house_funds, house_funds :real;

BEGIN
high_house_funds:=0;
low_house_funds:=0;
high_house_points:=0;
low_house_points:=9999;
Total_points:=0;
house_funds:=140000;
high_house_name:='';
low_house_name:='';

For i:=1 to 4 DO

house[i]:='';
points[i]:=0;

For i:=1 to 4 DO
BEGIN

Writeln('Enter house name');


readln (house[i]);
Writeln('Enter points scored by house');
readln (points[i]);
WHILE points[i] < 0 DO
Begin
Writeln('This value is invalid')
End;

Total_points:= points[i] + Total_points;


IF (points[i] > high_house_points) THEN
Begin
high_house_points:= points[i];
high_house_name:= house[i]
End;

IF (points[i] < Low_house_points) THEN


Begin
Low_house_points:= points[i];
Low_house_name:= house[i]
End;
high_house_funds:=(45/100) * 140000;
low_house_funds:=(17/100) *140000;
End;
Writeln('The total points scored is:', Total_points);
Writeln( high_house_name,' is the highest house and earned ',high_house_points,' points and
gained ', high_house_funds:4:2, ' from the sports fund ');
Writeln( low_house_name,' is the lowest house and earned ',low_house_points,' points and gained
', low_house_funds:4:2, ' from the sports fund ');

END.

You might also like