Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- САМОСТІЙНО визначити будь-який базовий клас і класи, похідні від нього із
- застосуванням віртуальних функцій.
- Animals --> Mammals
- \
- \ --> Birds
- */
- /*
- * Created by SharpDevelop.
- * User: vladyslavbezruk
- * Date: 08.04.2022
- * Time: 20:15
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- namespace task_2
- {
- class Animals
- {
- protected double weight;
- protected int lifetime;
- public Animals()
- {
- weight = 0;
- lifetime = 0;
- }
- public virtual void input()
- {
- Console.WriteLine("Enter info about animal:");
- Console.WriteLine("weight:");
- weight = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("lifetime:");
- lifetime = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("\n");
- }
- public virtual void output()
- {
- Console.WriteLine("Info about animal:");
- Console.WriteLine("weight: {0}", weight);
- Console.WriteLine("lifetime: {0}", lifetime);
- Console.WriteLine("\n");
- }
- public virtual void action()
- {
- Console.WriteLine("I am an animal. I live " + lifetime + " years");
- Console.Write('\n');
- }
- }
- class Mammals : Animals
- {
- private string coat_color;
- public Mammals() : base()
- {
- coat_color = "None";
- }
- public virtual void input()
- {
- Console.WriteLine("Enter info about mammal:");
- Console.WriteLine("weight:");
- weight = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("lifetime:");
- lifetime = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("coat color:");
- coat_color = Console.ReadLine();
- Console.WriteLine("\n");
- }
- public virtual void output()
- {
- Console.WriteLine("Info about mammal:");
- Console.WriteLine("weight: {0}", weight);
- Console.WriteLine("lifetime: {0}", lifetime);
- Console.WriteLine("coat color: " + coat_color);
- Console.WriteLine("\n");
- }
- public virtual void action()
- {
- Console.WriteLine("I am a mammal. I have a " + coat_color + " coat");
- Console.Write('\n');
- }
- }
- class Birds : Animals
- {
- private string feather_color;
- public Birds() : base()
- {
- feather_color = "None";
- }
- public virtual void input()
- {
- Console.WriteLine("Enter info about bird:");
- Console.WriteLine("weight:");
- weight = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("lifetime:");
- lifetime = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("feather color:");
- feather_color = Console.ReadLine();
- Console.WriteLine("\n");
- }
- public virtual void output()
- {
- Console.WriteLine("Info about bird:");
- Console.WriteLine("weight: {0}", weight);
- Console.WriteLine("lifetime: {0}", lifetime);
- Console.WriteLine("feather color: " + feather_color);
- Console.WriteLine("\n");
- }
- public virtual void action()
- {
- Console.WriteLine("I am a bird. I have a " + feather_color + " feathers");
- Console.Write('\n');
- }
- }
- class Program
- {
- public static void Main(string[] args)
- {
- Animals animal = new Animals();
- Mammals mammal = new Mammals();
- Birds bird = new Birds();
- animal.input();
- animal.output();
- animal.action();
- mammal.input();
- mammal.output();
- mammal.action();
- bird.input();
- bird.output();
- bird.action();
- // TODO: Implement Functionality Here
- Console.Write("Press any key to continue . . . ");
- Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement