Konstruktor



  • Hallo kann mir jemand erklären was genau der Fehler bei meiner Implementierung im Konstruktor ist ?

    #ifndef ASCIISCREENSOLUTION_MYCODE_CRECTANGLE_H_
    
    #include <ostream>
    using namespace std;
    
    #include "CPoint.h"
    #include "CScreen.h"
    
    /**
     * Diese Klasse beschreibt ein Rechteck in einem
     * Ganzzahl-Koordinatensystem �ber die Eigenschaften
     * "untere linke Ecke" und "obere rechte Ecke".
     *
     * Als zus�tzliche Eigenschaft hat die Klasse ein Zeichen
     * (char) das bei der graphischen Darstellung als
     * F�llzeichen verwendet wird.
     */
    class CRectangle
    {
    private:
    	/** Die linke untere Ecke. */
    	CPoint m_bottomLeft;
    	/** Die rechte obere Ecke. */
    	CPoint m_topRight;
    	/** Das F�llzeichen f�r die graphische Darstellung. */
    	char m_fillChar;
    
    public:
    	/**
    	 * Erzeugt ein neues Rechteck mit linker unterer und
    	 * rechter oberer Ecke bei (0,0) und dem angegebenen
    	 * F�llzeichen.
    	 */
    	CRectangle(char fillChar = '#');
    
    	/**
    	 * Erzeugt ein neues Rechteck mit der angegebenen linken
    	 * unteren und rechten oberen Ecken sowie dem angegebenen
    	 * F�llzeichen.
    	 *
    	 * Beim Erzeugen wird die Zusicherung �berpr�ft, dass die
    	 * rechte obere Ecke rechts von und oberhalt der linken
    	 * unteren Ecke liegen muss! Falls die x-Koordinate
    	 * der rechten oberen Ecke nicht gr��er als die x-Koordinate
    	 * der linken unteren Ecke ist, wird sie auf den Wert
    	 * der x-Koordinate der linken unteren Ecke gesetzt. Falls
    	 * die y-Koordinate der rechten oberen Ecke nicht gr��er als
    	 * die y-Koordinate der linken unteren Ecke ist, wird sie auf
    	 * dem Wert der y-Koordinate der linken unteren Ecke gesetzt.
    	 */
    	CRectangle(CPoint bottomLeft, CPoint topRight, char fillChar = '#');
    
    	/**
    	 * Weist den Eigenschaften "linke untere Ecke" und "rechte obere
    	 * Ecke" neue Werte zu.
    	 *
    	 * Vor der Zuweisung wird die Zusicherung �berpr�ft, dass die
    	 * rechte obere Ecke rechts von und oberhalt der linken
    	 * unteren Ecke liegen muss! Ist das nicht der Fall wird keines
    	 * der Attribute ver�ndert.
    	 */
    	void setCorners (CPoint bottomLeft, CPoint topRight);
    
    	/**
    	 * Liefert die linke untere Ecke des Rechtecks zur�ck.
    	 */
    	CPoint getBottomLeftCorner() const;
    
    	/**
    	 * Liefert die rechte obere Ecke des Rechtecks zur�ck.
    	 */
    	CPoint getTopRightCorner() const;
    
    	/**
    	 * Weist dem F�llzeichen den angegebene Wert zu.
    	 */
    	void setFillChar(char fillChar = '#');
    
    	/**
    	 * Liefert den Wert des F�llzeichens.
    	 */
    	char getFillChar() const;
    
    	/**
    	 * Pr�ft, ob die beiden Rechtecke in allen Eigenschaften �bereinstimmen.
    	 */
    	bool operator== (const CRectangle& other) const;
    
    	/**
    	 * Zeichnet das Rechteck in das �bergebene Bildschirmobjekt. Das heisst,
    	 * es werden mit CScreen::setPoint die Werte aller "Punkte", die im 
    	 * Bereich des Rechtecks liegen, auf das F�llzeichen des Rechtecks gesetzt.
    	 */
    	void draw(CScreen& screen) const;
    
    	/**
    	 * Gibt eine textuelle Darstellung des Rechtecks auf dem �bergebenen
    	 * Ausgabestrom aus. Das Format ist in der Aufgabenstellung beschrieben.
    	 */
    	friend ostream& operator<< (ostream& lhs, const CRectangle& rhs);
    };
    
    #endif /* ASCIISCREENSOLUTION_MYCODE_CRECTANGLE_H_ */
    
    #include "CRectangle.h"
    
    CRectangle::CRectangle(char fillChar)
    
    {
      m_fillChar = fillChar;
      /**
         * Erzeugt ein neues Rechteck mit der angegebenen linken
         * unteren und rechten oberen Ecken sowie dem angegebenen
         * F�llzeichen.
         *
         * Beim Erzeugen wird die Zusicherung �berpr�ft, dass die
         * rechte obere Ecke rechts von und oberhalt der linken
         * unteren Ecke liegen muss! Falls die x-Koordinate
         * der rechten oberen Ecke nicht gr��er als die x-Koordinate
         * der linken unteren Ecke ist, wird sie auf den Wert
         * der x-Koordinate der linken unteren Ecke gesetzt. Falls
         * die y-Koordinate der rechten oberen Ecke nicht gr��er als
         * die y-Koordinate der linken unteren Ecke ist, wird sie auf
         * dem Wert der y-Koordinate der linken unteren Ecke gesetzt.
         */
    
    }
    
    CRectangle::CRectangle(CPoint bottomLeft, CPoint topRight, char fillChar)
    {
    	if( topRight.x <=bottomLeft.x && topRight.y<= bottomLeft.y){
    
    			m_bottomLeft = bottomLeft;
    			m_topRight = topRight;
    		}
    }
    
    void CRectangle::setCorners(CPoint bottomLeft, CPoint topRight)
    {
    	// Bitte implementieren
    }
    
    CPoint CRectangle::getBottomLeftCorner() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return CPoint();
    }
    
    CPoint CRectangle::getTopRightCorner() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return CPoint();
    }
    
    void CRectangle::setFillChar(char fillChar)
    {
    	// Bitte implementieren
    }
    
    char CRectangle::getFillChar() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return 0;
    }
    
    bool CRectangle::operator ==(const CRectangle& other) const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return false;
    }
    
    void CRectangle::draw(CScreen& screen) const
    {
    	// Bitte implementieren
    }
    
    * CPoint.h
     *
     *  Created on: 05.01.2015
     *      Author: mnl
     */
    
    #ifndef ASCIISCREENSOLUTION_MYCODE_CPOINT_H_
    #define ASCIISCREENSOLUTION_MYCODE_CPOINT_H_
    
    /**
     * Diese Klasse repr�sentiert einen Punkt ein einem Ganzzahl-Koordinatensystem.
     */
    class CPoint
    {
    private:
    	/** Die x-Koordinate (Spalte) */
    	int m_x;
    	/** Die y-Koordinate (Zeile) */
    	int m_y;
    
    public:
    	/**
    	 * Erzeugt ein neues Objekt mit den angegeben
    	 * Werten f�r die x- und y-Koordinate.
    	 */
    	CPoint(int x = 0, int y = 0);
    
    	/**
    	 * Setzt die x-Koordinate auf den angegebenen Wert.
    	 */
    	void setX(int x);
    
    	/**
    	 * Setzt die y-Koordinate auf den angegebenen Wert.
    	 */
    	void setY(int y);
    
    	/**
    	 * Liefert den Wert der x-Koordinate.
    	 */
    	int getX() const;
    
    	/**
    	 * Liefert den Wert der y-Koordinate.
    	 */
    	int getY() const;
    
    	/**
    	 * Pr�ft, ob die x- und y-Koordinaten der Punkte �bereinstimmen.
    	 */
    	bool operator== (const CPoint& other) const;
    
    	/**
    	 * Pr�ft, ob sich die x- und y-Koordinaten der Punkte unterscheiden.
    	 */
    	bool operator!= (const CPoint& other) const;
    };
    
    #endif /* ASCIISCREENSOLUTION_MYCODE_CPOINT_H_ */
    
    #include "CPoint.h"
    
    CPoint::CPoint(int x, int y)
    {
    	m_x = x;
    	m_y = y;
    }
    
    void CPoint::setX(int x)
    {
    	m_x = x;
    }
    
    void CPoint::setY(int y)
    {
    	m_y = y;
    }
    
    int CPoint::getX() const
    {
    	return m_x;
    }
    
    int CPoint::getY() const
    {
    	return m_y;
    }
    
    bool CPoint::operator ==(const CPoint& other) const
    {
    	return m_x == other.m_x && m_y == other.m_y;
    }
    
    bool CPoint::operator !=(const CPoint& other) const
    {
    	return m_x != other.m_x || m_y != other.m_y;
    }
    
    /*
     * CScreen.h
     *
     *  Created on: 05.01.2015
     *      Author: mnl
     */
    
    #ifndef ASCIISCREENSOLUTION_MYCODE_CSCREEN_H_
    #define ASCIISCREENSOLUTION_MYCODE_CSCREEN_H_
    
    #include "CPoint.h"
    
    /**
     * Dies Klasse repr�sentiert einen Bereich von 80x24 "Punkten",
     * die als ein beliebiges Zeichen dargestellt werden k�nnen.
     */
    class CScreen
    {
    private:
    	/** Der Speicher f�r die Darstellung der Punkte. */
    	char m_content[24*80];
    
    public:
    	/**
    	 * Erzeugt eine neue Darstellung, bei der alle Punkte
    	 * auf den Wert '.' gesetzt sind.
    	 */
    	CScreen();
    
    	/**
    	 * Setzt den angegebenen Punkt auf das angegebene Zeichen.
    	 */
    	void setPoint(CPoint point, char content);
    
    	/**
    	 * Gibt die Darstellung aus.
    	 */
    	void print() const;
    
    	/**
    	 * L�scht die Darstellung. Alle Zeichen werden wieder auf
    	 * '.' gesetzt.
    	 */
    	void clear();
    };
    
    #endif /* ASCIISCREENSOLUTION_MYCODE_CSCREEN_H_ */
    
    /*
     * CScreen.cpp
     *
     *  Created on: 05.01.2015
     *      Author: mnl
     */
    
    #include <iostream>
    using namespace std;
    
    #include "CScreen.h"
    
    CScreen::CScreen()
    {
    	clear();
    }
    
    void CScreen::setPoint(CPoint point, char content)
    {
    	if (point.getX() < 0 || point.getY() < 0
    			|| point.getY() * 80 + point.getX() >= 24*80) {
    		return;
    	}
    	m_content[point.getY() * 80 + point.getX()] = content;
    }
    
    void CScreen::print() const
    {
    	cout << "    ";
    	for (int col = 0; col < 80; col++) {
    		cout << col / 10;
    	}
    	cout << endl;
    	cout << "    ";
    	for (int col = 0; col < 80; col++) {
    		cout << col % 10;
    	}
    	cout << endl;
    	for (int row = 23; row >= 0; row--) {
    		if (row < 10) {
    			cout << ' ';
    		}
    		cout << row << ": ";
    		for (int col = 0; col < 80; col++) {
    			cout << m_content[row * 80 + col];
    		}
    		cout << endl;
    	}
    	cout << endl;
    }
    
    void CScreen::clear() {
    	for (int i = 0; i < 24*80; i++) {
    		m_content[i] = '.';
    	}
    }
    

    Fehler :

    Description Resource Path Location Type
    make: *** [CRectangle.o] Fehler 1 CRectangle C/C++ Problem
    Field 'y' could not be resolved CRectangle.cpp /CRectangle line 34 Semantic Error
    declared private here CPoint.h /CRectangle line 18 C/C++ Problem
    in expansion of macro ‘x’ CRectangle.cpp /CRectangle line 33 C/C++ Problem
    ‘int CPoint::m_y’ is private within this context CRectangle.cpp /CRectangle line 10 C/C++ Problem
    declared private here CPoint.h /CRectangle line 20 C/C++ Problem
    in expansion of macro ‘y’ CRectangle.cpp /CRectangle line 38 C/C++ Problem
    Field 'x' could not be resolved CRectangle.cpp /CRectangle line 34 Semantic Error
    Member 'm_fillChar' was not initialized in this constructor CRectangle.cpp /CRectangle line 32 Code Analysis Problem
    Field 'y' could not be resolved CRectangle.cpp /CRectangle line 34 Semantic Error
    die Regel für Ziel „CRectangle.o“ scheiterte subdir.mk /CRectangle/Debug line 27 C/C++ Problem
    Field 'x' could not be resolved CRectangle.cpp /CRectangle line 34 Semantic Error



  • Dann suchst du mal die Stelle in deiner IDE, an der man die Ausgabe des Compilers sehen kann und kopierst die komplette Meldung.



  • Das sind doch oben die Fehlermeldungen ?



  • Nein, das ist das was deine IDE aus den Ausgaben macht. Suche die echte Ausgabe des Compilers.



  • 1:09:26 **** Incremental Build of configuration Debug for project CRectangle ****
    make all
    Building file: ../CRectangle.cpp
    Invoking: GCC C++ Compiler
    g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"CRectangle.d" -MT"CRectangle.d" -o "CRectangle.o" "../CRectangle.cpp"
    ../CRectangle.cpp: In constructor ‘CRectangle::CRectangle(CPoint, CPoint, char)’:
    ../CRectangle.cpp:34:15: error: ‘class CPoint’ has no member named ‘x’
    if(topRight.x < bottomLeft.x ){
    ^
    ../CRectangle.cpp:34:30: error: ‘class CPoint’ has no member named ‘x’
    if(topRight.x < bottomLeft.x ){
    ^
    ../CRectangle.cpp:36:17: error: ‘class CPoint’ has no member named ‘x’
    m_topRight.x = bottomLeft.x;
    ^
    ../CRectangle.cpp:36:32: error: ‘class CPoint’ has no member named ‘x’
    m_topRight.x = bottomLeft.x;
    ^
    ../CRectangle.cpp:39:16: error: ‘class CPoint’ has no member named ‘y’
    if(topRight.y < bottomLeft.y){
    ^
    ../CRectangle.cpp:39:31: error: ‘class CPoint’ has no member named ‘y’
    if(topRight.y < bottomLeft.y){
    ^
    ../CRectangle.cpp:41:17: error: ‘class CPoint’ has no member named ‘y’
    m_topRight.y = bottomLeft.y;
    ^
    ../CRectangle.cpp:41:32: error: ‘class CPoint’ has no member named ‘y’
    m_topRight.y = bottomLeft.y;
    ^
    make: *** [CRectangle.o] Fehler 1
    subdir.mk:27: die Regel für Ziel „CRectangle.o“ scheiterte

    21:09:26 Build Finished (took 483ms)



  • Versuch mal mit Worten zu beschreiben was die Fehlermeldung bemängelt.
    Dann sollte klar werden wo der Fehler liegt.



  • Wie kommst du auf .x bzw. .y?
    Schau dir die Klasse "CPoint" nochmal genau an...



  • In der Klasse steht es so:

    CPoint::CPoint(int x, int y) 
    { 
        m_x = x; 
        m_y = y; 
    } 
    
    void CPoint::setX(int x) 
    { 
        m_x = x; 
    } 
    
    void CPoint::setY(int y) 
    { 
        m_y = y; 
    }
    

    Ich dachte das man mit dem .x auf das x zugreift ?

    Wie soll ich es sonst machen?



  • Gast12 schrieb:

    Wie soll ich es sonst machen?

    Über die Funktionen, welche dir die Klasse CPoint anbietet, um den Wert von x bzw. y zu erhalten.



  • Habe es so versucht , aber scheint auch das problem nicht zu lösen?

    if(topRight.setX() < bottomLeft.setX() ){
    
    	    m_topRight.setX() = bottomLeft.setX();
    	  }
    


  • Ja klar, setX ist die Funktion, die den Wert x liefert. Ernsthaft? Da stehen sogar noch Kommentare dran!



  • manni66 schrieb:

    Ja klar, setX ist die Funktion, die den Wert x liefert. Ernsthaft? Da stehen sogar noch Kommentare dran!

    Das unterstütze ich! Bitte erstmal das Lesen womit man arbeitet! Ansonsten muss man das hier leider als Trollversuch einordnen.



  • #include "CRectangle.h"
    #include "CPoint.h"
    CRectangle::CRectangle(char fillChar)
    
    {
      m_fillChar = fillChar;
      /**
         * Erzeugt ein neues Rechteck mit der angegebenen linken
         * unteren und rechten oberen Ecken sowie dem angegebenen
         * F�llzeichen.
         *
         * Beim Erzeugen wird die Zusicherung �berpr�ft, dass die
         * rechte obere Ecke rechts von und oberhalt der linken
         * unteren Ecke liegen muss! Falls die x-Koordinate
         * der rechten oberen Ecke nicht gr��er als die x-Koordinate
         * der linken unteren Ecke ist, wird sie auf den Wert
         * der x-Koordinate der linken unteren Ecke gesetzt. Falls
         * die y-Koordinate der rechten oberen Ecke nicht gr��er als
         * die y-Koordinate der linken unteren Ecke ist, wird sie auf
         * dem Wert der y-Koordinate der linken unteren Ecke gesetzt.
         */
    
    }
    
    CRectangle::CRectangle(CPoint bottomLeft, CPoint topRight, char fillChar)
    {
    	m_fillChar = fillChar;
    
    	 if(topRight.getX() < bottomLeft.getX() ){
    
    	    m_topRight.setX(bottomLeft.getX());
    	  }
    
    	  if(topRight.getY() < bottomLeft.getY()){
    
    	    m_topRight.setY(bottomLeft.getY());
    	  }
    }
    
    void CRectangle::setCorners(CPoint bottomLeft, CPoint topRight)
    {
    	// Bitte implementieren
    }
    
    CPoint CRectangle::getBottomLeftCorner() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return CPoint();
    }
    
    CPoint CRectangle::getTopRightCorner() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return CPoint();
    }
    
    void CRectangle::setFillChar(char fillChar)
    {
    	// Bitte implementieren
    }
    
    char CRectangle::getFillChar() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return 0;
    }
    
    bool CRectangle::operator ==(const CRectangle& other) const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return false;
    }
    
    void CRectangle::draw(CScreen& screen) const
    {
    	// Bitte implementieren
    }
    

    Noch diese Fehler zu beseitigen ?
    Eclipse meckert auch nur rum. 😃

    Description Resource Path Location Type
    no matching function for call to ‘CPoint::setX()’ CRectangle.cpp
    /CRectangle line 34 C/C++ Problem
    candidate: void CPoint::setX(int) CPoint.h /CRectangle line 32 C/C++
    Problem
    candidate expects 1 argument, 0 provided CPoint.h /CRectangle line
    32 C/C++ Problem
    no matching function for call to ‘CPoint::setY()’ CRectangle.cpp
    /CRectangle line 39 C/C++ Problem
    make: *** [CRectangle.o] Fehler 1 CRectangle C/C++ Problem
    no matching function for call to ‘CPoint::setX()’ CRectangle.cpp
    /CRectangle line 36 C/C++ Problem
    die Regel für Ziel „CRectangle.o“ scheiterte subdir.mk
    /CRectangle/Debug line 27 C/C++ Problem
    candidate: void CPoint::setY(int) CPoint.h /CRectangle line 37 C/C++
    Problem
    candidate expects 1 argument, 0 provided CPoint.h /CRectangle line
    37 C/C++ Problem
    no matching function for call to ‘CPoint::setY()’ CRectangle.cpp
    /CRectangle line 41 C/C++ Problem



  • manni66 schrieb:

    Dann suchst du mal die Stelle in deiner IDE, an der man die Ausgabe des Compilers sehen kann und kopierst die komplette Meldung.



  • Building file: ../CRectangle.cpp
    Invoking: GCC C++ Compiler
    g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"CRectangle.d" -MT"CRectangle.d" -o "CRectangle.o" "../CRectangle.cpp"
    ../CRectangle.cpp: In constructor ‘CRectangle::CRectangle(CPoint, CPoint, char)’:
    ../CRectangle.cpp:34:20: error: no matching function for call to ‘CPoint::setX()’
    if(topRight.setX() < bottomLeft.setX() ){
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:32:7: note: candidate: void CPoint::setX(int)
    void setX(int x);
    ^~~~
    ../CPoint.h:32:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:34:40: error: no matching function for call to ‘CPoint::setX()’
    if(topRight.setX() < bottomLeft.setX() ){
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:32:7: note: candidate: void CPoint::setX(int)
    void setX(int x);
    ^~~~
    ../CPoint.h:32:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:36:22: error: no matching function for call to ‘CPoint::setX()’
    m_topRight.setX() = bottomLeft.setX();
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:32:7: note: candidate: void CPoint::setX(int)
    void setX(int x);
    ^~~~
    ../CPoint.h:32:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:36:42: error: no matching function for call to ‘CPoint::setX()’
    m_topRight.setX() = bottomLeft.setX();
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:32:7: note: candidate: void CPoint::setX(int)
    void setX(int x);
    ^~~~
    ../CPoint.h:32:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:39:21: error: no matching function for call to ‘CPoint::setY()’
    if(topRight.setY() < bottomLeft.setY()){
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:37:7: note: candidate: void CPoint::setY(int)
    void setY(int y);
    ^~~~
    ../CPoint.h:37:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:39:41: error: no matching function for call to ‘CPoint::setY()’
    if(topRight.setY() < bottomLeft.setY()){
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:37:7: note: candidate: void CPoint::setY(int)
    void setY(int y);
    ^~~~
    ../CPoint.h:37:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:41:22: error: no matching function for call to ‘CPoint::setY()’
    m_topRight.setY() = bottomLeft.setY();
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:37:7: note: candidate: void CPoint::setY(int)
    void setY(int y);
    ^~~~
    ../CPoint.h:37:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:41:42: error: no matching function for call to ‘CPoint::setY()’
    m_topRight.setY() = bottomLeft.setY();
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:37:7: note: candidate: void CPoint::setY(int)
    void setY(int y);
    ^~~~
    ../CPoint.h:37:7: note: candidate expects 1 argument, 0 provided
    make: *** [CRectangle.o] Fehler 1
    subdir.mk:27: die Regel für Ziel „CRectangle.o“ scheiterte

    00:29:08 Build Finished (took 302ms)



  • Das ist die Stelle, die du angeblich geändert hast...



  • Jetzt klappt es ohne Fehlermeldung .

    Kann ich die Zuweisung so vor der If Bedingung machen ?

    m_fillChar = fillChar;
    m_bottomLeft = bottomLeft;
    m_topRight = topRight;

    * CRectangle.cpp
     *
     *  Created on: 05.02.2015
     *      Author: lipp
     */
    
    #include "CRectangle.h"
    #include "CPoint.h"
    CRectangle::CRectangle(char fillChar)
    
    {
      m_fillChar = fillChar;
      /**
         * Erzeugt ein neues Rechteck mit der angegebenen linken
         * unteren und rechten oberen Ecken sowie dem angegebenen
         * F�llzeichen.
         *
         * Beim Erzeugen wird die Zusicherung �berpr�ft, dass die
         * rechte obere Ecke rechts von und oberhalt der linken
         * unteren Ecke liegen muss! Falls die x-Koordinate
         * der rechten oberen Ecke nicht gr��er als die x-Koordinate
         * der linken unteren Ecke ist, wird sie auf den Wert
         * der x-Koordinate der linken unteren Ecke gesetzt. Falls
         * die y-Koordinate der rechten oberen Ecke nicht gr��er als
         * die y-Koordinate der linken unteren Ecke ist, wird sie auf
         * dem Wert der y-Koordinate der linken unteren Ecke gesetzt.
         */
    
    }
    
    CRectangle::CRectangle(CPoint bottomLeft, CPoint topRight, char fillChar)
    {
    	m_fillChar = fillChar;
    	m_bottomLeft = bottomLeft;
    	m_topRight = topRight;
    
    	 if(topRight.getX() < bottomLeft.getX() ){
    
    	    m_topRight.CPoint::setX(bottomLeft.getX());
    	  }
    
    	  if(topRight.getY() < bottomLeft.getY()){
    
    	    m_topRight.setY(bottomLeft.getY());
    	  }
    }
    
    void CRectangle::setCorners(CPoint bottomLeft, CPoint topRight)
    {
    	// Bitte implementieren
    }
    
    CPoint CRectangle::getBottomLeftCorner() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return CPoint();
    }
    
    CPoint CRectangle::getTopRightCorner() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return CPoint();
    }
    
    void CRectangle::setFillChar(char fillChar)
    {
    	// Bitte implementieren
    }
    
    char CRectangle::getFillChar() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return 0;
    }
    
    bool CRectangle::operator ==(const CRectangle& other) const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return false;
    }
    
    void CRectangle::draw(CScreen& screen) const
    {
    	// Bitte implementieren
    }
    


  • Gast12 schrieb:

    Jetzt klappt es ohne Fehlermeldung .

    Kann ich die Zuweisung so vor der If Bedingung machen ?

    m_fillChar = fillChar;
    m_bottomLeft = bottomLeft;
    m_topRight = topRight;

    Technisch gesehen kannst du das machen. Ob es das ist, was du machen willst, kann ich nicht beurteilen. Am besten probierst du aus, ob das raus kommt, was du erwartest.



  • Sagen wir mal so .
    Ich übe ja an dieser Aufgabe.
    Ist es das was der Aufgabensteller erwartet ? 😃



  • Gast12 schrieb:

    Sagen wir mal so .
    Ich übe ja an dieser Aufgabe.
    Ist es das was der Aufgabensteller erwartet ? 😃

    Ich denke mal der erwartet (oder eventuell auch nicht), dass durch das Lösen der Aufgabe Verständnis für das Programmieren und die Sprache entwickelst.
    Das wird aber nicht passieren, wenn du einfach nur rätst und da irgendwas reinschreibst.
    Du musst schon die Logik dahinter verstehen und dir auch etwas dabei denken.

    Im Endeffekt drückt man beim Programmieren einen logischen Gedankengang in einer formalen Sprache aus - wenn man die Logik einfach weglässt und per trial und error + Forenposts irgendwann zum Ergebnis kommt, dann hat man aber nichts gelernt.


Anmelden zum Antworten