Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Laba3
  4. {
  5.     class Human
  6.     {
  7.         private string _name;
  8.         private int _age;
  9.  
  10.         public string Name
  11.         {
  12.             set
  13.             {
  14.                 if (value == "")
  15.                 {
  16.                     Console.WriteLine("Enter your name, please.");
  17.                 }
  18.                 else
  19.                 {
  20.                     _name = value;
  21.                 }
  22.             }
  23.         }
  24.  
  25.         public int Age
  26.         {
  27.             set
  28.             {
  29.                 if (value <= 0)
  30.                 {
  31.                     Console.WriteLine("Should be positive !");
  32.                 }
  33.                 else
  34.                 {
  35.                     _age = value;
  36.                 }
  37.             }
  38.             get { return _age; }
  39.         }
  40.    
  41.  
  42.  
  43.     public void out_info()
  44.         {
  45.             Console.WriteLine($"Name: {_name}   Age: {Age}");
  46.         }
  47.     }
  48.  
  49.     class Student:Human
  50.     {
  51.         public float average_grade;
  52.         private int _class;
  53.         public bool scholarship;
  54.  
  55.         public int Class {
  56.             set
  57.             {
  58.                 if (value <= 0)
  59.                 {
  60.                     Console.WriteLine("Check your info about your studying year!");
  61.                 }
  62.                 else
  63.                 {
  64.                     _class = value;
  65.                 }
  66.             }
  67.             get { return _class; }
  68.         }
  69.     }
  70.     class Program
  71.     {
  72.  
  73.         static void Main(string[] args)
  74.         {
  75.            Human ellia = new Human();
  76.            Student feda = new Student();
  77.            feda.Age = 19;
  78.            feda.out_info();
  79.            ellia.out_info();
  80.  
  81.            ellia.Age = -9;
  82.            ellia.Name = "Ellia";
  83.            ellia.out_info();
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement