예제 #1
0
        public void ExecuteFullAdder_compareWITHHA()
        {
            int[] inputC_B = new int[2] {1,1};
            int[] inputB_A = new int[2] {1,1 };
            int[] inputOr = new int[2] {0, 0 };

            int[] outputExpectC_B = new int[2] { 0, 1 };
            int[] outputExpectB_A = new int[2] { 0, 1 };
            int[] outputTest = new int[2];
            int[] outputExpect = new int[2] { 0, 1 };

             var oHalfAdder = new HalfAdder();
            int[] outputC_B = oHalfAdder.ExecuteAdder(inputC_B);
            Assert.AreEqual(outputExpectC_B[0], outputC_B[0]);
            Assert.AreEqual(outputExpectC_B[1], outputC_B[1]);

            int[] outputB_A = oHalfAdder.ExecuteAdder(inputB_A);
            Assert.AreEqual(outputExpectB_A[0], outputB_A[0]);
            Assert.AreEqual(outputExpectB_A[1], outputB_A[1]);

            var oGate = new OrGate();
            oGate.Input = inputOr;
            outputTest[0]= oGate.Operate();
            outputTest[1] = outputB_A[1];

            Assert.AreEqual(outputTest[0], outputExpect[0]);
            Assert.AreEqual(outputTest[1], outputExpect[1]);
        }
예제 #2
0
        public int[] ExecuteAdder(int[] x)
        {
            int[] result = new int[2];
            int[] Input = new int[2];
            int[] Output = new int[2];

            Input[0] = x[0];
            Input[1] = x[1];
            var oHalfAdd = new HalfAdder();
            Output = oHalfAdd.ExecuteAdder(Input);
            result[0] = Output[0];

            Input[0] = Output[1];
            Input[1] = x[2];
            Output = oHalfAdd.ExecuteAdder(Input);
            result[1] = Output[1];

            Input[0] = result[0];
            Input[1] = Output[0];
            var oOr = new OrGate();
            oOr.Input = Input;
            result[0] = oOr.Operate();
            return result;
        }
예제 #3
0
        static void Main(string[] args)
        {
            int[] result = new int[2];

            Console.WriteLine("*********************************************************");
            Console.WriteLine("                    ASSIGNMENT ONE                       ");
            Console.WriteLine("*********************************************************");

            Console.WriteLine("==================== HALF ADDER (HA) ====================");
            IExecuteAdder oHalfAdder = new HalfAdder();
            var halfAdder = new int[] { 1, 1 };
            result = oHalfAdder.ExecuteAdder(halfAdder);
            PrintResult(halfAdder, result);

            halfAdder = new int[] { 1, 0 };
            result = oHalfAdder.ExecuteAdder(halfAdder);
            PrintResult(halfAdder, result);

            halfAdder = new int[] { 0, 1 };
            result = oHalfAdder.ExecuteAdder(halfAdder);
            PrintResult(halfAdder, result);

            halfAdder = new int[] { 0, 0 };
            result = oHalfAdder.ExecuteAdder(halfAdder);
            PrintResult(halfAdder, result);

            Console.WriteLine("=========================================================");
            Console.WriteLine("==================== FULL ADDER (FA) ====================");
            var fullAdder = new int[] { 0, 0, 0 };
            IExecuteAdder oFullAdder = new FullAdder();
            result = oFullAdder.ExecuteAdder(fullAdder);
            PrintResult(halfAdder, result);

            fullAdder = new int[] { 0, 0, 1 };
            result = oFullAdder.ExecuteAdder(fullAdder);
            PrintResult(fullAdder, result);

            fullAdder = new int[] { 0, 1, 0 };
            result = oFullAdder.ExecuteAdder(fullAdder);
            PrintResult(fullAdder, result);

            fullAdder = new int[] { 1, 0, 0 };
            result = oFullAdder.ExecuteAdder(fullAdder);
            PrintResult(fullAdder, result);

            fullAdder = new int[] { 0, 1, 1 };
            result = oFullAdder.ExecuteAdder(fullAdder);
            PrintResult(fullAdder, result);

            fullAdder = new int[] { 1, 0, 1 };
            result = oFullAdder.ExecuteAdder(fullAdder);
            PrintResult(fullAdder, result);

            fullAdder = new int[] { 1, 1, 0 };
            result = oFullAdder.ExecuteAdder(fullAdder);
            PrintResult(fullAdder, result);

            fullAdder = new int[] { 1, 1, 1 };
            result = oFullAdder.ExecuteAdder(fullAdder);
            PrintResult(fullAdder, result);

            Console.WriteLine("=========================================================");

            Console.WriteLine("*********************************************************");
            Console.WriteLine("                    ASSIGNMENT TWO                       ");
            Console.WriteLine("*********************************************************");

            double x = 0.00;

            Console.WriteLine("###Exit Console by type 'exit'###"); // Prompt
            Console.WriteLine("Enter input Sqrt:"); // Prompt
            string line = Console.ReadLine(); // Get string from user
            if (line == "exit") // Check string
            {
                Environment.Exit(0);
            }
            else
            {
                try
                {
                    x = Convert.ToDouble(line);
                    double output = Sqrt(x);
                    Console.WriteLine(output.ToString("#.0000"));

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
            Console.WriteLine("Press Any key to Exit");
            Console.ReadLine();
        }