Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostram>
- #include<string>
- using namespace std;
- namespace cs_figury_7
- {
- class Figura
- {
- protected string kolor;
- public Figura() { }
- public Figura(string _kolor)
- {
- kolor = _kolor;
- }
- public string getKolor()
- {
- return kolor;
- }
- public void setKolor(string _kolor)
- {
- kolor = _kolor;
- }
- }
- class Punkt
- {
- private int x, y;
- public Punkt() { }
- public Punkt(int _x, int _y)
- {
- x = _x;
- y = _y;
- }
- public Punkt(Punkt P)
- {
- x = P.x;
- y = P.y;
- }
- public int getX()
- {
- return x;
- }
- public int getY()
- {
- return y;
- }
- public override string ToString()
- {
- ostringstream napis;
- napis << "\n(" << x << ";" << y << ") ";
- return napis.str();
- }
- }
- class Linia
- {
- private Punkt p1, p2;
- public Linia() { }
- public Linia(Punkt _p1, Punkt _p2)
- {
- p1 = new Punkt(_p1);
- p2 = new Punkt(_p2);
- }
- public Linia(Linia L)
- {
- p1 = L.p1;
- p2 = L.p2;
- }
- public Punkt getp1()
- {
- return p1;
- }
- public Punkt getp2()
- {
- return p2;
- }
- public override string ToString()
- {
- ostringstream naapis;
- napis << "\n(" << p1.getX() << ";" << p1.getY() << ")\n( "<<p2.getX()<<";"<<p2.getY()<<")";
- return naapis.str();
- }
- }
- class Trojkat : Figura
- {
- private Linia l1, l2, l3;
- public Trojkat() : base() { }
- public Trojkat(Punkt _p1, Punkt _p2, Punkt _p3, string _kolor) : base(_kolor)
- {
- l1 = new Linia(_p1, _p2);
- l2 = new Linia(_p2, _p3);
- l3 = new Linia(_p3, _p1);
- }
- public override string ToString()
- {
- ostringstream naaapis;
- napis << "\n(" << l1.getp1().getX() << ";" << l1.getp1().getY() << ")\n( "<<l1.getp2().getX()<<";"<<l1.getp2().getY()<<")\n("<<l2.getp2().getX()<<";"<<l2.getp2().getY()+")\n"<<getKolor();
- return naaapis.str();
- }
- }
- class Czworokat : Figura
- {
- protected Linia l1, l2, l3, l4;
- public Czworokat() : base() { }
- public Czworokat(Punkt _p1, Punkt _p2, Punkt _p3, Punkt _p4, string _kolor) : base(_kolor)
- {
- l1 = new Linia(_p1, _p2);
- l2 = new Linia(_p2, _p3);
- l3 = new Linia(_p3, _p4);
- l4 = new Linia(_p4, _p1);
- }
- public override string ToString()// nie wiem co z tym
- { ostringstream naaaapis;
- napis << "\n(" << l1.getp1().getX() << ";" << l1.getp1().getY() << ")\n( "<<l1.getp2().getX()<<";"<<l1.getp2().getY()<<")\n("<<l3.getp1().getX()<<";"<<l3.getp1().getY()+")\n("<<l3.getp2().getX()<<";"+l3.getp2().getY()<<")\n"<<getKolor();
- return naaaapis.str();
- }
- }
- class Prostokat : Czworokat
- {
- public Prostokat() : base() { }
- public Prostokat(Punkt pg, Punkt ld, string _kolor) : base(new Punkt(pg.getX(), pg.getY()), new Punkt(pg.getX(), ld.getY()), new Punkt(ld.getX(), ld.getY()), new Punkt(ld.getX(), pg.getY()), _kolor) { }
- }
- class Kwadrat : Prostokat
- {
- public Kwadrat() : base() { }
- public Kwadrat(Punkt p, int dlugosc, string _kolor) : base(p, new Punkt(p.getX() - dlugosc, p.getY() - dlugosc), _kolor) { }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Punkt punkt = null;
- Linia linia = null;
- Trojkat trojkat = null;
- Czworokat czworokat = null;
- Prostokat prostokat = null;
- Kwadrat kwadrat = null;
- int x1, x2, x3, x4, y1, y2, y3, y4, wybor = 0;
- string kolor;
- //Menu
- while (wybor != 9)
- {
- cout<<"Wpisz:\n1 - Stwórz obiekt\n2 - Wyświetl obiekt\n9 - Zakończ działanie programu";
- cin>>wybor;
- system( "cls" )
- switch (wybor)
- {
- case 1:
- cout<<"Stwórz:\n1 - Punkt\n2 - Linię\n3 - Trójkąt\n4 - Czworokąt\n5 - Prostokąt\n6 - Kwadrat";
- cin>>wybor;
- switch (wybor)
- {
- case 1:
- cout<<"Wpisz współrzędne punktu:\nx = ";
- if//chyba to zamienia try/catch ale pewna nie jestem
- {
- x1 = int.Parse(Console.ReadLine());// nie wiem
- cout<<"y = ";
- y1 = int.Parse(Console.ReadLine());//nie wiem
- }
- else(FormatException)
- {
- Console.Clear();
- break;
- }
- punkt = new Punkt(x1, y1);
- system( "cls" )
- break;
- case 2:
- cout<<"Wpisz współrzędne punktów:\nx1 = ";
- if
- {
- x1 = int.Parse(Console.ReadLine());//znowu konwersje ogarnij to
- Console.Write("y1 = ");
- y1 = int.Parse(Console.ReadLine());//tu tez
- Console.Write("x2 = ");
- x2 = int.Parse(Console.ReadLine());// tu tesh
- Console.Write("y2 = ");
- y2 = int.Parse(Console.ReadLine());// tu tesh
- }
- else(FormatException)
- {
- system( "cls" )
- break;
- }
- linia = new Linia(new Punkt(x1, y1), new Punkt(x2, y2));
- system( "cls" )
- break;
- case 3:
- cout<<"Wpisz współrzędne punktów:\nx1 = ";
- if
- {
- x1 = int.Parse(Console.ReadLine());//tu tez
- Console.Write("y1 = ");
- y1 = int.Parse(Console.ReadLine());//i tu i pod spodem
- Console.Write("x2 = ");
- x2 = int.Parse(Console.ReadLine());
- Console.Write("y2 = ");
- y2 = int.Parse(Console.ReadLine());
- Console.Write("x3 = ");
- x3 = int.Parse(Console.ReadLine());
- Console.Write("y3 = ");
- y3 = int.Parse(Console.ReadLine());
- Console.Write("Kolor: ");
- cin>>kolor;
- }
- else (FormatException)
- {
- Console.Clear();
- break;
- }
- trojkat = new Trojkat(new Punkt(x1, y1), new Punkt(x2, y2), new Punkt(x3, y3), kolor);
- system( "cls" )
- break;
- case 4:
- cout<<"Wpisz współrzędne punktów:\nx1 = ";
- if
- {
- x1 = int.Parse(Console.ReadLine());// i tu i pod spodem
- Console.Write("y1 = ");
- y1 = int.Parse(Console.ReadLine());
- Console.Write("x2 = ");
- x2 = int.Parse(Console.ReadLine());
- Console.Write("y2 = ");
- y2 = int.Parse(Console.ReadLine());
- Console.Write("x3 = ");
- x3 = int.Parse(Console.ReadLine());
- Console.Write("y3 = ");
- y3 = int.Parse(Console.ReadLine());
- Console.Write("x4 = ");
- x4 = int.Parse(Console.ReadLine());
- Console.Write("y4 = ");
- y4 = int.Parse(Console.ReadLine());
- Console.Write("Kolor: ");
- cin>>kolor;
- }
- else (FormatException)// nie wiem czy te (formatexception wgl potrzebne sprobuj tez wyjebac to
- {
- system( "cls" )
- break;
- }
- czworokat = new Czworokat(new Punkt(x1, y1), new Punkt(x2, y2), new Punkt(x3, y3), new Punkt(x4, y4), kolor);
- system( "cls" )
- break;
- case 5:
- cout<<"Wpisz współrzędne punktów:Lewy, górny x = ";
- if
- {
- x1 = int.Parse(Console.ReadLine());// i tu i pod spodem
- Console.Write("Lewy, górny y = ");
- y1 = int.Parse(Console.ReadLine());
- Console.Write("Prawy, dolny x = ");
- x2 = int.Parse(Console.ReadLine());
- Console.Write("Prawy, dolny y = ");
- y2 = int.Parse(Console.ReadLine());
- Console.Write("Kolor: ");
- cin>>kolor;
- }
- else(FormatException)
- {
- system( "cls" )
- break;
- }
- prostokat = new Prostokat(new Punkt(x1, y1), new Punkt(x2, y2), kolor);
- system( "cls" )
- break;
- case 6:
- cout<<"Wpisz współrzędne lewego, górnego punktu:\nx = ";
- if
- {
- x1 = int.Parse(Console.ReadLine());// i tu xdd
- Console.Write("y = ");
- y1 = int.Parse(Console.ReadLine());
- Console.Write("Długość boku = ");
- x2 = int.Parse(Console.ReadLine());
- Console.Write("Kolor: ");
- cin>>kolor;
- }
- else (FormatException)
- {
- system( "cls" )
- break;
- }
- kwadrat = new Kwadrat(new Punkt(x1, y1), x2, kolor);
- system( "cls" )
- break;
- default:
- break;
- }
- break;
- case 2:
- cout<<"Wyświetl:\n1 - Punkt\n2 - Linię\n3 - Trójkąt\n4 - Czworokąt\n5 - Prostokąt\n6 - Kwadrat";
- cin>>wybor;
- switch (wybor)
- {
- case 1:
- if (punkt == null) break;
- Console.Write(punkt.ToString());// nie ogarniam juz xd
- Console.ReadKey(true);
- break;
- case 2:
- if (linia == null) break;
- Console.Write(linia.ToString());
- Console.ReadKey(true);
- break;
- case 3:
- if (trojkat == null) break;
- Console.Write(trojkat.ToString());
- Console.ReadKey(true);
- break;
- case 4:
- if (czworokat == null) break;
- Console.Write(czworokat.ToString());
- Console.ReadKey(true);
- break;
- case 5:
- if (prostokat == null) break;
- Console.Write(prostokat.ToString());
- Console.ReadKey(true);
- break;
- case 6:
- if (kwadrat == null) break;
- Console.Write(kwadrat.ToString());
- Console.ReadKey(true);
- break;
- default:
- break;
- }
- system( "cls" )
- break;
- default:
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement