quiz_thumbQuiz Tool like Memory Lifter is a great memorisation technique (read also “How to memorize anything”). In this first lesson, we will build a simple textual version (next version will have a visual GUI).

The first version of our script below is based upon the one found here except for the data which has been taken from CodeProject’s article on Design Patterns Interview Questions ( Quick Reference).


Rebol [
]
questions: [
"Abstract Factory" "Creates an instance of several families of classes" "Creational Pattern"
"Builder" "Separates object construction from its representation" "Creational Pattern"
"Factory Method" "Creates an instance of several derived classes" "Creational Pattern"
"Prototype" "is a fully initialized instance to be copied or cloned" "Creational Pattern"
"Singleton" "is a class in which only a single instance can exist " "Creational Pattern"
"Adapter" "Match interfaces of different classes" "Structural Pattern"
"Bridge" "Separates an object’s abstraction from its implementation" "Structural Pattern"
"Composite" "is a tree structure of simple and composite objects" "Structural Pattern"
"Decorator" "Add responsibilities to objects dynamically" "Structural Pattern"
"Façade" "is a single class that represents an entire subsystem" "Structural Pattern"
"Flyweight" "is a fine-grained instance used for efficient sharing" "Structural Pattern"
"Proxy" "is an object representing another object" "Structural Pattern"
"Mediator" "Defines simplified communication between classes" "Behavorial Pattern"
"Memento" "Capture and restore an object's internal state" "Behavorial Pattern"
"Interpreter" "is a way to include language elements in a program" "Behavorial Pattern"
"Iterator" "Sequentially access the elements of a collection" "Behavorial Pattern"
"Chain of Resp" "is a way of passing a request between a chain of objects" "Behavorial Pattern"
"Command" "Encapsulate a command request as an object" "Behavorial Pattern"
"State" "Alter an object's behavior when its state changes" "Behavorial Pattern"
"Strategy" "Encapsulates an algorithm inside a class" "Behavorial Pattern"
"Observer" "is a way of notifying change to a number of classes" "Behavorial Pattern"
"Template Method" "Defer the exact steps of an algorithm to a subclass" "Behavorial Pattern"
"Visitor" "Defines a new operation to a class without change" "Behavorial Pattern"
]

correct: wrong: 0

foreach [pattern description category] questions [
   desc: ask rejoin [newline "What is the" " " pattern " " "pattern?"]
   either desc = description [
      print "*** Correct!!! ***"
      correct: correct + 1
   ][
      print ["Sorry...pattern" pattern description]
      wrong: wrong + 1
   ]

   cat: ask rejoin [newline "What is the category of pattern " pattern " ?"]
   either cat = category [
      print "*** Correct!!! ***"
      correct: correct + 1
   ][
      print ["Sorry...the category of" pattern "is" category]
      wrong: wrong + 1
   ]
]


Let’s add some variation:


n: (length? questions) / 3
foreach [pattern description category] questions [
   i: random n
   random-pattern: pick questions (1 + (i * 3))
   answer: ask rejoin [newline "Random Q" i ": " "What is the " random-pattern " pattern?"]
   desc: select questions random-pattern
   either answer = desc [
      print "*** Correct!!! ***"
      correct: correct + 1
   ][
      print ["Sorry...pattern" random-pattern desc]
      wrong: wrong + 1
   ]

   answer: ask rejoin [newline "What is the category of pattern " random-pattern " ?"]
   either answer = (cat: select questions desc) [
      print "*** Correct!!! ***"
      correct: correct + 1
   ][
      print ["Sorry...the category of" random-pattern "is" cat]
      wrong: wrong + 1
   ]
]

Let’s add score printing:


print [newline "You answered" correct "questions correctly and"
       wrong "questions incorrectly.^\"
       "This gives you a score of"
       to-integer (correct / (correct + wrong) * 100 + .5) "%"
 ]

We will refine the Quiz in next installment.

Bookmark and Share