C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 4th, 2004, 04:01 PM
sdobby sdobby is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 1 sdobby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problem with this programming I'm making!

Okay, I've looked over my thing like a million times and I can't figure out whats wrong! (Yea I'm pretty new at programming...)

Here's the code I'm working with...any help would be greatly appreciated! Thanks!

RECT.HPP

//Begin Rect.hpp
#include <iostream>

class Point //holds x,y coordinates
{
//no constructor, use 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 GetBottom() const {return itsBottom;}
int GetRight() const {return itsRight;}

Point GetUpperLeft() const {return itsUpperLeft;}
Point GetLowerLeft() const {return itsLowerLeft;}
Point GetUpperRight() const {return itsUpperRight;}
Point GetLowerRight() const {return itsLowerRight;}

void SetUpperLeft(Point Location);
void SetLowerLeft(Point Location);
void SetUpperRight(Point Location);
void SetLowerRight(Point Location);

void SetTop(int top);
void SetLeft(int left);
void SetBottom(int bottom);
void SetRight(int right);

int GetArea() const;

private:
Point itsUpperLeft;
Point itsLowerLeft;
Point itsUpperRight;
Point itsLowerRight;
int itsTop;
int itsLeft;
int itsBottom;
int itsRight;
};
//end Rect.hpp

RECT.CPP

//Begin rect.cpp
#include "Rect.hpp"

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);
}

void Rectangle::SetUpperLeft(Point Location)
{
itsUpperLeft = Location;
itsUpperRight.SetY(Location.GetY());
itsLowerLeft.SetX(Location.GetX());
itsTop = Location.GetY();
itsLeft = Location.GetX();
}

void Rectangle::SetLowerLeft(Point Location)
{
itsLowerLeft = Location;
itsLowerRight.SetY(Location.GetY());
itsUpperLeft.SetX(Location.GetX());
itsBottom = Location.GetY();
itsLeft = Location.GetX();
}

void Rectangle::SetLowerRight(Point Location)
{
itsLowerRight = Location;
itsLowerLeft.SetY(Location.GetY());
itsUpperRight.SetX(Location.GetX());
itsBottom = Location.GetY();
itsRight = Location.GetX();
}

void Rectangle::SetUpperRight(Point Location)
{
itsUpperRight = Location;
itsUpperLeft.SetY(Location.GetY());
itsLowerRight.SetX(Location.GetX());
itsTop = Location.GetY();
itsRight = Location.GetX();
}

void Rectangle::SetTop(int top)
{
itsTop = top;
itsUpperLeft.SetY(top);
itsUpperRight.SetY(top);
}

void Rectangle::SetLeft(int left)
{
itsLeft = left;
itsUpperLeft.SetX(left);
itsLowerLeft.SetX(left);
}

void Rectangle::SetBottom(int bottom)
{
itsBottom = bottom;
itsLowerLeft.SetY(bottom);
itsLowerRight.SetY(bottom);
}

void Rectangle::SetRight(int right)
{
itsRight = right;
itsUpperRight.SetX(right);
itsLowerRight.SetX(right);
}

int Rectangle::GetArea() const
{
int Width = itsRight-itsLeft;
int Height = itsTop - itsBottom;
return(Width*Height);
}

//compute are of the rectangle by finding corners,
//establishing width and height and then multiply
int main()
{
//initialize a locatl Rectangle variable
Rectangle MyRectangle(100, 20, 50, 80);

int Area = MyRectangle.GetArea();

std::cout << "Area: " << Area << "\n";
std::cout << "Upper Left X Coordinate: ";
std::cout << MyRectangle.GetUpperLeft().GetX();
system("pause");
return 0;
}

ERRORS THAT I GOT
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c Rect.cpp -o Rect.o -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"

Rect.cpp: In function `int main()':
Rect.cpp:100: `Rectangle' undeclared (first use this function)
Rect.cpp:100: (Each undeclared identifier is reported only once for each

function it appears in.)
Rect.cpp:100: parse error before `(' token
Rect.cpp:102: `MyRectangle' undeclared (first use this function)

make.exe: *** [Rect.o] Error 1

Execution terminated

Reply With Quote
  #2  
Old November 8th, 2004, 07:56 AM
duxxx001 duxxx001 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 4 duxxx001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

Quote:
Originally Posted by sdobby
Okay, I've looked over my thing like a million times and I can't figure out whats wrong! (Yea I'm pretty new at programming...)


Hmm, I've tried your example and it workd for me, so you have these options:

You have to havefollowing files: rect.hpp, rect.cpp, test.cpp

test.cpp
___________________
#include <rect.h>

int main(int argc, char *argv[])
{
...
}
_____________________


rect.hpp
___________________
#ifndef RECT_HPP
#define RECT_HPP

.. your stuff ..

#endif
___________________


rect.cpp
__________________
#include <rect.hpp>

.. your stuff ..
__________________

Now try woth these 3 files and it should work. If it doesn't, problem is in you compiler so change it
Since I use Linux, I tried this with Intel & gcc compilers, and it works flawlessly.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Problem with this programming I'm making!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT