Example #1
0
        static void Main()
        {
            const int n = 5;

            airplanes[]  machines = new airplanes[n];
            StreamReader f;

            string[] s = new string[7];
            string   str;

            try {
                f = new StreamReader("C:\\Users\\acer\\Desktop\\input.txt");
            }
            catch (Exception e) {
                Console.WriteLine();
                return;
            }
            int i = 0;

            while ((str = f.ReadLine()) != null)
            {
                s[0] = str.Split(' ')[0];
                s[1] = str.Split(' ')[1];
                s[2] = str.Split(' ')[2];
                s[3] = str.Split(' ')[3];
                s[4] = str.Split(' ')[4];
                s[5] = str.Split(' ')[5];
                if (s[0] == "0")
                {
                    machines[i] = new airplanes(int.Parse(s[1]), int.Parse(s[2]), int.Parse(s[3]), s[4], int.Parse(s[5]));
                    ++i;
                }
                else
                {
                    s[6]        = str.Split(' ')[6];
                    machines[i] = new auto(int.Parse(s[1]), int.Parse(s[2]), int.Parse(s[3]), s[4], int.Parse(s[5]), s[6]);
                    ++i;
                }
            }
            f.Close();
            for (i = 0; i < n; ++i)
            {
                machines[i].info();
            }
            Console.WriteLine();
            FileStream      fs;
            BinaryFormatter form = new BinaryFormatter();

            try{ fs = new FileStream("D:\\a.dat", FileMode.Create, FileAccess.Write); }
            catch (Exception e) {
                Console.WriteLine(e.Message);
                return;
            }
            form.Serialize(fs, machines);
            fs.Close();
            Console.ReadKey();
        }
Example #2
0
        static void Main()
        {
            const int n = 5;

            auto[] machines = new auto[n];

            StreamReader f;

            string[] s = new string[6];
            string   str;

            try
            {
                f = new StreamReader("C:\\Users\\acer\\Desktop\\input1.txt");
            }
            catch (Exception e)
            {
                Console.WriteLine();
                return;
            }
            int i = 0;

            while ((str = f.ReadLine()) != null)
            {
                s[0]        = str.Split(' ')[0];
                s[1]        = str.Split(' ')[1];
                s[2]        = str.Split(' ')[2];
                s[3]        = str.Split(' ')[3];
                s[4]        = str.Split(' ')[4];
                s[5]        = str.Split(' ')[5];
                machines[i] = new auto(int.Parse(s[1]), int.Parse(s[2]), int.Parse(s[3]), s[4], int.Parse(s[5]));
                ++i;
            }
            f.Close();

            for (i = 0; i < n; ++i)
            {
                machines[i].info();
            }
            Console.WriteLine();

            for (i = 0; i < n; ++i)
            {
                if (machines[i] is auto)
                {
                    auto a = (auto)machines[i];
                    Console.WriteLine(a.Power);
                }
            }

            //Console.WriteLine("Введите номер самолета:");
            //int num = int.Parse(Console.ReadLine());

            //for (i = 0; i < n; ++i)
            //    if (mech[i] is airplanes && mech[i].Number == num)
            //        Console.WriteLine("Мощность самолета: " + mech[i].Power + ", максимальная высота полета: " + mech[i].Height + "\n");
            //int max = 0;
            //for (i = 0; i < n; ++i)
            //{
            //    if (mech[i] is auto)
            //    {
            //        auto a = (auto)mech[i];
            //        if (a.Cost > max)
            //            max = a.Cost;
            //    }
            //}
            //for (i = 0; i < n; ++i)
            //{
            //    if (mech[i] is auto)
            //    {
            //        auto a = (auto)mech[i];
            //        if (a.Cost == max)
            //            Console.WriteLine(a.Techvis);
            //    }
            //}

            //double nal = 0;
            //for (i = 0; i < n; ++i)
            //{
            //    if (!(mech[i] is auto))
            //    {
            //        airplanes a = (airplanes)mech[i];
            //        nal += 0.03 * a.Cost;
            //    }
            //}
            //Console.WriteLine(nal);
            Console.ReadKey();
        }