Advertisement
Slapoguzov

Lab2_mod3

May 16th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. /* Обработать исключения
  8.  * Сделать нормальную сортировку по алфавиту
  9.  */
  10. namespace Lab2_mod3
  11. {
  12.     class Class1
  13.     {
  14.         const int LENGTH_ARR = 4;
  15.         static private ORDER[] operations = new ORDER[LENGTH_ARR];
  16.         struct ORDER
  17.         {
  18.             private string payerCurrentAcc;
  19.             private string recipientCurrentAcc;
  20.             private decimal sumRUB;
  21.  
  22.  
  23.             public string PayerCurrentAcc
  24.             {
  25.                 get { return payerCurrentAcc;  }
  26.                 set
  27.                 {
  28.                     if (value.Length > 0) payerCurrentAcc = value;
  29.                     else
  30.                     {
  31.                         Console.WriteLine("Ошибка! Вы не указали расчетный счет плательщика");
  32.                         Menu();
  33.                     }
  34.                 }
  35.             }
  36.             public string RecipientCurrentAcc
  37.             {
  38.                 get { return recipientCurrentAcc; }
  39.                 set
  40.                 {
  41.                     if ("" != value) recipientCurrentAcc = value;
  42.                     else
  43.                     {
  44.                         Console.WriteLine("Ошибка! Вы не указали расчетный счет получателя");
  45.                         Menu();
  46.                     }
  47.                 }
  48.             }
  49.             public decimal SumRUB
  50.             {
  51.                 get { return sumRUB; }
  52.                 set
  53.                 {
  54.                     if (0 != value) sumRUB = value;
  55.                     else
  56.                     {
  57.                         Console.WriteLine("Ошибка! Вы не указали перечисляемую сумму");
  58.                         Menu();
  59.                     }
  60.                 }
  61.             }
  62.  
  63.             public ORDER(string payerCurrentAcc_, string recipientCurrentAcc_, decimal sumRUB_)
  64.             {
  65.                 payerCurrentAcc = payerCurrentAcc_;
  66.                 recipientCurrentAcc = recipientCurrentAcc_;
  67.                 sumRUB = sumRUB_;
  68.             }
  69.  
  70.  
  71.         }
  72.  
  73.         static void Main()
  74.         {
  75.             if(checkAccount("12AB")) Console.WriteLine("true1");
  76.             if(checkAccount("azz")) Console.WriteLine("true2");
  77.             Console.WriteLine("-------------------------------------------------");
  78.             Console.WriteLine("--------------------Lab2_mod3--------------------");
  79.             Console.WriteLine("-------------------------------------------------");
  80.             Console.WriteLine();
  81.             Console.WriteLine("Введите данные платежей");
  82.  
  83.             string read;
  84.             ORDER temp;
  85.             decimal temp2;
  86.             int k = 0;
  87.  
  88.             Console.WriteLine("------- Операция {0} ------", 1);
  89.             Console.Write("Введите расчетный счет плательщика: ");
  90.             operations[0].PayerCurrentAcc = Console.ReadLine();
  91.             Console.Write("Введите расчетный счет получателя: ");
  92.             operations[0].RecipientCurrentAcc = Console.ReadLine();
  93.  
  94.             Console.Write("Введите сумму операции в рублях: ");
  95.             if (decimal.TryParse(Console.ReadLine(), out temp2))
  96.             {
  97.                 operations[0].SumRUB = temp2;
  98.             }
  99.             else { Console.WriteLine("Ошибка преобразования!"); }
  100.  
  101.  
  102.             for (int i = 1; i < LENGTH_ARR; i++)
  103.             {
  104.                 Console.WriteLine("------- Операция {0} ------", i+1);
  105.                 Console.Write("Введите расчетный счет плательщика: ");
  106.                 read = Console.ReadLine();
  107.  
  108.                 operations[i].PayerCurrentAcc = read;
  109.  
  110.                 Console.Write("Введите расчетный счет получателя: ");
  111.                 operations[i].RecipientCurrentAcc = Console.ReadLine();
  112.  
  113.                 Console.Write("Введите сумму операции в рублях: ");
  114.                 if (decimal.TryParse(Console.ReadLine(), out temp2))
  115.                 {
  116.                     operations[i].SumRUB = temp2;
  117.                 }
  118.                 else { Console.WriteLine("Ошибка преобразования!"); }
  119.  
  120.                 k = i;
  121.  
  122.                 while ( k > 0 && operations[k].PayerCurrentAcc[0] < operations[k-1].PayerCurrentAcc[0] )
  123.                 {
  124.                     temp = operations[k - 1];
  125.                     operations[k - 1] = operations[k];
  126.                     operations[k] = temp;
  127.                     k--;
  128.                 }
  129.  
  130.             }
  131.             Menu();
  132.  
  133.             Console.ReadKey();
  134.         }
  135.  
  136.         static void Menu()
  137.         {
  138.  
  139.             try
  140.             {
  141.                 Console.WriteLine("-------------------------------------------------");
  142.                 Console.WriteLine("----------------------Menu-----------------------");
  143.                 Console.WriteLine("-------------------------------------------------");
  144.                 Console.WriteLine("1.Получить сумму, снятую с рассчетного счета плательщика");
  145.                 Console.WriteLine("2.Вывести информацию по всем платежам");
  146.                 Console.WriteLine("3.Выход");
  147.  
  148.                 switch (Convert.ToInt32(Console.ReadLine()))
  149.                 {
  150.                     case 1:
  151.                         string account;
  152.                         decimal sum = 0;
  153.                         Console.Write("Введите расчетный счет: ");
  154.                         account = Console.ReadLine();
  155.                         for (int i = 0; i < LENGTH_ARR; i++)
  156.                         {
  157.                             if (account == operations[i].PayerCurrentAcc) sum += operations[i].SumRUB;
  158.                         }
  159.                         if (0 != sum) Console.WriteLine("С этого счета было снято: {0}", sum);
  160.                         else Console.WriteLine("С этого счета деньги не снимались!");
  161.                         Menu();
  162.                         break;
  163.                     case 2:
  164.                         for (int i = 0; i < LENGTH_ARR; i++)
  165.                         {
  166.                             Console.WriteLine("------- Операция {0} ------", i + 1);
  167.                             Console.WriteLine("Расчетный счет плательщика: {0}", operations[i].PayerCurrentAcc);
  168.                             Console.WriteLine("Расчетный счет получателя: {0}", operations[i].RecipientCurrentAcc);
  169.                             Console.WriteLine("Сумма операции в рублях: {0}", operations[i].SumRUB);
  170.                         }
  171.                         Menu();
  172.                         break;
  173.                     case 3:
  174.                         Environment.Exit(0);
  175.                         break;
  176.                     default:
  177.                         Console.WriteLine("Ошибка ввода, повторите попытку!");
  178.                         Menu();
  179.                         break;
  180.                 }
  181.             }
  182.             catch
  183.             {
  184.             }
  185.         }
  186.  
  187.         static bool checkAccount(string str)
  188.         {
  189.             bool status = false;
  190.             status = Regex.IsMatch(str, @"\b[a-z]");
  191.             return status;
  192.         }
  193.  
  194.     }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement