In Rect.hpp
Code:
#ifndef Rect_H
#define Rect_H
// Begin Rect.h
#include <cstdlib.h>
#include <iostream.h>
class Point{ // holds x,y coordinates
//no constructor, using default
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;
}; // end of Point Class declaration
class Rectangle{
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; }
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:
Point itsUpperLeft;
Point itsUpperRight;
Point itsLowerLeft;
Point itsLowerRight;
int itsTop;
int itsLeft;
int itsBottom;
int itsRight;
};
#endif /*Rect_H*/
In main.cpp
Code:
#include "rect.hpp"
Rectangle::Rectangle(int top, int left, int bottom, int right){
itsTop = top;
itsRight = right;
itsLeft = left;
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);
}
// compute area of rectangle by finding corners,
// establish width and height then multiply (algebra lol)
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 << "Upper Left X Coordinate: ";
cout << MyRectangle.GetUpperLeft().GetX();
return 0;
}
Output from compiler:
Compiler: Default compiler
Executing g++.exe...
g++.exe "Z:\Code\6.9.cpp" -o "Z:\Code\6.9.exe" -fverbose-asm -I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include\c++\mingw32" -I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
In file included from Z:/Code/6.9.cpp:2:
Z:/Code/rect.hpp:4:21: cstdlib.h: No such file or directory
In file included from C:/Dev-Cpp/include/c++/backward/iostream.h:31,
from Z:/Code/rect.hpp:5,
from Z:/Code/6.9.cpp:2:
C:/Dev-Cpp/include/c++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
Z:/Code/6.9.cpp: In function `int main()':
Z:/Code/6.9.cpp:32: `Rectangle' undeclared (first use this function)
Z:/Code/6.9.cpp:32: (Each undeclared identifier is reported only once for each
function it appears in.)
Z:/Code/6.9.cpp:32: parse error before `(' token
Z:/Code/6.9.cpp:34: `MyRectangle' undeclared (first use this function)
Execution terminated
Basically, I already declared Rectangle -- so I don't understand why it's saying undeclared. It compiles fine in MSVC according to a friend -- so is there some sort of software glitch this compiler might have? Or do you see something wrong w/ my code?