Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.59 KB | None | 0 0
  1. #include<iostram>
  2. #include<string>
  3. using namespace std;
  4.  
  5.  
  6. namespace cs_figury_7
  7. {
  8. class Figura
  9. {
  10. protected string kolor;
  11. public Figura() { }
  12. public Figura(string _kolor)
  13. {
  14. kolor = _kolor;
  15. }
  16. public string getKolor()
  17. {
  18. return kolor;
  19. }
  20. public void setKolor(string _kolor)
  21. {
  22. kolor = _kolor;
  23. }
  24. }
  25.  
  26. class Punkt
  27. {
  28. private int x, y;
  29.  
  30. public Punkt() { }
  31. public Punkt(int _x, int _y)
  32. {
  33. x = _x;
  34. y = _y;
  35. }
  36. public Punkt(Punkt P)
  37. {
  38. x = P.x;
  39. y = P.y;
  40. }
  41. public int getX()
  42. {
  43. return x;
  44. }
  45. public int getY()
  46. {
  47. return y;
  48. }
  49. public override string ToString()
  50. {
  51. ostringstream napis;
  52. napis << "\n(" << x << ";" << y << ") ";
  53. return napis.str();
  54.  
  55. }
  56. }
  57.  
  58. class Linia
  59. {
  60. private Punkt p1, p2;
  61. public Linia() { }
  62. public Linia(Punkt _p1, Punkt _p2)
  63. {
  64. p1 = new Punkt(_p1);
  65. p2 = new Punkt(_p2);
  66. }
  67. public Linia(Linia L)
  68. {
  69. p1 = L.p1;
  70. p2 = L.p2;
  71. }
  72. public Punkt getp1()
  73. {
  74. return p1;
  75. }
  76. public Punkt getp2()
  77. {
  78. return p2;
  79. }
  80. public override string ToString()
  81. {
  82. ostringstream naapis;
  83. napis << "\n(" << p1.getX() << ";" << p1.getY() << ")\n( "<<p2.getX()<<";"<<p2.getY()<<")";
  84. return naapis.str();
  85.  
  86. }
  87. }
  88.  
  89. class Trojkat : Figura
  90. {
  91. private Linia l1, l2, l3;
  92.  
  93. public Trojkat() : base() { }
  94.  
  95. public Trojkat(Punkt _p1, Punkt _p2, Punkt _p3, string _kolor) : base(_kolor)
  96. {
  97. l1 = new Linia(_p1, _p2);
  98. l2 = new Linia(_p2, _p3);
  99. l3 = new Linia(_p3, _p1);
  100. }
  101. public override string ToString()
  102. {
  103. ostringstream naaapis;
  104. napis << "\n(" << l1.getp1().getX() << ";" << l1.getp1().getY() << ")\n( "<<l1.getp2().getX()<<";"<<l1.getp2().getY()<<")\n("<<l2.getp2().getX()<<";"<<l2.getp2().getY()+")\n"<<getKolor();
  105. return naaapis.str();
  106.  
  107. }
  108. }
  109.  
  110. class Czworokat : Figura
  111. {
  112. protected Linia l1, l2, l3, l4;
  113. public Czworokat() : base() { }
  114. public Czworokat(Punkt _p1, Punkt _p2, Punkt _p3, Punkt _p4, string _kolor) : base(_kolor)
  115. {
  116. l1 = new Linia(_p1, _p2);
  117. l2 = new Linia(_p2, _p3);
  118. l3 = new Linia(_p3, _p4);
  119. l4 = new Linia(_p4, _p1);
  120. }
  121. public override string ToString()// nie wiem co z tym
  122. { ostringstream naaaapis;
  123. 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();
  124. return naaaapis.str();
  125.  
  126. }
  127. }
  128.  
  129. class Prostokat : Czworokat
  130. {
  131. public Prostokat() : base() { }
  132. 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) { }
  133. }
  134.  
  135. class Kwadrat : Prostokat
  136. {
  137. public Kwadrat() : base() { }
  138. public Kwadrat(Punkt p, int dlugosc, string _kolor) : base(p, new Punkt(p.getX() - dlugosc, p.getY() - dlugosc), _kolor) { }
  139. }
  140.  
  141. class Program
  142. {
  143. static void Main(string[] args)
  144. {
  145. Punkt punkt = null;
  146. Linia linia = null;
  147. Trojkat trojkat = null;
  148. Czworokat czworokat = null;
  149. Prostokat prostokat = null;
  150. Kwadrat kwadrat = null;
  151.  
  152. int x1, x2, x3, x4, y1, y2, y3, y4, wybor = 0;
  153.  
  154. string kolor;
  155.  
  156. //Menu
  157. while (wybor != 9)
  158. {
  159. cout<<"Wpisz:\n1 - Stwórz obiekt\n2 - Wyświetl obiekt\n9 - Zakończ działanie programu";
  160. cin>>wybor;
  161. system( "cls" )
  162.  
  163. switch (wybor)
  164. {
  165. case 1:
  166. cout<<"Stwórz:\n1 - Punkt\n2 - Linię\n3 - Trójkąt\n4 - Czworokąt\n5 - Prostokąt\n6 - Kwadrat";
  167. cin>>wybor;
  168. switch (wybor)
  169. {
  170. case 1:
  171. cout<<"Wpisz współrzędne punktu:\nx = ";
  172. if//chyba to zamienia try/catch ale pewna nie jestem
  173. {
  174. x1 = int.Parse(Console.ReadLine());// nie wiem
  175. cout<<"y = ";
  176. y1 = int.Parse(Console.ReadLine());//nie wiem
  177. }
  178. else(FormatException)
  179. {
  180. Console.Clear();
  181. break;
  182. }
  183. punkt = new Punkt(x1, y1);
  184. system( "cls" )
  185. break;
  186. case 2:
  187. cout<<"Wpisz współrzędne punktów:\nx1 = ";
  188. if
  189. {
  190. x1 = int.Parse(Console.ReadLine());//znowu konwersje ogarnij to
  191. Console.Write("y1 = ");
  192. y1 = int.Parse(Console.ReadLine());//tu tez
  193. Console.Write("x2 = ");
  194. x2 = int.Parse(Console.ReadLine());// tu tesh
  195. Console.Write("y2 = ");
  196. y2 = int.Parse(Console.ReadLine());// tu tesh
  197. }
  198. else(FormatException)
  199. {
  200. system( "cls" )
  201. break;
  202. }
  203. linia = new Linia(new Punkt(x1, y1), new Punkt(x2, y2));
  204. system( "cls" )
  205. break;
  206. case 3:
  207. cout<<"Wpisz współrzędne punktów:\nx1 = ";
  208. if
  209. {
  210. x1 = int.Parse(Console.ReadLine());//tu tez
  211. Console.Write("y1 = ");
  212. y1 = int.Parse(Console.ReadLine());//i tu i pod spodem
  213. Console.Write("x2 = ");
  214. x2 = int.Parse(Console.ReadLine());
  215. Console.Write("y2 = ");
  216. y2 = int.Parse(Console.ReadLine());
  217. Console.Write("x3 = ");
  218. x3 = int.Parse(Console.ReadLine());
  219. Console.Write("y3 = ");
  220. y3 = int.Parse(Console.ReadLine());
  221. Console.Write("Kolor: ");
  222. cin>>kolor;
  223. }
  224. else (FormatException)
  225. {
  226. Console.Clear();
  227. break;
  228. }
  229. trojkat = new Trojkat(new Punkt(x1, y1), new Punkt(x2, y2), new Punkt(x3, y3), kolor);
  230. system( "cls" )
  231. break;
  232. case 4:
  233. cout<<"Wpisz współrzędne punktów:\nx1 = ";
  234. if
  235. {
  236. x1 = int.Parse(Console.ReadLine());// i tu i pod spodem
  237. Console.Write("y1 = ");
  238. y1 = int.Parse(Console.ReadLine());
  239. Console.Write("x2 = ");
  240. x2 = int.Parse(Console.ReadLine());
  241. Console.Write("y2 = ");
  242. y2 = int.Parse(Console.ReadLine());
  243. Console.Write("x3 = ");
  244. x3 = int.Parse(Console.ReadLine());
  245. Console.Write("y3 = ");
  246. y3 = int.Parse(Console.ReadLine());
  247. Console.Write("x4 = ");
  248. x4 = int.Parse(Console.ReadLine());
  249. Console.Write("y4 = ");
  250. y4 = int.Parse(Console.ReadLine());
  251. Console.Write("Kolor: ");
  252. cin>>kolor;
  253. }
  254. else (FormatException)// nie wiem czy te (formatexception wgl potrzebne sprobuj tez wyjebac to
  255. {
  256. system( "cls" )
  257. break;
  258. }
  259. czworokat = new Czworokat(new Punkt(x1, y1), new Punkt(x2, y2), new Punkt(x3, y3), new Punkt(x4, y4), kolor);
  260. system( "cls" )
  261. break;
  262. case 5:
  263. cout<<"Wpisz współrzędne punktów:Lewy, górny x = ";
  264. if
  265. {
  266. x1 = int.Parse(Console.ReadLine());// i tu i pod spodem
  267. Console.Write("Lewy, górny y = ");
  268. y1 = int.Parse(Console.ReadLine());
  269. Console.Write("Prawy, dolny x = ");
  270. x2 = int.Parse(Console.ReadLine());
  271. Console.Write("Prawy, dolny y = ");
  272. y2 = int.Parse(Console.ReadLine());
  273. Console.Write("Kolor: ");
  274. cin>>kolor;
  275. }
  276. else(FormatException)
  277. {
  278. system( "cls" )
  279. break;
  280. }
  281. prostokat = new Prostokat(new Punkt(x1, y1), new Punkt(x2, y2), kolor);
  282. system( "cls" )
  283. break;
  284. case 6:
  285. cout<<"Wpisz współrzędne lewego, górnego punktu:\nx = ";
  286. if
  287. {
  288. x1 = int.Parse(Console.ReadLine());// i tu xdd
  289. Console.Write("y = ");
  290. y1 = int.Parse(Console.ReadLine());
  291. Console.Write("Długość boku = ");
  292. x2 = int.Parse(Console.ReadLine());
  293. Console.Write("Kolor: ");
  294. cin>>kolor;
  295. }
  296. else (FormatException)
  297. {
  298. system( "cls" )
  299. break;
  300. }
  301. kwadrat = new Kwadrat(new Punkt(x1, y1), x2, kolor);
  302. system( "cls" )
  303. break;
  304. default:
  305. break;
  306. }
  307. break;
  308. case 2:
  309. cout<<"Wyświetl:\n1 - Punkt\n2 - Linię\n3 - Trójkąt\n4 - Czworokąt\n5 - Prostokąt\n6 - Kwadrat";
  310. cin>>wybor;
  311. switch (wybor)
  312. {
  313. case 1:
  314. if (punkt == null) break;
  315. Console.Write(punkt.ToString());// nie ogarniam juz xd
  316. Console.ReadKey(true);
  317. break;
  318. case 2:
  319. if (linia == null) break;
  320. Console.Write(linia.ToString());
  321. Console.ReadKey(true);
  322. break;
  323. case 3:
  324. if (trojkat == null) break;
  325. Console.Write(trojkat.ToString());
  326. Console.ReadKey(true);
  327. break;
  328. case 4:
  329. if (czworokat == null) break;
  330. Console.Write(czworokat.ToString());
  331. Console.ReadKey(true);
  332. break;
  333. case 5:
  334. if (prostokat == null) break;
  335. Console.Write(prostokat.ToString());
  336. Console.ReadKey(true);
  337. break;
  338. case 6:
  339. if (kwadrat == null) break;
  340. Console.Write(kwadrat.ToString());
  341. Console.ReadKey(true);
  342. break;
  343. default:
  344. break;
  345. }
  346. system( "cls" )
  347. break;
  348. default:
  349. break;
  350. }
  351. }
  352. }
  353. }
  354. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement