コード例 #1
0
ファイル: Filecs.cs プロジェクト: AEkaterina/OOP_3_sem
        public static void LoadFromFile(ref CollectionType <Playground> objCollectionType)
        {
            string text = "";

            using (StreamReader sr = new StreamReader(@"D:\studing\OOP\labs\Lab_8\Lab_8\file.txt"))
            {
                while (sr.ReadLine() != null)
                {
                    text = sr.ReadLine();
                    switch (text)
                    {
                    case "Beams":
                        objCollectionType.Add(new Beams(20));
                        break;

                    case "Mats":
                        objCollectionType.Add(new Mats());
                        break;

                    case "Tennis":
                        objCollectionType.Add(new Tennis());
                        break;

                    case "Bench":
                        objCollectionType.Add(new Bench());
                        break;

                    case "Basketball":
                        objCollectionType.Add(new Basketball());
                        break;
                    }
                }
            }
        }
コード例 #2
0
        public static void ParseFile(CollectionType <Plant> objColl)
        {
            using (StreamReader stream = new StreamReader(@"D:\Visual\3 sem\5-th Lab\Read.txt"))
            {
                while (stream.ReadLine() is string line)
                {
                    switch (line)
                    {
                    case "Rose":
                        objColl.Add(new Rose());
                        break;

                    case "Bush":
                        objColl.Add(new Bush());
                        break;

                    case "Gladiolus":
                        objColl.Add(new Gladiolus());
                        break;

                    case "Cactus":
                        objColl.Add(new Cactus());
                        break;
                    }
                }
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Tsun4mii/OOP-Labs
        static void Main(string[] args)
        {
            //Console.WriteLine("-----------Розы-------------");
            //Rose rose = new Rose();
            //rose.ToPlant();
            //rose.GetPlants();
            //rose.ToPlant();
            //rose.ToPlant();
            //rose.GetPlants();
            //rose.Pour(3);
            //if (rose is Plant)
            //{
            //    Console.WriteLine($"{rose} is plant");
            //}

            //Console.WriteLine("-----------Кактусы-------------");
            //Cactus cactus = new Cactus();
            //IPot cactus_2 = cactus;
            //cactus_2.ToPlant();
            //cactus.ToPlant();
            //cactus.GetPlants();
            //cactus.Collect();
            //cactus.PutInPot();

            //Console.WriteLine("-----------Гладиолусы-------------");
            //Gladiolus gladiolus = new Gladiolus();
            //gladiolus.ToPlant();
            //gladiolus.ToPlant();
            //gladiolus.Pour(2);
            //gladiolus.Collect();
            //gladiolus.PackIn();

            //Printer printer = new Printer();
            //printer.iAmPrinting(cactus);

            CollectionType <string> obj1 = new CollectionType <string>();
            IGereric <string>       a;

            obj1.Add("bye ");
            obj1.Add("adyos ");
            obj1.Add("sayonara ");
            a = obj1;
            a.Show();

            CollectionType <Plant> plnt = new CollectionType <Plant>();

            plnt.Add(new Rose());
            plnt.Add(new Gladiolus());
            plnt.Add(new Bush());
            plnt.Show();

            Console.WriteLine("\n");
            CollectionType <Plant> obj2 = new CollectionType <Plant>();

            ParseFile(obj2);
            obj2.Show();

            obj2.WriteFile(obj2);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            try
            {
                CollectionType <string> obj1 = new CollectionType <string>();
                IGeneric <string>       a;
                obj1.Add("bye ");
                obj1.Add("adyos ");
                obj1.Add("sayonara ");
                a = obj1;
                a.Show();
                obj1.SaveInFile();

                Console.WriteLine();
                CollectionType <Playground> plGr = new CollectionType <Playground>();
                plGr.Add(new Basketball());
                plGr.Add(new Bench());
                plGr.Add(new Tennis());

                Playground beam = new Beams(12);
                plGr.Add(beam);
                plGr.Show();

                Console.WriteLine();
                plGr.Delete(beam);
                plGr.Show();
                plGr.SaveInFile();

                CollectionType <Playground> pl2 = new CollectionType <Playground>();
                LoadFromFile(ref pl2);
                Console.WriteLine("\nЭлементы файла file.txt:");
                pl2.Show();
            }

            catch (CollectionException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                Console.WriteLine("\nFINALLY");
            }
            Console.ReadLine();
        }