im a new C++ programmer(or wanna be programmer i guess). I've started through my C++ tutorial book, but Im having difficulties with classes. Its really starting to frustrate me.
can someone take a look at this quickly and tell me why it wont compile? it looks straight to me, but then again, this is one i my first "programs"
#include<iostream>
using namespace std;
enum CHOICE { DrawRect=1, GetArea, GetPerim, ChangeDImensions, Quit};
//Rectangle class declaration
class Rectangle
{
public:
//constructors
Rectangle(int width, int height);
~Rectangle();
//Accessors
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;
};
//class implementation
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);
void DoGetArea(Rectangle);
void DoGetPerim(Rectangle);
int main()
{
//initialize a rectangle to 30, 5
Rectangle theRect(30,5);
int choice = DrawRect;
int fQuit = false;
while (!fQuit)
{
choice= DoMenu();
if (choice < DrawRect || choice > quit)
{
cout << "\nInvalid Choice, please try again.\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 <<"\nNew Width: ";
cin >> newWidth
cout << "\nNew Length ";
cin >> newLength
theRect.SetSize(newWidth, NewHeight);
DoDrawRect(theRect);
break;
case Quit:
fQuit= true;
cout << "\nExiting...\n\n";
break;
default:
cout >> "Error in choice!\n";
fQuit = true;
break;
}
}
return 0;
}
int DoMenu()
{
int choice;
cout << "\n\n** M E N U **\n";
cout << "(1) Draw Rectangle\n";
cout << "(2) Area\n";
cout << "(3) Perimeter\n";
cout << "(4) Resize\n";
cout << "(5) Quit\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 << "Perimeter: "<< theRect.GetPerim() << endl;
}
thanks in advance