Exemplo n.º 1
0
        public void Octal_Float_Dot_Separated_Test()
        {
            INumber number = new NumberModel("123.456", 8);

            number.IntegerPart.Should().Be("123");
            number.FloatPart.Should().Be("456");
            number.Base.Should().Be(8);

            number = new OctalNumber("123.456");
            number.IntegerPart.Should().Be("123");
            number.FloatPart.Should().Be("456");
            number.Base.Should().Be(8);
        }
Exemplo n.º 2
0
        void buttonSubmit_Click(object sender, EventArgs e)
        {
            string    userInput       = textBox.Text;
            InputType numberInputType = (InputType)inputType.SelectedIndex;
            INumber   number;

            try
            {
                switch (numberInputType)
                {
                case InputType.Binary:
                    number = new BinaryNumber(userInput);
                    break;

                case InputType.Decimal:
                    number = new DecimalNumber(userInput);
                    break;

                case InputType.Octal:
                    number = new OctalNumber(userInput);
                    break;

                default:
                    number = new DecimalNumber(userInput);
                    break;
                }
                DisplayConversions(number);
                labelError.Text      = "Conversion Sucessful!";
                labelError.ForeColor = Color.Green;
            }
            catch (FormatException formatEx)
            {
                labelError.ForeColor = Color.Red;
                labelError.Text      = formatEx.Message;
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //keyBinary k1 = new keyBinary('1', KeyType.Number);
            //keyBinary k2 = new keyBinary('0', KeyType.Number);
            //keyBinary k3 = new keyBinary('1', KeyType.Number);
            //keyBinary k4 = new keyBinary('0', KeyType.Number);

            //BinaryNumber b1 = new BinaryNumber();
            //b1.Add(k1);
            //b1.Add(k2);
            //b1.Add(k3);
            //b1.Add(k4);

            //b1.convertToString();

            //BinaryConversion BC1 = new BinaryConversion(b1);
            //BC1.ToOctal();


            //keyOctal kO1 = new keyOctal('5', KeyType.Number);
            //keyOctal kO2 = new keyOctal('6', KeyType.Number);

            //OctalNumber O1 = new OctalNumber();
            //O1.Add(kO1);
            //O1.Add(kO2);
            //O1.convertToString();

            //OctalConversion OC1 = new OctalConversion(O1);
            //OC1.ToBinary();

            //keyBinary k5 = new keyBinary('1', KeyType.Number);
            //keyBinary k6 = new keyBinary('0', KeyType.Number);
            //keyBinary k7 = new keyBinary('0', KeyType.Number);
            //keyBinary k8 = new keyBinary('0', KeyType.Number);

            //BinaryNumber b2 = new BinaryNumber();
            //b2.Add(k5);
            //b2.Add(k6);
            //b2.Add(k7);
            //b2.Add(k8);

            //b2.convertToString();

            //BinaryOperations BO1 = new BinaryOperations(b1, b2);
            //BO1.Subtraction();

            Screen      Screen1 = new Screen();
            keyOperator KeyOp   = Screen1.PrintOperators();
            NumberType  NumType = Screen1.PrintNumberType();

            Console.WriteLine("{0}", KeyOp.Key);


            switch (KeyOp.keyType)
            {
            case KeyType.Conversion:
            {
                switch (NumType)
                {
                case NumberType.Binary:

                    Console.WriteLine("Enter Binary Number. (press Enter after each digit. Enter 'X' to stop)");

                    BinaryNumber BN = new BinaryNumber();
                    BN.GetNumber();
                    BinaryConversion BC = new BinaryConversion(BN);
                    if (KeyOp.Key == 'M')
                    {
                        BC.ToDecimal();
                    }
                    else if (KeyOp.Key == 'I')
                    {
                        Console.WriteLine("cannot convert binary to binary");
                    }
                    else if (KeyOp.Key == 'O')
                    {
                        BC.ToOctal();
                    }
                    else if (KeyOp.Key == 'H')
                    {
                        BC.ToHexaDecimal();
                    }
                    break;

                case NumberType.Octal:

                    Console.WriteLine("Enter Octal Number. (press Enter after each digit. Enter 'X' to stop)");

                    OctalNumber ON = new OctalNumber();
                    ON.GetNumber();
                    OctalConversion OC = new OctalConversion(ON);
                    if (KeyOp.Key == 'M')
                    {
                        OC.ToDecimal();
                    }
                    else if (KeyOp.Key == 'I')
                    {
                        OC.ToBinary();
                    }
                    else if (KeyOp.Key == 'O')
                    {
                        OC.ToOctal();
                    }
                    else if (KeyOp.Key == 'H')
                    {
                        OC.ToHexaDecimal();
                    }
                    break;
                }
                break;
            }

            case KeyType.Operator:
            {
                switch (NumType)
                {
                case NumberType.Binary:

                    Console.WriteLine("Enter 1st Binary Number. (press Enter after each digit. Enter 'X' to stop");

                    BinaryNumber BN1 = new BinaryNumber();
                    BN1.GetNumber();


                    Console.WriteLine("Enter 2nd Binary Number (press Enter after each digit. Enter 'X' to stop");
                    BinaryNumber BN2 = new BinaryNumber();
                    BN2.GetNumber();
                    BinaryOperations BO = new BinaryOperations(BN1, BN2);
                    //Console.WriteLine("{0}", BN1.number);
                    //Console.WriteLine("{0}", BN2.number);
                    if (KeyOp.Key == '+')
                    {
                        BO.Addition();
                    }
                    else if (KeyOp.Key == '-')
                    {
                        BO.Subtraction();
                    }
                    else if (KeyOp.Key == '*')
                    {
                        Console.WriteLine("Not implemented");
                    }
                    else if (KeyOp.Key == '/')
                    {
                        Console.WriteLine("Not implemented");
                    }


                    break;

                default:
                    break;
                }
                break;
            }
            }
        }
Exemplo n.º 4
0
 public OctalConversion(OctalNumber oN)
 {
     this.Source = oN;
 }