예제 #1
0
 public static void Input_Info(institude i)
 {
     Console.WriteLine("Input name: ");
     i.Name = Console.ReadLine();
     try
     {
         Console.WriteLine("Input number of pupils: ");
         i.Amount_Pupils = int.Parse(Console.ReadLine());
         Console.WriteLine("Input years of studying: ");
         i.Year_Studying = int.Parse(Console.ReadLine());
         Console.WriteLine("Input facility number: ");
         i.Number = int.Parse(Console.ReadLine());
         Console.WriteLine("Input number of staff members: ");
         i.Amount_staff = int.Parse(Console.ReadLine());
     }
     catch (System.FormatException)
     {
         Console.WriteLine("Invalid input!");
     }
 }
예제 #2
0
        static void Main(string[] args)
        {
            institude[] arr        = new institude[2];
            School      school     = new School();
            University  university = new University();

            Console.WriteLine("Input school information:");
            Input_Info(school);
            Console.WriteLine("Input university information:");
            Input_Info(university);
            arr[0] = school;
            arr[1] = university;
            for (; ;)
            {
                string[] action;
                int      i;
                Console.WriteLine("Input 1 to choose school or 2 to choose university: ");
                int.TryParse(Console.ReadLine(), out i);
                i--;
                Console.WriteLine("Actions: ");
                Console.WriteLine("sn 'name' to set name\t\t\t\tgn to get name");
                Console.WriteLine("sp 'pupils' to set pupils\t\t\tgp to get pupils");
                Console.WriteLine("sy 'years' to set years\t\t\t\tgy to get years;");
                Console.WriteLine("su 'number' to set number\t\t\tgu to get number ");
                Console.WriteLine("st 'staff' to set staff\t\t\t\tgt to get staff");
                Console.WriteLine("pa to print all info\t\t\t\tex to exit");
                Console.WriteLine("Input: ");
                action = Console.ReadLine().Split(" ");
                if (action[0] == "sn")
                {
                    arr[0].Name = action[1];
                }
                try
                {
                    if (action[0] == "sp")
                    {
                        arr[0].Amount_Pupils = int.Parse(action[1]);
                    }
                    if (action[0] == "sy")
                    {
                        arr[0].Year_Studying = int.Parse(action[1]);
                    }
                    if (action[0] == "su")
                    {
                        arr[0].Number = int.Parse(action[1]);
                    }
                    if (action[0] == "st")
                    {
                        arr[0].Amount_staff = int.Parse(action[1]);
                    }
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Invalid input!");
                }
                if (action[0] == "gn")
                {
                    Console.WriteLine($"Name: {arr[i].Name}");
                }
                if (action[0] == "gp")
                {
                    Console.WriteLine($"Pupils: {arr[i].Amount_Pupils}");
                }
                if (action[0] == "gy")
                {
                    Console.WriteLine($"Years: {arr[i].Year_Studying}");
                }
                if (action[0] == "gu")
                {
                    Console.WriteLine($"Number: {arr[i].Number}");
                }
                if (action[0] == "gq")
                {
                    Console.WriteLine($"Staff: {arr[i].Amount_staff}");
                }
                if (action[0] == "pa")
                {
                    Console.WriteLine(arr[i].GetInfo());
                }
                if (action[0] == "ex")
                {
                    break;
                }
            }
        }