Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- using System.Xml.Serialization;
- namespace WindowsFormsApplication4
- {
- public partial class Form1 : Form
- {
- public abstract class Figura
- {
- public string nazwa;
- public double bok1;
- public double bok2;
- protected Figura(string nazwa, double bok1, double bok2)
- {
- this.nazwa = nazwa;
- this.bok1 = bok1;
- this.bok2 = bok2;
- }
- public abstract void pokaz();
- public abstract void obwod();
- };
- public class Prostokat : Figura
- {
- public string kolor;
- public Prostokat(string nazwa, double bok1, double bok2, string kolor)
- : base(nazwa, bok1, bok2)
- {
- this.kolor = kolor;
- }
- public override void pokaz()
- {
- System.Console.WriteLine("Prostokat " + kolor + " " + nazwa + " " + bok1 + " " + bok2);
- }
- public override void obwod()
- {
- System.Console.WriteLine("Obwod " + (2 * bok1 + 2 * bok2));
- }
- };
- public class Trojkat : Figura
- {
- public string kolor;
- public Trojkat(string nazwa, double bok1, double bok2, string kolor)
- : base(nazwa, bok1, bok2)
- {
- this.kolor = kolor;
- }
- public override void pokaz()
- {
- System.Console.WriteLine("Trojkat " + kolor + " " + nazwa + " " + bok1 + " " + bok2);
- }
- public override void obwod()
- {
- System.Console.WriteLine("Obwod " + (2 * bok1 + bok2));
- }
- }
- List<Figura> lista = new List<Figura>();
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- string nazwa_temp = this.nazwa1.Text;
- string kolor_temp = this.kolor1.Text;
- double bok1_temp = Double.Parse(this.bok11.Text);
- double bok2_temp = Double.Parse(this.bok22.Text);
- if (this.Trojkat1.Checked)
- {
- lista.Add(new Trojkat(nazwa_temp, bok1_temp, bok2_temp, kolor_temp));
- }
- else
- {
- lista.Add(new Prostokat(nazwa_temp, bok1_temp, bok2_temp, kolor_temp));
- }
- StringBuilder wyj2 = new StringBuilder();
- for (int i = 0; i < lista.Count; i++)
- {
- wyj2 = wyj2.Append(lista[i].nazwa + " " + lista[i].bok1 + " " + lista[i].bok2 + System.Environment.NewLine);
- }
- using (StreamWriter ff = new StreamWriter(@"c:\temp\lab4_z2_out.txt"))
- { ff.Write(wyj2); }
- }
- catch
- {
- MessageBox.Show("ERROR");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement