Advertisement
damesova

DemoOOP

Feb 6th, 2024
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.45 KB | None | 0 0
  1. // Клас Student
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Net.NetworkInformation;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Xml.Linq;
  10.  
  11. namespace DemoOOP
  12. {
  13.     public class Student : Person
  14.     {
  15.         // Полета - Състояние
  16.         private int Pin;
  17.         private string Name;
  18.         private string LastName;
  19.         private double gradeBEL;
  20.  
  21.         public Student(int Pin, string Name, string LastName, double grade) : base(Pin, Name, LastName)
  22.         {
  23.             this.Pin = Pin;
  24.             this.Name = Name;
  25.             this.LastName = LastName;
  26.             this.gradeBEL = grade;
  27.         }
  28.  
  29.         // ctor с параметри)
  30.  
  31.  
  32.  
  33.         // Метод за изчисляване на средна оценка по два предмета
  34.         public double CalcAvgGrade(double grade1, double grade2)
  35.         {
  36.             double avg = (grade1 + grade2)/2;
  37.            
  38.  
  39.             return avg;
  40.         }
  41.  
  42.         // Метод за принтиране данните на обект в конзолата
  43.         public void PrintData()
  44.         {
  45.             Console.WriteLine(this.Pin);
  46.             Console.WriteLine(this.Name);
  47.             Console.WriteLine(this.LastName);
  48.             Console.WriteLine(this.gradeBEL);
  49.         }
  50.  
  51.     }
  52. }
  53.  
  54. //==============================================
  55.  
  56. Клас Person
  57.  
  58. using System;
  59. using System.Collections.Generic;
  60. using System.Linq;
  61. using System.Text;
  62. using System.Threading.Tasks;
  63.  
  64. namespace DemoOOP
  65. {
  66.     public class Person
  67.     {
  68.  
  69.         private int Pin;
  70.         private string Name;
  71.         private string LastName;
  72.  
  73.  
  74.         public Person( int Pin,  string Name, string LastName)
  75.         {
  76.             this.Pin = Pin;
  77.             this.Name = Name;
  78.             this.LastName = LastName;
  79.         }
  80.     }
  81. }
  82.  
  83.  
  84. //================================================
  85.  
  86. // Клас Program
  87.  
  88. namespace DemoOOP
  89. {
  90.     internal class Program
  91.     {
  92.         static void Main(string[] args)
  93.         {
  94.            
  95.  
  96.             Console.WriteLine("==================================");
  97.  
  98.             Console.WriteLine("Created by ctor with parameters");
  99.             Student student2 = new Student(1234567890, "Milena", "Damesova", 4.55);
  100.             student2.PrintData();
  101.             Console.WriteLine(student2.CalcAvgGrade(4.55, 6.00));
  102.  
  103.  
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement