Closed Thread Icon

Topic awaiting preservation: C++ problem (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=22352" title="Pages that link to Topic awaiting preservation: C++ problem (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: C++ problem <span class="small">(Page 1 of 1)</span>\

 
OlssonE
Maniac (V) Inmate

From: Eagleshieldsbay, Sweden
Insane since: Nov 2001

posted posted 06-28-2004 18:56

I get an "Undefined symbol 'Rectangle" at this line void DoDrawRect(Rectangle);

edit: I use Borland Cbuilder

code:
//---------------------------------------------------------------------------
#include <iostream.h>
#include <vcl.h>
#pragma hdrstop
#pragma argsused
//---------------------------------------------------------------------------

enum CHOICE { DrawRect = 1, GetArea, GetPerim, ChangeDimensions, Quit };

class Rectangle
{
public:
Rectangle(int width, int height);
~Rectangle();

int GetHeight() const {return itsHeight;}
int GetWidth() const {return itsWidth;}
int GetArea() const {return itsHeight * itsWidth;}
int GetPerim() const {return 2*itsHeight + 2*itsWidth;}
void SetSize(int newWidth, int newHeight);

private:
int itsWidth;
int itsHeight;
};

void Rectangle::SetSize(int newWidth, int newHeight)
{
itsWidth = newWidth;
itsHeight = newHeight;
}

Rectangle::Rectangle(int width, int height)
{
itsWidth = width;
itsHeight = height;

}

Rectangle::~Rectangle() {}

int DoMenu();
void DoDrawRect(Rectangle); //-I get an "Undefined symbol 'Rectangle"
void DoGetArea(Rectangle); //-I get an "Undefined symbol 'Rectangle"
void DoGetPerim(Rectangle);//-I get an "Undefined symbol 'Rectangle"




int main(int argc, char* argv[])
{
Rectangle theRect(30,5);

int choice = DrawRect;
bool fQuit = false;

while (!fQuit)
{
choice = DoMenu();
if (choice < DrawRect || choice > Quit)
{
cout << "\nOgiltigt vail, försök igen.\n\n";
continue;
}
switch (choice)
{
case DrawRect:
DoDrawRect(theRect);
break;
case GetArea:
DoGetArea(theRect);
break;
case GetPerim:
DoGetPerim(theRect);
break;
case ChangeDimensions:
int newLength, newWidth;
cout << "\nNy bredd: ";
cin >> newWidth;
cout << "Ny höjd: ";
cin >> newLength;
theRect.SetSize(newWidth, newLength);
DoDrawRect(theRect);
break;
case Quit:
fQuit = true;
cout << "\nAvslutar...\n\n";
break;
default:
cout << "Fel i val\n";
fQuit = True;
break;
}
}

return 0;
}
//---------------------------------------------------------------------------

int DoMenu()
{
int choice;
cout << "\n\n *** Meny *** \n";
cout << "(1) Rita rektangeln\n";
cout << "(2) Area\n";
cout << "(3) Omkrets\n";
cout << "(4) Ändra storlek\n";
cout << "(5) Avsluta\n";

cin >> choice;
return choice;
}

void DrawRect(Rectangle theRect)
{
int height = thrRect.GetHeight();
int width = theRect.GetWidth();

for (int i = 0; i<height; i++)
{
for (int j = 0; j<width; j++)
cout << "*";
cout << "\n";
}
}

void DoGetArea(Rectangle theRect)
{
cout << "Area: " << thrRect.GetArea() << endl;
}

void DoGetPerim(Rectangle theRect)
{
cout << "Omrkets: " << theRect.GetPerim() << endl;
}



(Edited by OlssonE on 06-28-2004 20:50)

OlssonE
Maniac (V) Inmate

From: Eagleshieldsbay, Sweden
Insane since: Nov 2001

posted posted 06-28-2004 20:46

If someone with a diffrent compiler would try and compile this code.
Then I would now If It Is an compiler based problem. It's probably not
but just good to know....

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 06-28-2004 20:55

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

OlssonE
Maniac (V) Inmate

From: Eagleshieldsbay, Sweden
Insane since: Nov 2001

posted posted 06-28-2004 21:20

Ok, I've tried that It didn't fix It...

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-28-2004 21:51

lol, your defining Rectangle what?

You need to have something like void DoDrawRect(Rectangle r);

OlssonE
Maniac (V) Inmate

From: Eagleshieldsbay, Sweden
Insane since: Nov 2001

posted posted 06-28-2004 21:57

Nope... I'm declaring DoDrawRect(Rectangle);
And I have already tried that...

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-28-2004 22:01

Ugh, let me try to compile this.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-28-2004 22:33

So it was all Syntax errors and a logic error. I have the code as follows and it compiles.

1) True != true
2) ThrRect doesn't exist
3) void DoDrawRect() doesn't exist, DrawRect() does.
4) the enum DrawRect is a function, changed to DRect

code:
//---------------------------------------------------------------------------

#include <iostream.h>


#pragma hdrstop

#pragma argsused

//---------------------------------------------------------------------------



enum CHOICE { DRect = 1, GetArea, GetPerim, ChangeDimensions, Quit };



class Rectangle

{

public:

Rectangle(int width, int height);

~Rectangle();



int GetHeight() const {return itsHeight;}

int GetWidth() const {return itsWidth;}

int GetArea() const {return itsHeight * itsWidth;}

int GetPerim() const {return 2*itsHeight + 2*itsWidth;}

void SetSize(int newWidth, int newHeight);



private:

int itsWidth;

int itsHeight;

};



void Rectangle::SetSize(int newWidth, int newHeight)

{

itsWidth = newWidth;

itsHeight = newHeight;

}



Rectangle::Rectangle(int width, int height)

{

itsWidth = width;

itsHeight = height;



}



Rectangle::~Rectangle() {}



int DoMenu();

void DoDrawRect(Rectangle); //-I get an "Undefined symbol 'Rectangle"

void DoGetArea(Rectangle); //-I get an "Undefined symbol 'Rectangle"

void DoGetPerim(Rectangle);//-I get an "Undefined symbol 'Rectangle"









int main(int argc, char* argv[])

{

Rectangle theRect(30,5);



int choice = DRect;

bool fQuit = false;



while (!fQuit)

{

choice = DoMenu();

if (choice < DRect || choice > Quit)

{

cout << "\nOgiltigt vail, försök igen.\n\n";

continue;

}

switch (choice)

{

case DRect:

DoDrawRect(theRect);

break;

case GetArea:

DoGetArea(theRect);

break;

case GetPerim:

DoGetPerim(theRect);

break;

case ChangeDimensions:

int newLength, newWidth;

cout << "\nNy bredd: ";

cin >> newWidth;

cout << "Ny höjd: ";

cin >> newLength;

theRect.SetSize(newWidth, newLength);

DoDrawRect(theRect);

break;

case Quit:

fQuit = true;

cout << "\nAvslutar...\n\n";

break;

default:

cout << "Fel i val\n";

fQuit = true;

break;

}

}



return 0;

}

//---------------------------------------------------------------------------



int DoMenu()

{

int choice;

cout << "\n\n *** Meny *** \n";

cout << "(1) Rita rektangeln\n";

cout << "(2) Area\n";

cout << "(3) Omkrets\n";

cout << "(4) Ändra storlek\n";

cout << "(5) Avsluta\n";



cin >> choice;

return choice;

}



void DoDrawRect(Rectangle theRect)

{

int height = theRect.GetHeight();

int width = theRect.GetWidth();



for (int i = 0; i<height; i++)

{

for (int j = 0; j<width; j++)

cout << "*";

cout << "\n";

}

}



void DoGetArea(Rectangle theRect)

{

cout << "Area: " << theRect.GetArea() << endl;

}



void DoGetPerim(Rectangle theRect)

{

cout << "Omrkets: " << theRect.GetPerim() << endl;

}

OlssonE
Maniac (V) Inmate

From: Eagleshieldsbay, Sweden
Insane since: Nov 2001

posted posted 06-28-2004 22:56

Thanks for the help WM!

I actually had to remove this line
'#include <vcl.h>'
for the program to compile.
Strange...!!?

thanks again...

« BackwardsOnwards »

Show Forum Drop Down Menu