コード例 #1
0
ファイル: Plugin.cs プロジェクト: Ozerich/labs
        public LongNumber DoOp(LongNumber number1, LongNumber number2)
        {
            LongNumber res = new LongNumber();
            int ost = 0, sum;
            int i = 0;
            for (; i < Math.Max(number1.num_len, number2.num_len); i++)
            {
                sum = number2[i] + number1[i] + ost;
                ost = sum / 10;
                res[i] = sum % 10;

            }
            if (ost > 0)
                res[i] = ost;
            return res;
        }
コード例 #2
0
ファイル: Plugin.cs プロジェクト: Ozerich/labs
 public LongNumber DoOp(LongNumber number1, LongNumber number2)
 {
     LongNumber res = number1;
     int ost = 0, sum;
     int i = 0;
     for (; i < Math.Max(number2.num_len, number1.num_len); i++)
     {
         if(number1[i] - ost < number2[i])
         {
             sum = 10 + number1[i] - ost - number2[i];
             ost = 1;
         }
         else
         {
             sum = number1[i] - number2[i] - ost;
             ost = 0;
         }
         res[i] = sum;
     }
     return res;
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: Ozerich/labs
        static void Main(string[] args)
        {
            FindPlugins();
            LongNumber num_a = new LongNumber(0);
            LongNumber num_b = new LongNumber(0);
            int user_choise = 0;
            bool exit = false;
            while (!exit)
            {
                Console.WriteLine("\n1 - Input number A");
                Console.WriteLine("2 - Input number B");
                Console.WriteLine("3 - Do operation");
                Console.WriteLine("4 - Exit Application");
                Console.Write("? ");

                try
                {
                    user_choise = Int32.Parse(Console.ReadLine());
                    switch (user_choise)
                    {
                        case 1:
                            Console.Write("Number: ");
                            num_a = new LongNumber(Console.ReadLine());
                            break;
                        case 2:
                            Console.Write("Number: ");
                            num_b = new LongNumber(Console.ReadLine()); ;
                            break;
                        case 3:
                            int i = 1;
                            try
                            {
                                foreach (IPlugin plugin in plugins)
                                {
                                    var pluginName = Attribute.GetCustomAttribute(plugin.GetType(), typeof(PluginNameAttribute));
                                    PluginNameAttribute atr = (PluginNameAttribute)pluginName;
                                    Console.WriteLine(i++ + "- " + atr.Name);
                                }
                                Console.Write("Your action: ");
                                int op = Int32.Parse(Console.ReadLine());
                                IPlugin plug = plugins[op - 1];
                                LongNumber res = plug.DoOp(num_a, num_b);
                                Console.WriteLine("\nResult: " + res);

                            }
                            catch (Exception)
                            {
                                Console.WriteLine("Incorrect operation");
                            }
                            break;
                        case 4:
                            exit = true;
                            break;
                        default:
                            throw new FormatException();
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Input error! Try Again");
                }
            }
        }