This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
user:cforman:portfolio:cprogproject5 [2012/04/27 01:52] – created cforman | user:cforman:portfolio:cprogproject5 [2012/05/10 03:20] (current) – [Execution] cforman | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Logic Gates====== | ||
+ | A project for C/C++ by Corey Forman during the Spring 2012. | ||
+ | |||
+ | |||
+ | =====Objectives===== | ||
+ | Create a program that uses two created inputs and checks them in a series of way to observe and report if they pass through specific logic gates. | ||
+ | =====Prerequisites===== | ||
+ | In order to successfully accomplish/ | ||
+ | |||
+ | * basic idea of how logic gates work | ||
+ | * c++ coding | ||
+ | * class programming (class files and separating the program into manageable pieces) | ||
+ | * | ||
+ | =====Background===== | ||
+ | |||
+ | The idea of this project was brought up to us by the teacher. He discussed what an AND gate is and we went from there. here is a pic that has some logic gates in minecraft just for entertainment. | ||
+ | {{: | ||
+ | =====Scope===== | ||
+ | |||
+ | |||
+ | The scope of this project was to expand upon the idea of using both class functions and learning how logic gates function. The program will take two predetermined variables and then runs them through a series of checks to see which logic gates they pass. | ||
+ | =====Attributes===== | ||
+ | State and justify the attributes you'd like to receive upon successful approval and completion of this project. | ||
+ | |||
+ | * attribute1: why you feel your pursuit of this project will gain you this attribute | ||
+ | * attribute2: why you feel your pursuit of this project will gain you this attribute | ||
+ | * etc... | ||
+ | |||
+ | =====Procedure===== | ||
+ | The first step after writing the code was to assign boolean values to A and B. | ||
+ | next the program is run and results checked. | ||
+ | Change A and B test again to confirm. | ||
+ | |||
+ | =====Code===== | ||
+ | Upon completion of the project, if there is an applicable collection of created code, place a copy of your finished code within < | ||
+ | |||
+ | <code c> | ||
+ | # | ||
+ | 2 #include < | ||
+ | 3 | ||
+ | 4 class Gate{ | ||
+ | 5 | ||
+ | 6 | ||
+ | 7 bool getX(); | ||
+ | 8 void setA(bool); | ||
+ | 9 void setB(bool); | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 16 }; | ||
+ | 17 | ||
+ | 18 GATE:: | ||
+ | 19 { | ||
+ | | ||
+ | 21 } | ||
+ | 22 | ||
+ | 23 GATE()=0; | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 33 }; | ||
+ | 34 | ||
+ | 35 GATE:: | ||
+ | 36 { | ||
+ | | ||
+ | 38 } | ||
+ | 39 | ||
+ | 40 | ||
+ | 41 bool GATE:: getX() | ||
+ | 42 { | ||
+ | | ||
+ | 44 } | ||
+ | 45 | ||
+ | 46 void GATE:: setA(bool A) | ||
+ | 47 { | ||
+ | | ||
+ | 49 } | ||
+ | 50 | ||
+ | 51 void GATE:: setB(bool B) | ||
+ | 52 { | ||
+ | | ||
+ | 54 } | ||
+ | 55 | ||
+ | 56 void GATE:: setX(bool X) | ||
+ | 57 { | ||
+ | | ||
+ | 59 } | ||
+ | 60 | ||
+ | 61 | ||
+ | 62 Class AND:public GATE{ // | ||
+ | | ||
+ | | ||
+ | | ||
+ | 66 }; | ||
+ | 67 | ||
+ | 68 AND::AND() | ||
+ | 69 { | ||
+ | | ||
+ | | ||
+ | | ||
+ | 73 } | ||
+ | 74 | ||
+ | 75 void AND:: process() | ||
+ | 76 { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 81 } | ||
+ | 82 | ||
+ | 83 | ||
+ | 84 #include " | ||
+ | 85 #inlcude " | ||
+ | 86 | ||
+ | 87 int main() | ||
+ | 88 { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 95 } | ||
+ | 96 | ||
+ | 97 class NAND:public GATE{ | ||
+ | | ||
+ | | ||
+ | 100 void Process(); | ||
+ | 101 }; | ||
+ | 102 | ||
+ | 103 NAND:: | ||
+ | 104 { | ||
+ | 105 | ||
+ | 106 | ||
+ | 107 | ||
+ | 108 } | ||
+ | 109 | ||
+ | 110 void NAND:: process() | ||
+ | 111 { | ||
+ | 112 if ((A==true)and(B==true)) | ||
+ | 113 | ||
+ | 114 else | ||
+ | 115 | ||
+ | 116 } | ||
+ | 117 | ||
+ | 118 | ||
+ | 119 | ||
+ | 120 OR::OR() | ||
+ | 121 { | ||
+ | 122 | ||
+ | 123 | ||
+ | 124 | ||
+ | 125 } | ||
+ | 126 | ||
+ | 127 void OR:: process() | ||
+ | 128 { | ||
+ | 129 if ((A=true) or (B=true)) | ||
+ | 130 | ||
+ | 131 else | ||
+ | 132 | ||
+ | 133 } | ||
+ | 134 | ||
+ | 135 XOR::XOR | ||
+ | 136 { | ||
+ | 137 | ||
+ | 138 | ||
+ | 139 | ||
+ | 140 } | ||
+ | 141 | ||
+ | 142 XOR:: | ||
+ | 143 { | ||
+ | 144 | ||
+ | 145 | ||
+ | 146 else if((A=true) or (B=true)) | ||
+ | 147 | ||
+ | 148 else | ||
+ | 149 | ||
+ | 150 } | ||
+ | 151 | ||
+ | class NOT:public GATE{ | ||
+ | 7 | ||
+ | 8 | ||
+ | 9 void process(); | ||
+ | 10 }; | ||
+ | 4 NOT::NOT() | ||
+ | 5 { | ||
+ | 6 | ||
+ | 7 | ||
+ | 8 | ||
+ | 9 } | ||
+ | 10 | ||
+ | 11 void NOT:: process() | ||
+ | 12 { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 17 } | ||
+ | class NOR:public GATE{ | ||
+ | 7 | ||
+ | 8 | ||
+ | 9 void process(); | ||
+ | 10 }; | ||
+ | | ||
+ | 5 { | ||
+ | 6 | ||
+ | 7 | ||
+ | 8 | ||
+ | 9 } | ||
+ | 10 | ||
+ | 11 void NOR:: process() | ||
+ | 12 { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 17 } | ||
+ | 18 | ||
+ | class XNOR:public GATE{ | ||
+ | 7 | ||
+ | 8 | ||
+ | 9 void process(); | ||
+ | 10 }; | ||
+ | | ||
+ | 5 { | ||
+ | 6 | ||
+ | 7 | ||
+ | 8 | ||
+ | 9 } | ||
+ | 10 | ||
+ | 11 void XNOR:: process() | ||
+ | 12 { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 19 } | ||
+ | 20 | ||
+ | |||
+ | |||
+ | | ||
+ | </ | ||
+ | |||
+ | |||
+ | this is what main.cc looked like in order for the program to run. | ||
+ | <code c> | ||
+ | #include < | ||
+ | 2 #include < | ||
+ | 3 | ||
+ | 4 #include " | ||
+ | 5 #include " | ||
+ | 6 #include " | ||
+ | 7 #include " | ||
+ | 8 #include " | ||
+ | 9 #include " | ||
+ | 10 #include " | ||
+ | 11 #include " | ||
+ | 12 | ||
+ | 13 int main() | ||
+ | 14 { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 22 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 51 | ||
+ | | ||
+ | |||
+ | </ | ||
+ | |||
+ | =====Execution===== | ||
+ | Again, if there is associated code with the project, and you haven' | ||
+ | |||
+ | <cli> | ||
+ | result for AND is: 1 | ||
+ | result for NAND is: 0 | ||
+ | result for OR is: 0 | ||
+ | result for XOR is: 1 | ||
+ | result for NOT is: 1 | ||
+ | result for NOR is 0 | ||
+ | result for XNOR is 1 | ||
+ | |||
+ | |||
+ | </ | ||
+ | changed variables...original found in main.cc above | ||
+ | <cli> | ||
+ | myAND-> | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | </ | ||
+ | results | ||
+ | <cli> | ||
+ | lab46: | ||
+ | result for AND is: 1 | ||
+ | result for NAND is: 1 | ||
+ | result for OR is: 1 | ||
+ | result for XOR is: 0 | ||
+ | result for NOT is: 1 | ||
+ | result for NOR is 0 | ||
+ | result for XNOR is 1 | ||
+ | |||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | =====Reflection===== | ||
+ | Logic gates are an important thing to understand in c++ as this helps you go about through the decision process and gives the user the ability to interpret and realize a decision making process. | ||
+ | =====References===== | ||
+ | In performing this project, the following resources were referenced: | ||
+ | |||
+ | * in class data only except for the photo which was from google.com |