IPT - A Virtual Approach IPT A Virtual Approach by Peter Whitehouse
Quick Links:
 
 
Information and Intelligent Systems Social and Ethical Implications Human Computer Interaction Software and Systems Engineering eXercise Files Course Outline and Assessment A-Z of Geeky Acronyms Terrace Work Program 2004 Sillybus FAQ = Frequently Asked Questions Help
 
 

Maths Tutor

A Simple application based on "ON CLICK" events

calculator form

This application uses a series of simple event handlers to bring a maths tutor to life. In this 'unsophisticated' application, 'sums' are generated randomly and the user is given the opportunity to answer and check their work.

The Components:

What follows is a list of components needed for this application, along with some properties that need to be set for those components. Be systematic and TIDY placing your components.

  • Change FORM1's COLOR to clGreen
  • Place a BUTTON, change it's name to clear, and ensure it's caption reads clear
  • Do the same for BUTTONS named Check, Quit and New (ie. another 3 buttons)
  • Place a Button, change it's name to one, and ensure it's caption reads 1
  • Do the same for BUTTONS called two, three, four, five, six, seven, eight, nine and zero (ie. another 9 buttons)
  • Place an EDITBOX, change it's name to sum, delete the text in it's text property and change it's ReadOnly property to true. (That way users can't change the sum to suit their answer)
  • Place an EDITBOX, change it's name to answer and delete the text in it's text property.
  • Place LABELS "The Sum Is:" and "Your Answer is:" above the two edit boxes.

Other Objects

This project uses two VARIABLES to store the two RANDOM NUMBERS that will be used to construct the sum. Their NAMES are A and B, and their declarations need to be placed in the GLOBAL VAR section of this form's code. When correctly defined, the VAR section should resemble the following:

{$R *.DFM}
Var Operand1, Operand2 : integer;

 

The Event Handlers

There are a number of simple event handlers that are necessary for the successful operation of this tutor.

To place an event handler behind a button, double click on the button to create a procedure container, then enter the instructions. Presented below are the ON CLICK event handlers associated with the named buttons:

Button Name Event Handler Code
clear
answer.text := ' '
quit
close
new
{Randomly generate two operands}
Operand1 := random(100);
Operand2 := random(100);
{construct the 'sum' as a string}
sum.text := intToStr(Operand1) + '+' + intToStr(Operand2);
answer.text := ' '
one
answer.text := answer.text + '1'
two
answer.text := answer.text + '2'
three
answer.text := answer.text + '3'
four
answer.text := answer.text + '4'
other 'number' buttons and so on
check
if Operand1+Operand2 = strToInt(answer.text)
   then showMessage('Correct')
   else showmessage('incorrect')

Final Touches

COMPILE the program to check for errors of 'SYNTAX', fix any that show, then RUN it to check it works correctly. Test it with both correct answers and incorrect answers.

It would be 'nice' if the program automatically offered it's first sum to the user, rather than you having to press NEW to get the first one. This can be easily remedied by opening up the FORM CREATE event (do this by double clicking on the form background) and COPYING the code that is contained in the NEW BUTTONCLICK.

The Title bar should be personalised - do this by changing FORM1's caption property.

To get the 'embossed' appearance, BEVELs have been placed on the form - experiment.

 

wonko@wonko.info
©Copyright t 1992..2018+. Edition 26.150117
wonkosite
Creative Commons License
This work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 2.1 Australia License
.