Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. class Rechteck // 1. Klasse
  7. {
  8. public:
  9. Rechteck (float xxol, float yyol,
  10. float xxur, float yyul); // Konstruktor
  11. void print_rechteck();
  12. float flaeche();
  13. float umfang();
  14. friend void punktlage(class Rechteck rr,
  15. class Punkt pp);
  16. private:
  17. float xol, yol, xur, yur;
  18. };
  19.  
  20. class Punkt // 2. Klasse
  21. {
  22. public:
  23. void read_punkt();
  24. void print_punkt();
  25. friend void punktlage(Rechteck rr, Punkt pp);
  26. private:
  27. float x, y;
  28. };
  29.  
  30.  
  31. Rechteck::Rechteck(float xxol, float yyol,
  32. float xxur, float yyur)
  33. {
  34. xol = xxol;
  35. yol = yyol;
  36. xur = xxur;
  37. yur = yyur;
  38. }
  39.  
  40. void Rechteck::print_rechteck()
  41. {
  42. cout << "x oben links: " << xol << endl
  43. << "y oben links: " << yol << endl
  44. << "x unten rechts: " << xur << endl
  45. << "y unten rechts: " << yur << endl;
  46. }
  47.  
  48. float Rechteck::flaeche()
  49. { return (xur - xol) * (yol - yur); }
  50.  
  51. float Rechteck::umfang()
  52. { return 2 * ((xur - xol) + (yol - yur)); }
  53.  
  54. void Punkt::read_punkt()
  55. {
  56. cout << "x-Koordinate des Punkts > ";
  57. cin >> x;
  58. cout << "y-Koordinate des Punkts > ";
  59. cin >> y;
  60. }
  61.  
  62. void Punkt::print_punkt()
  63. {
  64. cout << "x-Koordinate: " << x << endl;
  65. cout << "y-Koordinate: " << y << endl;
  66. }
  67.  
  68. //------------globale friend-Funktion---------------------
  69. void punktlage(Rechteck rr, Punkt pp)
  70. {
  71. if (pp.x > rr.xol && pp.x < rr.xur &&
  72. pp.y < rr.yol && pp.y > rr.yur)
  73. cout << "Der Punkt liegt innerhalb des Rechtecks" << endl;
  74. else
  75. cout << "Der Punkt liegt ausserhalb des Rechtecks" << endl;
  76. }
  77.  
  78. int main( )
  79. {
  80. class Rechteck r(5.5, 10.3, 12.6, 2.4);
  81. class Punkt p;
  82. float fl, um;
  83.  
  84. cout << "Eingabe der Punkt-Daten" << endl;
  85. p.read_punkt();
  86. cout << "Ausgaben:" << endl;
  87. p.print_punkt();
  88. cout << "Rechteck-Daten" << endl;
  89. r.print_rechteck();
  90. fl = r.flaeche();
  91. um = r.umfang();
  92. cout << "Flaeche des Rechtecks = " << fl << endl
  93. << "Umfang des Rechtecks = " << um << endl;
  94. punktlage(r, p);
  95.  
  96.  
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement