Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- class Rechteck // 1. Klasse
- {
- public:
- Rechteck (float xxol, float yyol,
- float xxur, float yyul); // Konstruktor
- void print_rechteck();
- float flaeche();
- float umfang();
- friend void punktlage(class Rechteck rr,
- class Punkt pp);
- private:
- float xol, yol, xur, yur;
- };
- class Punkt // 2. Klasse
- {
- public:
- void read_punkt();
- void print_punkt();
- friend void punktlage(Rechteck rr, Punkt pp);
- private:
- float x, y;
- };
- Rechteck::Rechteck(float xxol, float yyol,
- float xxur, float yyur)
- {
- xol = xxol;
- yol = yyol;
- xur = xxur;
- yur = yyur;
- }
- void Rechteck::print_rechteck()
- {
- cout << "x oben links: " << xol << endl
- << "y oben links: " << yol << endl
- << "x unten rechts: " << xur << endl
- << "y unten rechts: " << yur << endl;
- }
- float Rechteck::flaeche()
- { return (xur - xol) * (yol - yur); }
- float Rechteck::umfang()
- { return 2 * ((xur - xol) + (yol - yur)); }
- void Punkt::read_punkt()
- {
- cout << "x-Koordinate des Punkts > ";
- cin >> x;
- cout << "y-Koordinate des Punkts > ";
- cin >> y;
- }
- void Punkt::print_punkt()
- {
- cout << "x-Koordinate: " << x << endl;
- cout << "y-Koordinate: " << y << endl;
- }
- //------------globale friend-Funktion---------------------
- void punktlage(Rechteck rr, Punkt pp)
- {
- if (pp.x > rr.xol && pp.x < rr.xur &&
- pp.y < rr.yol && pp.y > rr.yur)
- cout << "Der Punkt liegt innerhalb des Rechtecks" << endl;
- else
- cout << "Der Punkt liegt ausserhalb des Rechtecks" << endl;
- }
- int main( )
- {
- class Rechteck r(5.5, 10.3, 12.6, 2.4);
- class Punkt p;
- float fl, um;
- cout << "Eingabe der Punkt-Daten" << endl;
- p.read_punkt();
- cout << "Ausgaben:" << endl;
- p.print_punkt();
- cout << "Rechteck-Daten" << endl;
- r.print_rechteck();
- fl = r.flaeche();
- um = r.umfang();
- cout << "Flaeche des Rechtecks = " << fl << endl
- << "Umfang des Rechtecks = " << um << endl;
- punktlage(r, p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement