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

eXercise #18

Some Simple Visual Projects
featuring sequence and selection

index: Quadratic | two-up | stack-queue | dice | shellgame

  1. Solving Quadratic equations of the form ax^2 + bx + c = 0 uses a relatively standard formula:

    x1 = (-b + root(b^2 - 4ac))/2a and x1 = (-b -+ root(b^2 - 4ac))/2a.

    In this project, you will construct a form as follows:
    run | cheat

    The project comprises:
    • 3 spin edit boxes named a, b and c
    • 2 edit boxes called root1 and root2
    • a factorize button and a done button
    • a label called notice

    You will write the event handler behind the [factorize] button so that
    • the notice tells the user the number and nature of roots present (ie. no real roots, one or two real roots)


    • make the root1 and root 2 edit boxes only become visible if there is a value to output in them
    • make the notice, root1 and root2 components vanish whilst the user is changing the values for a, b and c
    • add to the notice if the roots are whole (as opposed to containing fractions)

  2. The game of TWO-UP (although illegal on any day other than Anzac Day) has some simple rules.

    Construct a form as follows:

    run | cheat

    The project comprises:
    • 2 edit boxes called coin1 and coin2
    • a toss and done button
    • a label called outcome

    You will write the event handler behind the [toss] button so that
    • coin1 and coin2 edit boxes will display either HEADS or TAILS randomly
    • the notice will report EVENS if both coins are the same or ODDS if they differ
    • the notice will additionally report HEADS or TAILS depending on whether the coins are both heads or tails


    • add guessing so the user can nominate what they think the outcome will be (use check boxes for each of the 4 possible outcomes) - your program should report if the quess was right or not
    • add betting so the user can nominate an amount of money they wish to risk - the payout is 0 for a failure; twice the bet if odds or evens was their bet; four times the bet if teh exact output (ie heads/tails)

  3. Stacks and Queues are very different types of storage structures. In this project, you will explore the differences when adding and removing characters using either stack or queue conventions.

    To add to a stack, we use the term push, the value is placed on the head of the collection. To remove from a stack, we pop and the value also comes off the head of the data collection.
    When adding to a queue, we enqueue and the value is added to the tail. Removing values from a queue happens when we dequeue and the value is removed from the head.
    queue and stack editing
    Construct a form as follows:
    Stack Queue Simulator
    run | cheat

    Notice the form comprises:
    • an edit box called data
    • 5 buttons called push, pop, enqueue, dequeue and done
    • 5 labels - 3 of which change: collection, t and h

    You are to create the event handlers behind push (adds a letter from data to the head), pop (removes a letter from head into data), enqueue (adds a letter from data to the tail) and dequeue (removes a letter from the head into data).


    • you should also add code that updates the letters in h and t to reflect the actual head and tail of the collection
    • add code to inform the user that there is no data so pop/dequeue is not possible
    • add code to inform the user if the data is empty that push/enqueue is not possible if there is nothing there to store

  4. Dice Throws randomly generate numbers from 1 to 6. In this project, you visually create a single dice (die)
    A Dice
    run | cheat

    The form contains 6 TShapes (named spot1, spot2... spot6) all changed to be circles. There is also a done button (nothing new here) and a roll button and a label (for visual verification - probably it would be deleted int he final version).

    By randomly generating a value for the dice, you then apply some combination of if..then..else to make spots visible/invisible to match the roll of the dice.

    You should write a general process to wipe the dice clean after each roll, and should remember to randomize in the formcreate to ensure each roll is unpredictable.

    Experts would ensure the layout of the dice was more true to life

  5. The Shell Game is one of the oldest forms of gambling - in this version, one of the TShapes has (in it's mousedown event) a message congratulating the user on choosing the correct one. The other 2 TShapes commiserate the player for making the wrong choice.
    Shell Game
    run | cheat

    Notice the project comprises 3 Tshapes (shell1, shell2 and shell3)

    In this project, we randomly generate .top and .left values for each of the shells to shuffle them around (thus making the one correct one appear somewhere else on the board, providing the challenge to click on it. We rely on the clientwidth and clientheight properties fo the form (as these contain the actual dimensions of the form) to calculate the new positions of the shapes.

    • change the colour of the spot after it has been clicked on to show it is the selected one
    • try to ensure the spots don't overlap on the screen (nor should they move past the form's edges)
    • add some labels to keep tally of the number of right and wrong guesses
    • add betting that doubles the bet if you win

  6. work in progress ... watch this space

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