Professional Documents
Culture Documents
ЛР3
ЛР3
Хід роботи:
Текст програми:
using System;
using System.Collections.Generic;
using System.Text;
namespace Lr2
{
class Program
{
static void Main(string[] args)
{
List<Tvar> ar = new List<Tvar>();
int x1, x2;
while (true)
{
Console.WriteLine("Виберіть дію 1 ввід 2 вивід 0 вихід");
int monet = Convert.ToInt32(Console.ReadLine());
if (monet == 1)
{
while (true)
{
Console.WriteLine("Виберіь тип тварин 1 - Птахи; 2 Парнокопитні; 3 - Ссавці; 0 вихід ");
int z = Convert.ToInt32(Console.ReadLine());
if (z == 1)
{
Ptacha a1 = new Ptacha();
a1.vid();
ar.Add(a1);
}
else
if (z == 2)
{
ParnKop a1 = new ParnKop();
a1.vid();
ar.Add(a1);
}
else
if (z == 3)
{
Ssavzi a1 = new Ssavzi();
a1.vid();
ar.Add(a1);
}
else
if (z == 0)
{ break; }
if (ar[i] is Ptacha)
((Ptacha)ar[i]).vivid();
if (ar[i] is ParnKop)
((ParnKop)ar[i]).vivid();
if (ar[i] is Ssavzi)
((Ssavzi)ar[i]).vivid();
}
}
if (z == 2)
{
for (int i = 0; i < ar.Count; i++)
{
if (ar[i] is Ptacha)
((Ptacha)ar[i]).Resuls();
else
if (ar[i] is ParnKop)
((ParnKop)ar[i]).Resuls();
else
((Ssavzi)ar[i]).Resuls();
}
}
else
if (z == 0)
break;
}
}
if (monet == 0)
break;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Lr2
{
class Tvar
{
protected bool srt;
protected string Name, Haus, pri;
public virtual void vid()
{
Console.Write("Назва = ");
Name = Console.ReadLine();
Console.Write("Середовище життя = ");
Haus = Console.ReadLine();
Console.Write("Належить до красної книги(true/false) ");
srt = Convert.ToBoolean(Console.ReadLine());
if (srt == true)
{
Console.Write("Причина вимирання = ");
pri = Console.ReadLine();
}
Арк.
Вим.
2
Арк. № докум. Підпис Дата
}
public virtual void vivid()
{
Console.WriteLine("Назва = " + Name);
Console.WriteLine("Середовище життя= " + Haus);
Console.WriteLine("Вимирає = " + srt);
}
public virtual void Resuls()
{
if (srt == true)
{
Console.WriteLine("Назва = " + Name);
Console.WriteLine("Причина вимирання = " + pri);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Lr2
{
class Ptacha : Tvar
{
string Janr;
public override void vid()
{
base.vid();
Console.WriteLine(" Переважні місця гніздування ");
Janr = Console.ReadLine();
}
public override void vivid()
{
Console.WriteLine("Птахи: ");
base.vivid();
Console.WriteLine("Переважні місця гніздування " + Janr);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Lr2
{
class ParnKop : Tvar
{
string Pred;
public override void vid()
{
base.vid();
Console.Write("Олюблена їжа = ");
Pred = Console.ReadLine();
}
public override void vivid()
{
Console.WriteLine("Парнокопитні: ");
base.vivid();
Console.WriteLine("Олюблена їжа = " + Pred);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Lr2
{
class Ssavzi : Tvar
{
Арк.
Вим.
3
Арк. № докум. Підпис Дата
int Vipusk;
public override void vid()
{
base.vid();
Console.WriteLine("Період вживання молока в днях = ");
Vipusk = Convert.ToInt32(Console.ReadLine());
}
public override void vivid()
{
Console.WriteLine("Ссавці: ");
base.vivid();
Console.WriteLine("Період вживання молока в днях = " + Vipusk);
}
}
}
Арк.
Вим.
4
Арк. № докум. Підпис Дата