Advertisement
Guest User

C#Lab

a guest
May 29th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     public class Program
  9.     {
  10.  
  11.         public abstract class Student
  12.         {
  13.         protected string imie;
  14.         protected string nazwisko;
  15.         protected int nr_indeksu;
  16.             public Student(string x,string y,int z) //konstruktor
  17.             {
  18.                 this.imie = x;
  19.                 this.nazwisko = y;
  20.                 this.nr_indeksu = z;
  21.             }
  22.  
  23.             public abstract void Pokaz();
  24.             public abstract void NajlepszaUczelnia();
  25.  
  26.         }
  27.         public class StudentUniwersytetu : Student
  28.         {
  29.             string uczelnia;
  30.             string specjalnosc;
  31.             public StudentUniwersytetu(string x, string y, int z) : base(x, y, z) //konstruktor SU
  32.             {
  33.                 this.uczelnia = "Uniwersytet";
  34.                 this.specjalnosc = "Teoria";
  35.             }
  36.             public override void Pokaz()  //Polimorfizm przez nadpisanie Pokaz()
  37.             {
  38.                 System.Console.WriteLine("->Klasa Student Uniwersytetu: ");
  39.                 System.Console.WriteLine("->Imię studenta : " + imie);
  40.                 System.Console.WriteLine("->Nazwisko : " + nazwisko);
  41.                 System.Console.WriteLine("->Nr indeksu : " + nr_indeksu);
  42.                 System.Console.WriteLine("->Specjalnosc : " + specjalnosc);
  43.             }
  44.             public override void NajlepszaUczelnia()  //Polimorfizm przez nadpisanie NajlepszaUczelnia()
  45.             {
  46.                 System.Console.WriteLine("->Najlepsza uczelnia: " + uczelnia);
  47.             }
  48.         }
  49.         public class StudentPolitechniki : Student
  50.         {
  51.             string uczelnia;
  52.             string specjalnosc;
  53.             public StudentPolitechniki(string x, string y, int z) : base(x, y, z) //konstruktor SP
  54.             {
  55.                 this.uczelnia = "Politechnika";
  56.                 this.specjalnosc = "Improwizacja";
  57.             }
  58.             public override void Pokaz()  //Polimorfizm przez nadpisanie Pokaz()
  59.             {
  60.                 System.Console.WriteLine("Klasa Student Politechniki: ");
  61.                 System.Console.WriteLine("->Imię studenta : " + imie);
  62.                 System.Console.WriteLine("->Nazwisko : " + nazwisko);
  63.                 System.Console.WriteLine("->Nr indeksu : " + nr_indeksu);
  64.                 System.Console.WriteLine("->Specjalnosc : " + specjalnosc);
  65.             }
  66.             public override void NajlepszaUczelnia()  //Polimorfizm przez nadpisanie NajlepszaUczelnia()
  67.             {
  68.                 System.Console.WriteLine("->Najlepsza uczelnia: " + uczelnia);
  69.             }
  70.         }
  71.  
  72.         public static void Main(string[] args)
  73.         {
  74.  
  75.             // Create an instance of Manager and assign it to a Manager reference:
  76.             StudentPolitechniki m1 = new StudentPolitechniki("H.", "Ackerman ", 133222);
  77.             m1.Pokaz();
  78.             m1.NajlepszaUczelnia();
  79.             System.Console.WriteLine("------------------------------------------------------------");
  80.             StudentUniwersytetu m2 = new StudentUniwersytetu("M.", "Borawski", 111122);
  81.             m2.Pokaz();
  82.             m2.NajlepszaUczelnia();
  83.  
  84.             // Create an instance of Manager and assign it to an Employee reference:
  85.             /*Employee ee1 = new Manager("M. Knott");
  86.             ee1.Show();  //call the show method of the Manager class*/
  87.         }
  88.     }
  89. }
  90. //#######################################################
  91. using System;
  92. using System.Collections.Generic;
  93. using System.ComponentModel;
  94. using System.Data;
  95. using System.Drawing;
  96. using System.Linq;
  97. using System.Text;
  98. using System.Windows.Forms;
  99.  
  100. namespace WindowsFormsApplication1
  101. {
  102.     public partial class Form1 : Form
  103.     {
  104.         public abstract class Student
  105.         {
  106.             public string imie;
  107.             public string nazwisko;
  108.             public int nr_indeksu;
  109.             public Student(string x,string y,int z) //konstruktor
  110.             {
  111.                 this.imie = x;
  112.                 this.nazwisko = y;
  113.                 this.nr_indeksu = z;
  114.             }
  115.  
  116.             public abstract void Pokaz();
  117.             public abstract void NajlepszaUczelnia();
  118.  
  119.         }
  120.         public class StudentUniwersytetu : Student
  121.         {
  122.             string uczelnia;
  123.             string specjalnosc;
  124.             public StudentUniwersytetu(string x, string y, int z)
  125.                 : base(x, y, z) //konstruktor SU
  126.             {
  127.                 this.uczelnia = "Uniwersytet";
  128.                 this.specjalnosc = "Teoria";
  129.             }
  130.             public override void Pokaz()  //Polimorfizm przez nadpisanie Pokaz()
  131.             {
  132.                 System.Console.WriteLine("->Klasa Student Uniwersytetu: ");
  133.                 System.Console.WriteLine("->Imię studenta : " + imie);
  134.                 System.Console.WriteLine("->Nazwisko : " + nazwisko);
  135.                 System.Console.WriteLine("->Nr indeksu : " + nr_indeksu);
  136.                 System.Console.WriteLine("->Specjalnosc : " + specjalnosc);
  137.             }
  138.             public override void NajlepszaUczelnia()  //Polimorfizm przez nadpisanie NajlepszaUczelnia()
  139.             {
  140.                 System.Console.WriteLine("->Najlepsza uczelnia: " + uczelnia);
  141.             }
  142.         }
  143.         public class StudentPolitechniki : Student
  144.         {
  145.             string uczelnia;
  146.             string specjalnosc;
  147.             public StudentPolitechniki(string x, string y, int z)
  148.                 : base(x, y, z) //konstruktor SP
  149.             {
  150.                 this.uczelnia = "Politechnika";
  151.                 this.specjalnosc = "Improwizacja";
  152.             }
  153.             public override void Pokaz()  //Polimorfizm przez nadpisanie Pokaz()
  154.             {
  155.                 System.Console.WriteLine("Klasa Student Politechniki: ");
  156.                 System.Console.WriteLine("->Imię studenta : " + imie);
  157.                 System.Console.WriteLine("->Nazwisko : " + nazwisko);
  158.                 System.Console.WriteLine("->Nr indeksu : " + nr_indeksu);
  159.                 System.Console.WriteLine("->Specjalnosc : " + specjalnosc);
  160.             }
  161.             public override void NajlepszaUczelnia()  //Polimorfizm przez nadpisanie NajlepszaUczelnia()
  162.             {
  163.                 System.Console.WriteLine("->Najlepsza uczelnia: " + uczelnia);
  164.             }
  165.         }
  166.         System.Collections.Generic.List<Student> studenci = new System.Collections.Generic.List<Student>();
  167.         public Form1()
  168.         {
  169.             InitializeComponent();
  170.         }
  171.  
  172.         private void Form1_Load(object sender, EventArgs e)
  173.         {
  174.  
  175.         }
  176.  
  177.         private void button2_Click(object sender, EventArgs e)
  178.         {
  179.             string imi = textBox1.Text;
  180.             string nazw = textBox2.Text;
  181.             string indeks = textBox3.Text;
  182.             int indek = Int32.Parse(indeks);
  183.             if (radioButton1.Checked)
  184.             {
  185.                 studenci.Add(new StudentPolitechniki(imi, nazw, indek));
  186.             }
  187.             else if (radioButton2.Checked)
  188.             {
  189.                 studenci.Add(new StudentUniwersytetu(imi, nazw, indek));
  190.             }
  191.            
  192.  
  193.  
  194.  
  195.         }
  196.  
  197.         private void textBox3_TextChanged(object sender, EventArgs e)
  198.         {
  199.  
  200.         }
  201.  
  202.         private void button1_Click(object sender, EventArgs e)
  203.         {
  204.             foreach (Student s in studenci)
  205.             {
  206.                 MessageBox.Show("Klasa Student Politechniki: ->Imię studenta : " + s.imie + "->Nazwisko : " + s.nazwisko + "->Nr indeksu : " + s.nr_indeksu);
  207.             }
  208.             /*foreach (StudentUniwersytetu s in studenci)
  209.             {
  210.                 MessageBox.Show("Klasa Student Politechniki: ->Imię studenta : " + s.imie + "->Nazwisko : " + s.nazwisko + "->Nr indeksu : " + s.nr_indeksu);
  211.             }*/
  212.         }
  213.  
  214.         private void textBox1_TextChanged(object sender, EventArgs e)
  215.         {
  216.  
  217.         }
  218.  
  219.         private void textBox2_TextChanged(object sender, EventArgs e)
  220.         {
  221.  
  222.         }
  223.     }
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement