Durban thanks I've made the changes but I'm still getting a bunch of errors that I don't understand. If anyone can give a hand to figure this out it would be great.
Code:
#include <iostream>
#include <stdlib.h>
using namespace std;
class Plot
{
public:
Plot(double, double); //ADDED LINE
void setlength( double l ); //SHOULDNT RETURN DOUBLE
void setwidth( double w ); // SAME THING HERE VOID
double getlength();
double getwidth();
float area(); //RETURN VALUE CHANGED
float perimeter(); //SAME THING
private:
double length;
double width;
};
Plot::Plot(double , double )
{
length = l;
width = w;
}
void Plot::setlength() //ALWAYS PUT THE RETURN TYPE!!!
{
length = ( l >= 0.0 && l <= 7.0 ) ? l = 0;
}
void Plot::setwidth() //RETURN TYPE AGAIN!
{
width = ( w >= 0.0 && w <= 9.0 ) ? w = 0;
}
float Plot::area() //YOUR RETURNING WHY WAS THIS VOID
{
return (l * w);
}
float Plot::perimeter() //SAME THING HERE
{
return ( 2 * ( l + w ));
}
int main()
{
Plot rect = new Plot(7,9); //INSTANTIATE PLOT
cout << " The area of the rectangle is " << Plot.area() << endl;
cout << " The perimeter of the rectangle is " << Plot.perimeter() << endl; //YOU CANT CALL CLASS VARIABLES THAT DONT EXIST, USE THE VARIABLE
return 0;
}
Here are the errors I get:
Code:
(30) : error C2065: 'l' : undeclared identifier
(31) : error C2065: 'w' : undeclared identifier
(35) : error C2511: 'void Plot::setlength(void)' : overloaded member function not found in 'Plot'
(11) : see declaration of 'Plot'
(39) : error C2511: 'void Plot::setwidth(void)' : overloaded member function not found in 'Plot'
(11) : see declaration of 'Plot'
(53) : error C2440: 'initializing' : cannot convert from 'Plot *' to 'Plot'
No constructor could take the source type, or constructor overload resolution was ambiguous
(54) : warning C4832: token '.' is illegal after UDT 'Plot'
(11) : see declaration of 'Plot'
(54) : error C2275: 'Plot' : illegal use of this type as an expression
(11) : see declaration of 'Plot'
(55) : warning C4832: token '.' is illegal after UDT 'Plot'
(11) : see declaration of 'Plot'
(55) : error C2275: 'Plot' : illegal use of this type as an expression
(11) : see declaration of 'Plot'
Thanks.