Advertisement
maxlarin2

lab8

Mar 15th, 2014
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace classlab8
  7. {
  8.     class student_group
  9.     {
  10.         main check = new main();
  11.         public string[,] Data;
  12.         int length;
  13.         private void print(int index)
  14.         {
  15.             for (int i = 0; i < 4; i++)
  16.             {
  17.                 Console.Write("{0}  ",Data[index, i]);
  18.             }
  19.         }
  20.         public student_group(int size)
  21.         {
  22.             Data = new string[size, 4];
  23.             length = size;
  24.         }
  25.         public void data(string name)
  26.         {
  27.             bool is_exist = false;
  28.             for (int i = 0; i < length; i++)
  29.             {
  30.                 if (name == Data[i, 0] || name == Data[i,1])
  31.                 {
  32.                     print(i);
  33.                     is_exist = true;
  34.                 }
  35.             }
  36.             if (is_exist == false) Console.WriteLine("Записей не найдено!");
  37.         }
  38.         public string this[int i]
  39.         {
  40.             get
  41.             {
  42.                 string temp = "";
  43.                 if (i >= 0 && i < length) { return temp; }
  44.                 else { return "Noname"; }
  45.             }
  46.             set
  47.             {
  48.                 if (i >= 0 && i < length)
  49.                 {
  50.                     string[] mas = value.Split(new char[] {' ','\n','\r','\t', '.'});
  51.                     Data[i, 0] = mas[0];
  52.                     Data[i, 1] = mas[1];
  53.                     Data[i, 2] = Convert.ToString(main.longread(mas[2]));
  54.                     Data[i, 3] = Convert.ToString(main.read(mas[3]))+ "." + Convert.ToString(main.read(mas[4])) + "."+ Convert.ToString(main.read(mas[5]));
  55.                 }
  56.             }
  57.         }
  58.     }
  59.     class main
  60.     {
  61.         static void Main(string[] args)
  62.         {
  63.             int length;
  64.             length = read(Console.ReadLine());
  65.             student_group create = new student_group(length);
  66.             for (int i = 0; i < length; i++)
  67.             {
  68.                 create[i] = Console.ReadLine();
  69.             }
  70.             Console.WriteLine("Введите позицию для поиска:\n1: Фамилия(Имя)");
  71.             int switch_on = read(Console.ReadLine());
  72.             switch (switch_on)
  73.             {
  74.                case 1:Console.WriteLine("Введите фамилию или имя для поиска:");
  75.                     create.data(Console.ReadLine()); break;
  76.                case 2: Console.WriteLine("Введите номер телефона:");
  77.                    create.data(Convert.ToString(read(Console.ReadLine()))); break;
  78.                case 3: Console.WriteLine("Введите дату рождения для поиска:");
  79.                    create.data(Console.ReadLine()); break;
  80.             }
  81.            
  82.             Console.ReadKey();
  83.         }
  84.         public static bool check(string s)
  85.         {
  86.             long tmp;
  87.             if (long.TryParse(s,out tmp)) return true;
  88.             else return false;
  89.         }
  90.         public static int read(string stream)
  91.         {
  92.             while (!check(stream))
  93.             {
  94.                 Console.WriteLine("Введите число!");
  95.                 stream = Console.ReadLine();
  96.             }
  97.             return Convert.ToInt16(stream);
  98.         }
  99.         public static long longread(string stream)
  100.         {
  101.             while (!check(stream))
  102.             {
  103.                 Console.WriteLine("Введите число!");
  104.                 stream = Console.ReadLine();
  105.             }
  106.             return Convert.ToInt64(stream);
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement