I went through the chapter of Classes and I though i had understood this pretty well, with class, private, public, constructors, destructors ... So I tried to do a program from an exercise that seemed simple, but It compiling a bunch of errors, if anyone could put me on the right track to understand this, it would be great.
the exercise is:
This is what I have done as far as the program goes:Define a class called Plot that has private members of length and width. Include a constructor and a public function that calculates the area and the length of the boundary of the field. Use public functions in a program that computes and displays the area and the length of the boundary of the plot where the length and width are 7 and 9 respectively. Hint: The length of the boundary is 2 * (l + w).
These are the error codes I'm getting:Code:#include <iostream> #include <stdlib.h> using namespace std; class Plot { public: double setlength( double l ); double setwidth( double w ); double getlength(); double getwidth(); void area(); void perimeter(); private: double length; double width; }; Plot::Plot(double , double ) { length = l; width = w; } Plot::setlength() { length = ( l >= 0.0 && l <= 7.0 ) ? l = 0; } Plot::setwidth() { width = ( w >= 0.0 && w <= 9.0 ) ? w = 0; } void Plot::area() { return (l * w); } void Plot::perimeter() { return ( 2 * ( l + w )); } int main() { Plot rect( 7, 9 ); cout << " The area of the rectangle is " << Plot.area() << endl; cout << " The perimeter of the rectangle is " << Plot.perimeter() << endl; return 0; }
If anyone can help me understand what I'm doing wrong I would really appreciate it.Code:(27) : error C2511: 'Plot::Plot(double,double)' : overloaded member function not found in 'Plot' (11) : see declaration of 'Plot' (32) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (32) : error C2511: 'int Plot::setlength(void)' : overloaded member function not found in 'Plot' (11) : see declaration of 'Plot' (36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (36) : error C2511: 'int Plot::setwidth(void)' : overloaded member function not found in 'Plot' (11) : see declaration of 'Plot' (41) : error C2065: 'l' : undeclared identifier (41) : error C2065: 'w' : undeclared identifier (50) : error C2661: 'Plot::Plot' : no overloaded function takes 2 arguments (51) : warning C4832: token '.' is illegal after UDT 'Plot' (11) : see declaration of 'Plot' (51) : error C2275: 'Plot' : illegal use of this type as an expression (11) : see declaration of 'Plot' (52) : warning C4832: token '.' is illegal after UDT 'Plot' (11) : see declaration of 'Plot' (52) : error C2275: 'Plot' : illegal use of this type as an expression (11) : see declaration of 'Plot'
thanks.



LinkBack URL
About LinkBacks


