I'm not really sure if posting entire programs is good etiquette, but whatever. I made this for grade 9 computers class, and as you can probably see, it was a summary for the Turing unit. I pulled my grade up from a 53% at midterms to an 80% at the end of the year, and this here is part of the reason why (albeit a small part). It works anyway. Feel free to steal whatever you want.
My teacher made me overcomment everything, but I DID get perfect (or very close to it).
% Rob Sterkenburg
% December 14, 2005
% TURING SUMMARY ASSIGNMENT
% Line that allows me to use GUI statements (background colour, etc.)
import GUI in "%oot/lib/GUI"
% Puts Turing into graphics mode and declares screen size
setscreen ("graphics:1010;690")
% Procedure for creating a border
procedure border
drawfillbox (1, 1, 1008, 10, 55)
drawfillbox (1, 1, 10, 688, 55)
drawfillbox (10, 688, 1008, 678, 55)
drawfillbox (1008, 678, 998, 1, 55)
end border
% Quiz starting variable
var key : string (1)
% Answer and scoring variables
var Q1_Ans : string
var Q1_Score : int
Q1_Score := 0
var Q2_Ans : string (15)
var Q2_Score : int
Q2_Score := 0
var Q3_Ans : string
var Q3_Score : int
Q3_Score := 0
var Q4_Ans : string
var Q4_Score : int
Q4_Score := 0
var Q5_Ans : int
var Q5_Score : int
Q5_Score := 0
var Q6_Ans : string
var Q6_Score : int
Q6_Score := 0
var Q7_Ans : string
var Q7_Score : int
Q7_Score := 0
var TotalScore : int
% Variable to control how long delays are (shortened for testing).
var DelayTime : int
DelayTime := 10 %THIS WAS NEVER CHANGED BACK
% Background colour
var BackColour : int
BackColour := 255
GUI.SetBackgroundColor (BackColour)
% Intro info
border
colorback (255)
color (14)
for x : 1 .. 40
cls
locate (5, x)
put "Welcome to the Rob Sterkenburg Driving Test."
border
delay (50)
end for
for decreasing x : 43 .. 7
cls
locate (5, 41)
put "Welcome to the Rob Sterkenburg Driving Test."
locate (x, 38)
put "All answers use capital letters and whole numbers."
% Calls border procedure
border
delay (75)
end for
locate (10, 51)
put "Press any key to start."
% Calls border procedure
border
% Command that is fulfilled when any key is pressed
locate (11, 62)
getch (key)
cls
% QUESTION ONE
locate (3, 1)
put "When are roads the slickest? "
put " "
put "A) After it has rained for at least 20 minutes, and all of the oil, grease, dirt and rain mix together."
put "B) When it has just started to rain and the rain hasn't mixed with the substances on the road."
put "C) After the rain stops."
put "D) Before the rain starts."
loop
put " "
put "Answer: " ..
get Q1_Ans : *
% Increases score for number of attempts
Q1_Score := Q1_Score + 1
% If to determine what to do with 'Q1_Ans'
if Q1_Ans = "A" then
put "Sorry, A is not the correct answer."
elsif Q1_Ans = "B" then
put " "
put " "
put "Yes. The most dangerous time for losing traction during rain is around 20 minutes after the rain starts."
% Starts next question
delay (DelayTime)
cls
elsif Q1_Ans = "C" then
put "C is not the correct answer."
elsif Q1_Ans = "D" then
put "D is definately not the correct answer."
else
colour (12)
put "That is not a selectable option. Please put only a capital letter A, B, C, or D."
colour (14)
end if
exit when Q1_Ans = "B"
end loop
% QUESTION TWO
locate (3, 1)
put "Wet leaves can make the road very _________"
% Loop that forces correct answer to be given before proceeding
loop
put " "
put "Fill in the blank. " ..
get Q2_Ans : *
% Increases score for number of attempts
Q2_Score := Q2_Score + 1
% If statement to offer correct/wrong statements and hint statement
if Q2_Ans = "Slick" then
put " "
put " "
put "That is the right answer!"
delay (DelayTime)
cls
elsif Q2_Ans = "Slippery" then
put " "
put " "
put "That is the right answer!"
delay (DelayTime)
cls
elsif Q2_Ans = "Dangerous" then
put " "
put " "
put "That is the right answer!"
delay (DelayTime)
cls
% Statement for any answer that is not correct
else
put "No, that is not the right answer. Try captializing the first letter of your answer."
% Helping hint statement - runs at every wrong answer
put "Hint: There are three answers. They are 5, 8 and 9 letters long."
end if
exit when Q2_Ans = "Slick"
exit when Q2_Ans = "Slippery"
exit when Q2_Ans = "Dangerous"
end loop
% QUESTION THREE
locate (3, 1)
put "What is the leading cause of accidents in winter?"
put " "
put "A) Ice, snow or slush on roads."
put "B) Using improper tires (eg. summer tires or cheap all-season tires)."
put "C) Speeding."
put "D) Falling asleep."
% Loop that forces correct answer to be given before proceeding
loop
put " "
put "The answer is: " ..
get Q3_Ans : *
% Increases score for number of attempts
Q3_Score := Q3_Score + 1
% If to determine what to do with 'Q3_Ans'
if Q3_Ans = "A" then
put "That is the most common response, but it is not correct."
elsif Q3_Ans = "B" then
put "That is not the correct answer, though it is often a contributing factor to accidents."
elsif Q3_Ans = "C" then
put " "
put " "
put "Yes. Many drivers do not slow down sufficiently during poor conditions."
delay (DelayTime)
cls
elsif Q3_Ans = "D" then
put "This is not the correct answer."
else
colour (12)
put "That is not a selectable option. Please put only a capital letter A, B, C, or D."
colour (14)
end if
exit when Q3_Ans = "C"
end loop
% QUESTION FOUR
% Start of stop-sign picture
var x : array 1 .. 8 of int := init (400, 400, 435, 485,
520, 520, 485, 435)
var y : array 1 .. 8 of int := init (400, 450, 485, 485,
450, 400, 365, 365)
drawfillpolygon (x, y, 8, 12)
var fontA : int
fontA := Font.New ("arial:22")
Font.Draw ("STOP", 420, 415, fontA, white)
% End of stop-sign picture
% Start of question text
locate (3, 1)
put "You may pass a car on the road if: "
put "A) The lines in the middle of the road are solid yellow."
put "B) There is one solid line in the middle of the road."
put "C) The car you are passing is travelling under 75 km/h"
put "D) The lines in the middle of the road are solid only for you."
put "E) The line(s) in the middle of the road are broken for you or for both sides."
put "F) You are going up a hill."
% Loop that forces correct answer to be given before proceeding
loop
put " "
put "The answer is: " ..
get Q4_Ans : *
% Increases score for number of attempts
Q4_Score := Q4_Score + 1
% If to determine what to do with 'Q4_Ans'
if Q4_Ans = "A" then
put "No. You may not pass on any solid line."
elsif Q4_Ans = "B" then
put "No. You may not pass on any solid line."
elsif Q4_Ans = "C" then
put "That answer is not correct."
elsif Q4_Ans = "D" then
put "No. You may not pass a car if there is a solid line."
elsif Q4_Ans = "E" then
put " "
put " "
put "Yes, that is the correct answer."
delay (DelayTime)
cls
elsif Q4_Ans = "F" then
put "No. You should NEVER pass going up a hill because there may be a car approaching you can't see."
else
colour (12)
put "That is not a selectable option. Please put only a capital letter A, B, C, or D."
colour (14)
end if
% Exit for correct answer
exit when Q4_Ans = "E"
end loop
% QUESTION FIVE
locate (3, 1)
put "What is the normal speed in a school zone? (in Km/h)"
% Loop that forces correct answer to be given before proceeding
loop
put " "
put "The answer is: " ..
get Q5_Ans
% Increases score for number of attempts
Q5_Score := Q5_Score + 1
% If to determine what to do with 'Q5_Ans'
if Q5_Ans < 5 then
put "You are not using common sense."
elsif Q5_Ans < 20 then
put "No, that is a bit slow."
elsif Q5_Ans < 40 then
put "No, that is a little slow."
elsif Q5_Ans = 40 then
put " "
put " "
put "Yes, the speed in a school zone is 40 Km/h."
delay (DelayTime)
cls
elsif Q5_Ans > 41 then
put "No, that is a bit fast."
elsif Q5_Ans > 60 then
put "That is far too fast."
elsif Q5_Ans > 80 then
put "You are not using common sense."
else
colour (12)
put "That is not a selectable option. Please put only a realistic whole number."
colour (14)
end if
exit when Q5_Ans = 40
end loop
% QUESTION SIX
locate (3, 1)
put "What type of vehicles have blue flashing lights?"
put " "
put "A) Emergency Vehicles."
put "B) Volunteer Firefighters."
put "C) Police Vehicles."
put "D) Snow Removal Vehicles."
put "E) Construction Vehicles."
% Loop that forces correct answer to be given before proceeding
loop
put " "
put "Answer: " ..
get Q6_Ans : *
% Increases score for number of attempts
Q6_Score := Q6_Score + 1
% If to determine what to do with 'Q6_Ans'
if Q6_Ans = "A" then
put "That is incorrect. Emergency vehicles have red and white lights."
elsif Q6_Ans = "B" then
put "No, that is not the correct answer."
elsif Q6_Ans = "C" then
put "That is incorrect. Police vehicles (in Ontario) have only red and white lights."
elsif Q6_Ans = "D" then
put " "
put " "
put "Yes. Snow removal vehicles are the only vehicles with blue lights."
delay (DelayTime)
cls
elsif Q6_Ans = "E" then
put "That is incorrect. Volunteer firefighters' vehicles have green lights."
else
colour (12)
put "That is not a selectable option. Please put only a capital letter A, B, C, D, or E."
colour (14)
end if
exit when Q6_Ans = "D"
end loop
% SCORING
locate (3, 1)
put "The results of your test are: "
put " "
% If statements that determine wether ATTEMPT or ATTEMPTS is to be written
put "Question One: ", Q1_Score ..
if Q1_Score = 1 then
put " attempt."
else
put " attempts."
end if
put "Question Two: ", Q2_Score ..
if Q2_Score = 1 then
put " attempt."
else
put " attempts."
end if
put "Question Three: ", Q3_Score ..
if Q3_Score = 1 then
put " attempt."
else
put " attempts."
end if
put "Question Four: ", Q4_Score ..
if Q4_Score = 1 then
put " attempt."
else
put " attempts."
end if
put "Question Five: ", Q5_Score ..
if Q5_Score = 1 then
put " attempt."
else
put " attempts."
end if
put "Question Six: ", Q6_Score ..
if Q6_Score = 1 then
put " attempt."
else
put " attempts."
end if
TotalScore := Q1_Score + Q2_Score + Q3_Score + Q4_Score + Q5_Score + Q6_Score
put " "
put "The total number of attempts is: ", TotalScore, "."
put "Total number of attempts to pass: 6."
delay (3000)
var font1 : int
font1 := Font.New ("serif:18")
assert font1 > 0
if TotalScore < 7 then
Font.Draw ("You have passed! You may recieve your license!", 375, 600, font1, green)
else
Font.Draw ("You have failed. Please try again.", 375, 600, font1, brightred)
end if
Archived topic from Iceteks, old topic ID:4122, old post ID:34578