rect.hpp
Code:
#include <iostream.h>
//rect.hpp
class Point
{
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;
};
//klasa rectangle pocetak...
class Rectangle
{
public:
Rectangle (int top, int left, int right, int bottom);
~Rectangle() {}
int getTop() const {return itsTop;}
int getLeft() const {return itsLeft;}
int getRight() const {return itsRight;}
int getBottom() const {return itsBottom;}
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;}
void setTop(int top) {itsTop = top;}
void setLeft(int left) {itsLeft = left;}
void setRight(int right) {itsRight = right;}
void setBottom(int bottom) {itsBottom = bottom;}
int getArea() const;
private:
int itsTop;
int itsLeft;
int itsRight;
int itsBottom;
int itsUpperLeft;
int itsLowerLeft;
int itsUpperRight;
int itsLowerRight;
};
//kraj rect.hpp
#include <iostream.h>
//rect.hpp
class Point
{
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;
};
//klasa rectangle pocetak...
class Rectangle
{
public:
Rectangle (int top, int left, int right, int bottom);
~Rectangle() {}
int getTop() const {return itsTop;}
int getLeft() const {return itsLeft;}
int getRight() const {return itsRight;}
int getBottom() const {return itsBottom;}
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;}
void setTop(int top) {itsTop = top;}
void setLeft(int left) {itsLeft = left;}
void setRight(int right) {itsRight = right;}
void setBottom(int bottom) {itsBottom = bottom;}
int getArea() const;
private:
int itsTop;
int itsLeft;
int itsRight;
int itsBottom;
int itsUpperLeft;
int itsLowerLeft;
int itsUpperRight;
int itsLowerRight;
};
//kraj rect.hpp
rect.cpp
Code:
#include <iostream.h>
#include <stdlib.h>
#include <rect.hpp>
//pocetak rect.cpp
Rectangle::Rectangle (int top, int left, int right, int bottom)
{
itsTop = top;
itsLeft = left;
itsRight = right;
itsBottom = bottom;
itsUpperLeft.setX(left);
itsUpperLeft.setY(top);
itsUpperRight.setX(right);
itsUpperRight.setY(top);
itsLowerLeft.setX(left);
itsLowerLeft.setY(bottom);
itsLowerRight.setX(right);
itsLowerRight.setY(bottom);
}
int Rectangle::getArea() const
{
int width = itsRight - itsLeft;
int height = itsTop - itsBottom;
return (width*height);
}
int main()
{
Rectangle myRectangle ( 100, 20, 50 ,80 );
int Area = myRectangle.getArea();
cout << "Area : " << Area << "\n";
cout << "Gornja lijeva x koordinata : " << myRectangle.getUpperLeft().getX() ;
return 0;
system("pause");
}
#include <iostream.h>
#include <stdlib.h>
#include <rect.hpp>
//pocetak rect.cpp
Rectangle::Rectangle (int top, int left, int right, int bottom)
{
itsTop = top;
itsLeft = left;
itsRight = right;
itsBottom = bottom;
itsUpperLeft.setX(left);
itsUpperLeft.setY(top);
itsUpperRight.setX(right);
itsUpperRight.setY(top);
itsLowerLeft.setX(left);
itsLowerLeft.setY(bottom);
itsLowerRight.setX(right);
itsLowerRight.setY(bottom);
}
int Rectangle::getArea() const
{
int width = itsRight - itsLeft;
int height = itsTop - itsBottom;
return (width*height);
}
int main()
{
Rectangle myRectangle ( 100, 20, 50 ,80 );
int Area = myRectangle.getArea();
cout << "Area : " << Area << "\n";
cout << "Gornja lijeva x koordinata : " << myRectangle.getUpperLeft().getX() ;
return 0;
system("pause");
}
Radim u devc++ kompajleru i izbaciva mi slijedece greske:
In file included from g:\c__tes~1\weekon~1\rect.cpp:3:
C:\DEV-C_~1\Include\rect.hpp: In method `class Point Rectangle::getUpperLeft() const':
C:\DEV-C_~1\Include\rect.hpp:28: conversion from `const int' to non-scalar type `Point' requested
C:\DEV-C_~1\Include\rect.hpp: In method `class Point Rectangle::getLowerLeft() const':
C:\DEV-C_~1\Include\rect.hpp:29: conversion from `const int' to non-scalar type `Point' requested
C:\DEV-C_~1\Include\rect.hpp: In method `class Point Rectangle::getUpperRight() const':
C:\DEV-C_~1\Include\rect.hpp:30: conversion from `const int' to non-scalar type `Point' requested
C:\DEV-C_~1\Include\rect.hpp: In method `class Point Rectangle::getLowerRight() const':
C:\DEV-C_~1\Include\rect.hpp:31: conversion from `const int' to non-scalar type `Point' requested
C:\DEV-C_~1\Include\rect.hpp: In method `void Rectangle::setUpperLeft(Point)':
C:\DEV-C_~1\Include\rect.hpp:33: `class Point' used where a `int' was expected
C:\DEV-C_~1\Include\rect.hpp: In method `void Rectangle::setLowerLeft(Point)':
C:\DEV-C_~1\Include\rect.hpp:34: `class Point' used where a `int' was expected
C:\DEV-C_~1\Include\rect.hpp: In method `void Rectangle::setUpperRight(Point)':
C:\DEV-C_~1\Include\rect.hpp:35: `class Point' used where a `int' was expected
C:\DEV-C_~1\Include\rect.hpp: In method `void Rectangle::setLowerRight(Point)':
C:\DEV-C_~1\Include\rect.hpp:36: `class Point' used where a `int' was expected
g:\c__tes~1\weekon~1\rect.cpp: In method `Rectangle::Rectangle(int, int, int, int)':
g:\c__tes~1\weekon~1\rect.cpp:14: request for member `setX' in `Rectangle::itsUpperLeft', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:15: request for member `setY' in `Rectangle::itsUpperLeft', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:17: request for member `setX' in `Rectangle::itsUpperRight', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:18: request for member `setY' in `Rectangle::itsUpperRight', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:20: request for member `setX' in `Rectangle::itsLowerLeft', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:21: request for member `setY' in `Rectangle::itsLowerLeft', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:23: request for member `setX' in `Rectangle::itsLowerRight', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:24: request for member `setY' in `Rectangle::itsLowerRight', which is of non-aggregate type `int'
Jednostavno ne razumijem u cemu je problem... Jos sam pocetnik za c++ i jednostavno sve sto pokusam ne otklanja ove greske jer je vjerovatno problem negdje u sintaksi... Hvala unaprijed na pomoci!
The truth is out there somewhere...