Advertisement
Vladislav_Bezruk

Untitled

Apr 8th, 2022
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.58 KB | None | 0 0
  1. /*
  2. САМОСТІЙНО визначити будь-який базовий клас і класи, похідні від нього із
  3. застосуванням віртуальних функцій.
  4.  
  5. Animals --> Mammals
  6.      \
  7.       \ --> Birds
  8. */
  9. /*
  10.  * Created by SharpDevelop.
  11.  * User: vladyslavbezruk
  12.  * Date: 08.04.2022
  13.  * Time: 20:15
  14.  *
  15.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  16.  */
  17. using System;
  18.  
  19. namespace task_2
  20. {
  21.     class Animals
  22.     {
  23.         protected double weight;
  24.         protected int lifetime;
  25.        
  26.         public Animals()
  27.         {
  28.             weight = 0;
  29.             lifetime = 0;
  30.         }
  31.        
  32.         public virtual void input()
  33.         {
  34.             Console.WriteLine("Enter info about animal:");
  35.             Console.WriteLine("weight:");
  36.             weight = Convert.ToDouble(Console.ReadLine());
  37.             Console.WriteLine("lifetime:");
  38.             lifetime = Convert.ToInt32(Console.ReadLine());
  39.             Console.WriteLine("\n");
  40.         }
  41.        
  42.         public virtual void output()
  43.         {
  44.             Console.WriteLine("Info about animal:");
  45.             Console.WriteLine("weight: {0}", weight);
  46.             Console.WriteLine("lifetime: {0}", lifetime);
  47.             Console.WriteLine("\n");
  48.         }
  49.        
  50.         public virtual void action()
  51.         {
  52.             Console.WriteLine("I am an animal. I live " + lifetime + " years");
  53.             Console.Write('\n');
  54.         }
  55.     }
  56.    
  57.     class Mammals : Animals
  58.     {
  59.         private string coat_color;
  60.        
  61.         public Mammals() : base()
  62.         {
  63.             coat_color = "None";
  64.         }
  65.        
  66.         public virtual void input()
  67.         {
  68.             Console.WriteLine("Enter info about mammal:");
  69.             Console.WriteLine("weight:");
  70.             weight = Convert.ToDouble(Console.ReadLine());
  71.             Console.WriteLine("lifetime:");
  72.             lifetime = Convert.ToInt32(Console.ReadLine());
  73.             Console.WriteLine("coat color:");
  74.             coat_color = Console.ReadLine();
  75.             Console.WriteLine("\n");
  76.         }
  77.        
  78.         public virtual void output()
  79.         {
  80.             Console.WriteLine("Info about mammal:");
  81.             Console.WriteLine("weight: {0}", weight);
  82.             Console.WriteLine("lifetime: {0}", lifetime);
  83.             Console.WriteLine("coat color: " + coat_color);
  84.             Console.WriteLine("\n");
  85.         }
  86.        
  87.         public virtual void action()
  88.         {
  89.             Console.WriteLine("I am a mammal. I have a " + coat_color + " coat");
  90.             Console.Write('\n');
  91.         }
  92.     }
  93.    
  94.     class Birds : Animals
  95.     {
  96.         private string feather_color;
  97.        
  98.         public Birds() : base()
  99.         {
  100.             feather_color = "None";
  101.         }
  102.        
  103.         public virtual void input()
  104.         {
  105.             Console.WriteLine("Enter info about bird:");
  106.             Console.WriteLine("weight:");
  107.             weight = Convert.ToDouble(Console.ReadLine());
  108.             Console.WriteLine("lifetime:");
  109.             lifetime = Convert.ToInt32(Console.ReadLine());
  110.             Console.WriteLine("feather color:");
  111.             feather_color = Console.ReadLine();
  112.             Console.WriteLine("\n");
  113.         }
  114.        
  115.         public virtual void output()
  116.         {
  117.             Console.WriteLine("Info about bird:");
  118.             Console.WriteLine("weight: {0}", weight);
  119.             Console.WriteLine("lifetime: {0}", lifetime);
  120.             Console.WriteLine("feather color: " + feather_color);
  121.             Console.WriteLine("\n");
  122.         }
  123.        
  124.         public virtual void action()
  125.         {
  126.             Console.WriteLine("I am a bird. I have a " + feather_color + " feathers");
  127.             Console.Write('\n');
  128.         }
  129.     }
  130.    
  131.     class Program
  132.     {
  133.         public static void Main(string[] args)
  134.         {
  135.             Animals animal = new Animals();
  136.             Mammals mammal = new Mammals();
  137.             Birds bird = new Birds();
  138.            
  139.             animal.input();
  140.             animal.output();
  141.             animal.action();
  142.            
  143.             mammal.input();
  144.             mammal.output();
  145.             mammal.action();
  146.            
  147.             bird.input();
  148.             bird.output();
  149.             bird.action();
  150.            
  151.             // TODO: Implement Functionality Here
  152.            
  153.             Console.Write("Press any key to continue . . . ");
  154.             Console.ReadKey(true);
  155.         }
  156.     }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement