Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » Rätselecke » 39. Virtualrätsel

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 < [ 2 ]
000
25.08.2003, 21:26 Uhr
virtual
Sexiest Bit alive
(Operator)


Gegeben ist folgende Klasse:

C++:
class Rect:
{
     int x;
     int y;
     unsigned width;
     unsigned height;
};


Soll ein Rechteck implementieren.

Implementiere folgende Methoden:

C++:
Rect::operator bool () const; // Gebe true, zurück, wenn Rechteck nicht leer ist!
Rect Rect::operator & (const Rect& other) const; // Bild das kleinste gemeinsame Rechteck von this und other (intersection)
Rect Rect::operator | (const Rect& other) const; // Bild das größte umgebende Rechteck um this und other (union)
bool Rect::isIn(const Rect& other) const; // Rückgabe ist true, wenn dieses Rechteck komplett im anderen Rechteck liegt


--
Gruß, virtual
Quote of the Month
Ich eß' nur was ein Gesicht hat (Creme 21)
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
26.08.2003, 09:18 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


schaut das ding so aus?


C++:
Rect::operator bool () const
{
  return ((width > 0) && (height > 0));
}


negative Höhen/Breiten wären ja schwachsinnig
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
002
26.08.2003, 09:28 Uhr
virtual
Sexiest Bit alive
(Operator)


@FloSoft
Ja. So schaut das aus.
Negative Höhen sind aufgrund der intelligent (puh, da stinkt das Eigenlob ) gewählten Typen Für width und height eigentlich unmöglich
--
Gruß, virtual
Quote of the Month
Ich eß' nur was ein Gesicht hat (Creme 21)
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
003
26.08.2003, 09:52 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


naja sicher ist sicher, bei windows Compilern kann man nie wissen ob die sich bei unsigned auch an unsigned halten
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
004
26.08.2003, 09:57 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


Das Rätsel ist endlich mal was einfaches, was ich auch schaff


C++:
bool Rect::isIn(const Rect& other) const
{
  return ( (this->x > other->x) && (this->y > other->y) && (this->x+this->width < other->x+other->width) && (this->y+this->height < other->y+other->height) );
}


Ich hoffe ich hab etz keinen Müll gebaut (z.b Tipfeler )
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
005
26.08.2003, 10:06 Uhr
virtual
Sexiest Bit alive
(Operator)


Das isIn ist leider nur fast richtig, bzw. ist vielleicht eine Anschauungssache: Ich denke, daß ein Rechteck sich stets selbst enthält. Dh wird der Methode isIn das Rechteck *this übergeben, würde ich erwarten, daß true zurückkomt. Wenn du das genauso siehst, dann solltest Du noch 4 = Zeichen spendieren.
--
Gruß, virtual
Quote of the Month
Ich eß' nur was ein Gesicht hat (Creme 21)
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
006
26.08.2003, 12:00 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


ups oh voll übersehen, hast natürlich Recht...


C++:
bool Rect::isIn(const Rect& other) const
{
  return ( (this->x >= other->x) &&
            (this->y >= other->y) &&
            (this->x+this->width <= other->x+other->width) &&
            (this->y+this->height <= other->y+other->height) );
}


--
class God : public ChuckNorris { };

Dieser Post wurde am 26.08.2003 um 12:01 Uhr von FloSoft editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
007
26.08.2003, 12:17 Uhr
virtual
Sexiest Bit alive
(Operator)


Man könnte auch schreiben:

C++:
bool Rect::operator == (const Rect& other) const
{
   return x==other.x && y==other.y && width==other.width && height==other.height;
}


Um dann zu schreiben:

C++:
bool Rect::isIn(const Rect& other) const
{
     return *this == (*this & other);
}


(vorausgesetzt, man hat den Operator von obiger Aufgabe implementiert
--
Gruß, virtual
Quote of the Month
Ich eß' nur was ein Gesicht hat (Creme 21)
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
008
26.08.2003, 12:21 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


jo natürlich kann man die ( und this-> weglassen, habs nur hingemacht wegen besserer übersicht
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
009
26.08.2003, 14:59 Uhr
kronos
Quotenfisch
(Operator)


wie wär's mal wieder mit 'ne C-rätsel?
--
main($)??<-$<='?'>>2?main($-!!putchar(
(("$;99M?GD??(??/x0d??/a:???;a"+'?'/4)
??($??)+'?'/3-2-1+$%2)??''?')):'?';??>
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 < [ 2 ]     [ Rätselecke ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: