import GUI
colorback (125)
var Smiley : int
Smiley := Pic.FileNew ("back.bmp")
Pic.Draw(Smiley,1,1,picCopy)
var howMany : int := 0
var numbers : flexible array 1 .. howMany of int
var start: string
var swapped : boolean := false
var temp : int
proc enternumbers
put "How many Numbers do you have?"
get howMany
put "Enter your ", howMany, " numbers between 1 and 100"
for i : 1 .. howMany
new numbers, i
get numbers (i)
end for
end enternumbers
proc Mean
Smiley := Pic.FileNew ("back.bmp")
Pic.Draw(Smiley,1,1,picCopy)
enternumbers
var total : int := 0
for i : 1 .. howMany
total := total + numbers (i)
end for
put " The Mean Is ", total / howMany
end Mean
proc mode
Smiley := Pic.FileNew ("back.bmp")
Pic.Draw(Smiley,1,1,picCopy)
enternumbers
% Local variables for this procedure %
var counter : int := 1
% the array to store the numbers %
var mOde : array 1 .. 2 of int
var modecounter : int := 0
var howmanymode : int := 0
% The For loop for checking the conditions %
for i : 1 .. howMany - 1
% This checks the numbers for doubles and etc.%
if numbers (i) = numbers (i + 1) then
counter += 1
else
% Mode conditions %
if counter > modecounter and counter > 1 then
modecounter := counter
mOde (1) := numbers (i)
howmanymode := 1
elsif counter = modecounter and counter > 1 then
howmanymode += 1
if howmanymode = 2 then
mOde (2) := numbers (i)
end if
end if
counter := 1
end if
end for
if counter > modecounter and counter > 1 then
modecounter := counter
mOde (1) := numbers (howMany)
howmanymode := 1
elsif counter = modecounter and counter > 1 then
howmanymode += 1
if howmanymode = 2 then
mOde (2) := numbers (howMany)
end if
end if
% puts the mode on the screen %
if howmanymode = 1 then
put "The mode is ", mOde (1)
elsif howmanymode = 2 then
put "The mode is ", mOde (1), " and ", mOde (2)
else
put "There is no mode."
end if
end mode
Smiley := Pic.FileNew ("back.bmp")
Pic.Draw(Smiley,1,1,picCopy)
proc Median
Smiley := Pic.FileNew ("back.bmp")
Pic.Draw(Smiley,1,1,picCopy)
enternumbers
var med : int
for n : 1 .. howMany
swapped := false
for i : 1 .. howMany - 1
if numbers (i) > numbers (i + 1) then
temp := numbers (i)
numbers (i) := numbers (i + 1)
numbers (i + 1) := temp
swapped := true
end if
end for
exit when swapped = false
end for
if howMany rem 2 = 0 then % even
put "The Median is ", (numbers (3) + numbers (4)) / 2
else %odd
put "The Median is ", numbers ((howMany + 1) div 2)
end if
end Median
proc menu
var Bob : string
put " Witch Would you like to figure out? Mean, Mode, or Median?"color (200)
get Bob
if Bob = "Quit" or Bob = "quit" then
quit
elsif Bob = "Mean" or Bob = "mean" then
cls
Mean
elsif Bob = "Mode" or Bob = "mode" then
cls
mode
elsif Bob = "Median" or Bob = "median" then
cls
Median
elsif Bob = "cls" then
cls
end if
end menu
put " Would you like to find a mean mode or median? yes or no"
get start
if start = "no" or start = "No" or start= "no"or start = "N" then
quit
else
end if
menu
proc button
var quitBtn : int := GUI.CreateButton (200, 10, 0, "QUIT I HAVE HAD ENOUGH", GUI.Quit)
loop
exit when GUI.ProcessEvent
end loop
end button
menu
loop
menu
end loop
|