Witam. Mam taki program :
rect.h :
#include <iostream>
class Point // przechowuje współżędne x, y
{
public :
void SetX (int x) { itsX = x ; } ;
void SetY (int y) { itsY = y ; } ;
int GetX () const { return itsX ; };
int GetY () const { return itsY ; };
private :
int itsX ;
int itsY ;
} ;
class Rectangle // definicja klasy Prostokąt
{
public :
Rectangle (int top, int left, int bottom, int right) ;
~Rectangle () {} ;
int GetTop () const { return itsTop ; } ;
int GetLeft () const { return itsLeft ; } ;
int GetRight () const { return itsRight ; } ;
int GetBottom () const { return itsBottom ; } ;
void SetTop ( int top ) { itsTop = top ; } ;
void SetLeft ( int left ) { itsLeft = left ; } ;
void SetRight ( int right ) { itsRight = right ; } ;
void SetBottom ( int bottom ) { itsBottom = bottom ; } ;
Point GetUpperLeft () const { return itsUpperLeft ; } ;
Point GetLowerLeft () const { return itsLowerLeft ; } ;
Point GetUpperRight() const { return itsUpperRight ; } ;
Point GetLowerRight () const { return itsLowerRight ; } ;
void SetUpperLeft (Point Location) { itsUpperLeft = Location ; } ;
void SetLowerLeft (Point Location) { itsLowerLeft = Location ; } ;
void SetUpperRight(Point Location) { itsUpperRight = Location ; } ;
void SetLowerRight(Point Location) { itsLowerRight = Location ; } ;
int GetArea () const ;
private :
int itsTop ;
int itsLeft ;
int itsRight ;
int itsBottom ;
Point itsUpperLeft ;
Point itsUpperRight ;
Point itsLowerLeft ;
Point itsLowerRight ;
} ;
rectangle.cpp :
#include "rect.h"
#include <cstdlib>
#include <iostream>
#include <conio.h>
Rectangle::Rectangle (int top, int left, int bottom, int right)
{
itsTop = top ;
itsLeft = left ;
itsBottom = bottom ;
itsRight = right ;
itsUpperLeft.SetX(left) ;
itsUpperLeft.SetY(top) ;
itsUpperRight.SetX(right) ;
itsUpperRight.SetY(top) ;
itsLowerLeft.SetX(left) ;
itsLowerLeft.SetY(bottom);
itsLowerRight.SetX(right);
itsLowerRight.SetY(bottom);
}
// oblicza obszar prostokąta przez pomnożenie szerokości i wysokości
int Rectangle::GetArea () const
{
int Width = itsRight - itsLeft ;
int Height = itsTop - itsBottom ;
return (Width*Height) ;
}
main.cpp :
#include "rect.h"
#include <cstdlib>
#include <iostream>
#include <conio.h>
using namespace std;
int main(int argc, char *argv[])
{
//inicjalizacja zmiennej lokalnej typu Rentagle
Rectangle MyRentagle(100, 20, 50, 80) ;
int Area = MyRentagle.GetArea() ;
cout << "Obszar " << Area << endl ;
cout << "\nWspolzedna X gornego lewego rogu : " ;
cout << MyRentagle.GetUpperLeft().GetX() ;
cout << "\nWspolzedna Y gornego lewego rogu : " ;
cout << MyRentagle.GetUpperLeft().GetY() ;
cout << "\n\nWspolzedna X gornego prawego rogu : " ;
cout << MyRentagle.GetUpperRight().GetX() ;
cout << "\nWspolezdna Y gornego prawego rogu : " ;
cout << MyRentagle.GetUpperRight().GetY() ;
cout << "\n\nWspolzedna X dolnego lewego rogu : " ;
cout << MyRentagle.GetLowerLeft().GetX() ;
cout << "\nWspolzedna Y dolnego lewego rogu : " ;
cout << MyRentagle.GetLowerLeft().GetY() ;
cout <<"\n\nWspolzedna X dolnego prawego rogu : " ;
cout << MyRentagle.GetLowerRight().GetX() ;
cout << "\nWspolzedna Y dolnego prawego rogu : " ;
cout << MyRentagle.GetLowerRight().GetY() ;
getch() ;
return 0 ;
}
=============
Gdzie jest problem ? Przy współrzędnej dolnego prawego rogu.
Wyniki programu są takie :
X górny lewy : 20 , zgadza się
Y górny lewy : 100 , zgadza się
X górny prawy : 80 , zgadza się
Y górny prawy : 100 , zgadza się
X dolny lewy : 20 , zgadza się
Y dolny lewy : 50 , zgadza się
X dolny prawy : 20 , i tu jest zonk. Powinno być 80 . Przeleciałem kilka razy po kodzie i nie wiem, ja nie widzę błędu nigdzie ; /
Y dolny prawy : 50, i to też się zgadza
Proszę o pomoc z tym drobnym problemem : )
Pozdrawiam !</b>