Advertisement
Guest User

Window

a guest
May 25th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.42 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using System.IO;
  12. using System.Xml.Serialization;
  13.  
  14. namespace WindowsFormsApplication4
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public abstract class Figura
  19.         {
  20.             public string nazwa;
  21.             public double bok1;
  22.             public double bok2;
  23.  
  24.             protected Figura(string nazwa, double bok1, double bok2)
  25.             {
  26.                 this.nazwa = nazwa;
  27.                 this.bok1 = bok1;
  28.                 this.bok2 = bok2;
  29.             }
  30.  
  31.             public abstract void pokaz();
  32.             public abstract void obwod();
  33.         };
  34.  
  35.         public class Prostokat : Figura
  36.         {
  37.             public string kolor;
  38.             public Prostokat(string nazwa, double bok1, double bok2, string kolor)
  39.                 : base(nazwa, bok1, bok2)
  40.             {
  41.                 this.kolor = kolor;
  42.             }
  43.  
  44.  
  45.             public override void pokaz()
  46.             {
  47.                 System.Console.WriteLine("Prostokat " + kolor + " " + nazwa + " " + bok1 + " " + bok2);
  48.             }
  49.             public override void obwod()
  50.             {
  51.                 System.Console.WriteLine("Obwod " + (2 * bok1 + 2 * bok2));
  52.             }
  53.         };
  54.  
  55.         public class Trojkat : Figura
  56.         {
  57.             public string kolor;
  58.             public Trojkat(string nazwa, double bok1, double bok2, string kolor)
  59.                 : base(nazwa, bok1, bok2)
  60.             {
  61.                 this.kolor = kolor;
  62.             }
  63.  
  64.  
  65.             public override void pokaz()
  66.             {
  67.                 System.Console.WriteLine("Trojkat " + kolor + " " + nazwa + " " + bok1 + " " + bok2);
  68.             }
  69.             public override void obwod()
  70.             {
  71.                 System.Console.WriteLine("Obwod " + (2 * bok1 + bok2));
  72.             }
  73.         }
  74.         List<Figura> lista = new List<Figura>();
  75.    
  76.  
  77.         public Form1()
  78.         {
  79.             InitializeComponent();
  80.         }
  81.  
  82.         private void button1_Click(object sender, EventArgs e)
  83.         {
  84.             try
  85.             {
  86.                 string nazwa_temp = this.nazwa1.Text;
  87.                 string kolor_temp = this.kolor1.Text;
  88.                 double bok1_temp = Double.Parse(this.bok11.Text);
  89.                 double bok2_temp = Double.Parse(this.bok22.Text);
  90.                 if (this.Trojkat1.Checked)
  91.                 {
  92.                    lista.Add(new Trojkat(nazwa_temp, bok1_temp, bok2_temp, kolor_temp));
  93.                 }
  94.                 else
  95.                 {
  96.                    
  97.                     lista.Add(new Prostokat(nazwa_temp, bok1_temp, bok2_temp, kolor_temp));
  98.                 }
  99.                
  100.                 StringBuilder wyj2 = new StringBuilder();
  101.                 for (int i = 0; i < lista.Count; i++)
  102.                 {
  103.                     wyj2 = wyj2.Append(lista[i].nazwa + " " + lista[i].bok1 + " " + lista[i].bok2 + System.Environment.NewLine);
  104.  
  105.                 }
  106.                 using (StreamWriter ff = new StreamWriter(@"c:\temp\lab4_z2_out.txt"))
  107.                 { ff.Write(wyj2); }
  108.  
  109.      
  110. }
  111.  
  112.  
  113.  
  114.            
  115.             catch
  116.             {
  117.                 MessageBox.Show("ERROR");
  118.             }
  119.  
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement