You are going to write a simple Digital Circuit Design program that electronics engineers could use to design and test simple digital circuits. It will allow you to create various kinds of logic gates (AND/OR/NOT etc.), input sources and output lamps, move them around the design window, add wires to connect them together, and so on. Each logic gate and wire will be represented in the program by an object with methods like Draw, and properties like Left and Top. You are given a very simple working version of this digital circuits program, which only handles AND gates and wires. Your first task will be to refactor this program to use inheritance, so that it is easier to add new kinds of logic gates. After you have done this, and added several new kinds of logic gates, you will add evaluation methods to the gates, so that each gate behaves like a real digital gate and computes its output signal based on what inputs it is connected to. The final step will be to add support for compound circuits – so that an engineer can design a small circuit, then group all the gates in that circuit into one “uber-gate”, which can be moved around, copied and reused as a single object. For example, this could be used to create a half-adder gate from several simple gates, then two copies of that half-adder could be combined to give a 1-bit full adder.
Step 1: Becoming familiar with the example program Download the example Circuits.zip file from Moodle and unzip it in your COMPX102 directory. Open up the CircuitsCircuits.sln file with Visual Studio and explore the code and run the program until you understand how it works. Read the documentation at the top of each class to get an overview of the program.
Step 2: Creating an abstract Gate superclass (1 mark) This is the most important step of this project. You must create a new Gate class, then move some of the AndGate methods, properties and variables up into your new Gate class. Which ones should you move up? The ones that seem to be useful for all kinds of Gates, and are not specific to AND gates. Then change your AndGate class so that it inherits from Gate. Don’t forget to make methods virtual. [Note: It would also be possible to change the Wire class to be a subclass of Gate if you want, but the advantages of doing this seem reasonably minor to me.] Next change all the references to AndGate in the Form1 class so that they use Gate objects instead. (The only call to AndGate that you will need to keep is the one in the buttonAnd_Click handler, where a new AndGate object is created and put into the currentGate variable, which will now be of type Gate). Make sure that your program runs correctly, and test its behaviour. If you find that your Gate class needs to define a method (like Draw), so that Form1 can call it, but the implementation code inside that method is obviously specific to AND gates, then make it an abstract method in the Gate class and override it with the correct implementation in the AndGate subclass. For example: public abstract void Draw(..); //in Gate class public override void Draw(..) { … } //in AndGate class Once you have done this successfully, you have generalized your Form1 program so that it can work on all kinds of Gates, not just AND gates! In the rest of this assignment, we will be adding lots of interesting kinds of new Gates by implementing new subclasses. However, your Form1 code must not change very much as these subclasses are added. Assignment 1: Digital Circuit Design 3 Typically, you will have to just add one button click handler for each new subclass, which creates an instance of that subclass and assigns it to the newGate variable. The goal is to make as few changes to Form1.cs as possible throughout the rest of this assignment. This shows how a good object-oriented design allows us to add new functionality to a program by just adding new subclasses to it.
Step 3: New Logic Gates (1 mark each) Now implement two new kinds of Gates: OR gates and NOT gates. Each of these will be a subclass of Gate, so must override various Gate methods and maybe add some extra methods. Each of these subclasses is worth one mark. Note that your new gates should turn red when selected, just like an AndGate does. As well as OR and NOT gates, you could implement a PAD gate, which is just a small rectangle with one input pin and one output pin. For each subclass you create, you should add a button to the toolbar with a handler that creates a new instance of your subclass, and assigns it to the newGate variable. This allows the engineer to drag it into the circuit and position it with a click.
Step 4: Input Sources and Output Lamps (1 mark each) Add a new subclass of Gate called InputSource. This should have no input pins and just one output pin. It should contain a boolean variable that says whether the output pin is currently high voltage (which represents a true value being output) or a zero voltage (which represents a false value being output). An InputSource gate should look different when its boolean value is high. For example, the inside of the gate might be a different colour (avoid red), or it might display a “1” or “0” to show its on/off status. Each time an InputSource gate is selected, its boolean value should toggle. That is, selecting it once should change the boolean value from false (the default) to true, then selecting it again should change it from true back to false. Similarly, create another subclass of Gate called OutputLamp. This will have one input pin and no output pins. Like the InputSource, it contains a boolean variable that records its current on/off status. It should glow like a small coloured lamp when that variable is true, and be dark when it is false. Add buttons for both of these new subclasses of Gate, and then test that you can add them to circuits and use wires to connect them to other gates.
Step 5: Evaluation Facilities (2 marks) Now extend your Gate class by adding an abstract Evaluate() method that returns a boolean result. Each subclass will implement this method in a different way, so that it computes the correct logical result for that kind of gate. For example, the Evaluate() method of an InputSource will just return its internal on/off boolean variable. The Evaluate() method of the AndGate class will return true if both the input pins evaluate to true, COMPX102 4 or false otherwise. (If an input pin is not connected to a wire, you should display an error message and assume that the pin is false.) The code to do this will look something like this (you should extend this to handle notconnected pins): Gate gateA = pins[0].InputWire.FromPin.Owner; Gate gateB = pins[1].InputWire.FromPin.Owner; return gateA.Evaluate() && gateB.Evaluate(); The Evaluate() method of an OutputLamp will evaluate its input pin (like gateA of the AndGate code) and set its internal on/off boolean variable to the result of this evaluation. So the output lamps trigger a series of Evaluate() calls to other gates in the circuit, then they display and remember the boolean results of the evaluations. Add a toolbar button, “Evaluate”, whose handler loops through all the gates and asks each OutputLamp to evaluate itself. (Use the C# is or as operators to find out which gates are OutputLamps). To test your evaluation functions, use your program to design an exclusive-or circuit with two InputSources and one OutputLamp.
Step 6: Copy and Paste of Gates (1 mark) Now extend your Gate class by adding an abstract Clone() method that returns a fresh copy of the gate. Each subclass will implement this in a different way, by making a copy of itself. Note that it will also need to make a clone of each of its pins. Add a “Copy” button to the toolbar, that calls the Clone() method of the currently selected gate (if a gate is selected) and assigns it to the newGate variable. This will allow engineers to copy a single gate. Not very useful, but this feature can become much more useful once you’ve implemented compound gates.
Step 7: Compound Gates (6 marks) A very powerful and useful feature of most digital circuit editors is that they allow a collection of Gates to be grouped together into one compound Gate. The resulting compound Gate can then be treated as a new primitive Gate, selected as one whole group, moved around together, and maybe copied and pasted etc. Implement a Compound class, which will be another subclass of Gate, but will contain a list of Gate objects and an AddGate method that adds a Gate to that list. Add a “Start Group” button to the toolbar, whose handler creates a new empty Compound gate and stores it in a new instance variable of Form1, called newCompound. If a Gate is selected while newCompound is non-null, that gate is added into the newCompound object. Then add an “End Group” button to the toolbar, with a handler that moves newCompound into newGate and resets newCompound to null.
Why Work with Us
Top Quality and Well-Researched Papers
We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.
Professional and Experienced Academic Writers
We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.
Free Unlimited Revisions
If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.
Prompt Delivery and 100% Money-Back-Guarantee
All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.
Original & Confidential
We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.
24/7 Customer Support
Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.
Try it now!
How it works?
Follow these simple steps to get your paper done
Place your order
Fill in the order form and provide all details of your assignment.
Proceed with the payment
Choose the payment system that suits you most.
Receive the final file
Once your paper is ready, we will email it to you.
Our Services
No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.
Essays
No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.
Admissions
Admission Essays & Business Writing Help
An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.
Reviews
Editing Support
Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.
Reviews
Revision Support
If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.