☰ خطة العام · تكنولوجيا المعلومات والاتصالات (بالإنجليزية)

The AND simulator in VB.NET

الأسبوع 9 · الوحدة ٢ الموضوع الثاني: مشروع محاكاة بوابة AND بلغة VB.NET: الهدف والمراحل وأدوات التحكم والكود في ثلاثة أجزاء · 3 دروس
1

Planning a switch-and-lamp simulator

ICT Secondary 3 Term 1, Unit 2, Topic 2: pp. 19–31
GoalState what the AND simulator must do, name its requirements and stages, and list its four states.
New words
simulation · imitating something real in a program so that we can try it without building itsimulator · the program that does the imitatingrequirement · something the program must do or havestate · what the controls show right now, such as the texts of the buttons and the lamp
Explanation

A simulation imitates something real so that we can try it safely. Our simulator imitates the AND circuit of Week 8: two switches and a lamp on the screen. It has four jobs. At the start both switches show Off and the lamp is unlit. When a switch is clicked its text flips between Off and On. The lamp is lit only when both switches are On. In every other case the lamp is unlit. To build it we need two things: the AND rule, which we have, and a programming language, here VB.NET. The stages are the same as for the converter in Week 6: design the window, set the properties, write the code. The word state is useful. The state of the program is what its controls show now: the text of the two buttons and whether the lamp is lit. A click changes the state, and the code must make the new state obey the AND rule.

Switch A showsSwitch B showsLamp
OffOffunlit
OnOffunlit
OffOnunlit
OnOnlit
Worked examples
RequirementWhat does it
start with both switches Off and the lamp unlitthe code that runs when the window opens
flip a switch’s text when it is clickedthe click code of that switch
light the lamp only when both are Onan If inside the click code that looks at the other switch
The requirements, each with the part of the program that will do it.
From (A, B)Click A givesClick B gives
Off, OffOn, Off (unlit)Off, On (unlit)
On, OffOff, Off (unlit)On, On (lit)
Off, OnOn, On (lit)Off, Off (unlit)
On, OnOff, On (unlit)On, Off (unlit)
Where does one click lead? From each state, a click on A or on B gives a new state. Only the click that ends with both switches On lights the lamp.
Class activity

Plan on paper a simulator for a lamp that lights only when three switches are On. Write its start state, how many states it has, and which of them lights the lamp.

Practice
1
What is a simulator?
2
What does the window show at the start?
3
How many different states can two Off-or-On buttons make?
4
Which two things do we need before we build the simulator?