Hey, all! I am in my first programming class and have done pretty well thus far. I am running into error messages and cannot figure out where I went wrong - please help if you can. Thanks in advance.
This is the program I have developed:
Code:
//Program that defines a class called Plot that contains private members.
#include <iostream>
#include <stdlib.h>
using namespace std;
class Plot
{
public:
Plot(double,double);
void setlength (double l);
void setwidth (double w);
double getlength();
double getwidth();
float area();
float perimeter();
private:
double length;
double width;
};
Plot::Plot(double,double)
{
length = l;
width = w;
}
void Plot::setlength(double l)
{
length = (l >= 0.0 && l <= 7.0)?l = 0;
}
void Plot::setwidth(double w)
{
width = (w >= 0.0 && w <= 9.0)?w = 0;
}
float Plot::area()
{
return (l * w);
}
float Plot::perimeter()
{
return (2*(l + w));
}
int main()
{
Plot rect(7,9);
cout<<"The area of the retangle is "<<rect.area()<<endl;
cout<<"The perimeter of the rectangle is "<<rect.perimeter()<<endl;
return 0;
}
Here are the error messaged I am getting:
Code:
error C2065: 'l' : undeclared identifier
error C2065: 'w' : undeclared identifier
error C2143: syntax error : missing ',' before ';'
error C2143: syntax error : missing ',' before ';'
Where the heck would I be missing commas? I have tried to move what I though was the identifier around, but it just causes more chaos. Anything to help is appreciated!