Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

New to OOP need help on simple program

cabbaecabbae Member Posts: 2
Well hi my names abraham(abe) and well I'm studying CS at UPR-B and well I'm practicing abit for my quiz on OOP and well I have this program that I have modified from a book that I have. The problem is that it wont compile and can't seem to find the error in the program

[code]
//Implementation file for Rectangle Class
#include "Rectangle.h"
#include

using namespace std;

//**************************************************************
//setLength sets the value of the member variable length. *
//**************************************************************
void Rectangle::setLength(double len)
{
if (len >= 0)
length = len;
else
cout << "ERROR: Invalid Length!
";
}

//**************************************************************
//setWidth sets the value of the member variable width. *
//**************************************************************

void Rectangle::setWidth(double w)
{
if (w >= 0)
width = w;
else
cout << "ERROR: Invalid Width!
";
}

//**************************************************************
//setHeight sets the value of the member variable height. *
//**************************************************************

void Rectangle::setHeight(double h)
{
if (h >= 0)
height = h;
else
cout << "ERROR: Invalid Height!
";
}

//**************************************************************
//getLength returns the value in member variable length. *
//**************************************************************

double Rectangle::getLength() const
{
return length;
}

//**************************************************************
//getWidth returns the value in member variable width. *
//**************************************************************

double Rectangle::getWidth() const
{
return width;
}
//**************************************************************
//getHeight returns the value in member variable height. *
//**************************************************************

double Rectangle::getHeight() const
{
return height;
}

//**************************************************************
//getPerimeter returns the product of length times two plus *
//width times two. *
//**************************************************************

double Rectangle::getPerimeter() const
{
return ((length * 2) + (width * 2));
}

//**************************************************************
//getArea returns the product of length times width. *
//**************************************************************

double Rectangle::getArea() const
{
return (length * width);
}

//**************************************************************
//getVolume returns the product of length times width times *
//height. *
//**************************************************************

double Rectangle::getVolume() const
{
return (length * width * height);
}
[/code]

[code]
//This is the specification file where the class will be defined.
#ifndef RECTANGLE_H
#define RECTANGLE_H

//Rectangle class definition.

class Rectangle
{
public:
void setLength(double);
void setWidth(double);
void setHeight(double);
double getLength() const;
double getWidth() const;
double getHeight() const;
double getPerimeter() const;
double getArea() const;
double getVolume() const;
private:
double length;
double width;
double height;
}

#endif
[/code]

[code]
#include <iostream>
#include "Rectangle.h" // Needed for rectangle class.
sing namespace std;

int main()
{
//local variables
Rectangle box; // Defines an instance of the rectangle's Class.
double rectLength; // Defines a variable for width.
double rectWidth; // Defines a variable for length.
double rectHeight; // Defines a varaible for Height.

//Get the rectangles length, width & height from the user.
cout << "Enter the triangles Length: ";
cin >> rectLength;

cout << "Enter the triangles Width: ";
cin >> rectWidth;

cout << "Enter the triangles Height: ";
cin >> rectHeight;

//Now store the inputed data into the object.
box.setLength(rectLength);
box.setWidth(rectWidth);
box.setHeight(rectHeight);

//Now to display the rectangles data.
cout << "Here is the rectangles data:
";
cout << " Length: " << box.getArea() << endl;
cout << " Width: " << box.getWidth() << endl;
cout << " Perimeter: " << box.getPerimeter() << endl;
cout << " Area: " << box.getArea() << endl;
cout << " Volume: " << box.getVolume() << endl;

system("pause");
return 0;
}
[/code]

I tried using inline functions in the specification file but even that didn't work. Tried taking the #ifndef & #define out and still no luck...

Comments

  • cabbaecabbae Member Posts: 2
    I found the error, after I closed the class with the "}" I forgot to put ";" and in the implementation file it says sing namespace std; when it should be using namespace std;
Sign In or Register to comment.