Thread: Functions and Classes - What did I do wrong?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    2
    Ok, this is where I'm at now:

    Code:
    //this is my coding
    
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    class rectangle {
        private:
        double Width, Lenght;  
      public:
    	  rectangle () {Width = 1.0, Lenght = 1.0;}; 
        rectangle (double,double);
        double area (void) const {return (Width*Lenght);}
        double perimeter (void) const {return (Lenght*2 + Width*2);}
        void setWidth(double x);
        void setLenght(double y);
        double getWidth() const;
        double getLenght() const;
    
    	
    };
    
    void rectangle::setWidth(double x;)
    {
        if ((x < 0.0;) || (x > 20.0;))
    	{
    		Width = 1.0;
    	}
    	Width = x;
    
    
    }
    
    void rectangle::setLenght(double y;)
    {
        if ((y < 0.0;) || (y > 20.0;))
    	{
    		Lenght = 1.0;
    	}
    Lenght = y;
    
    }
    
    int rectangle::getWidth()
    {
       return Width;
    
    }
    
    int rectangle::getLenght()
    {
       return Lenght;
    
    
    }
    
    
    //this is what was given
    int main()
    {
    	rectangle a, b(4.0,5.0), c(67.0, 888.0);
    	cout<< setiosflags(ios::fixed | ios::showpoint);
    	cout<<setprecision(1);
    
    	cout<<"a: length = " << a.getLenght() << "; width = " << a.getWidth()
                                                << "area = " << a.area() <<'\n';
    
    	cout<< "b: length = " << b.getLenght() << "; width = " << b.getWidth() 
                                                         << "; perimeter = " << b.perimeter()
                                                         << "; area = " << b.area() << '\n';
    
    	cout << "c: length = " << c.getLenght() << "; width = " << c.getWidth() 
                                                          << "; perimeter =" << c.perimeter() 
                                                          << "; area = " << c.area() << endl;
    
    	return 0;
    }


    ERRORS
    C:\Documents and Settings\Chris\Cpp1.cpp(24) : error C2143: syntax error : missing ')' before ';'
    C:\Documents and Settings\Chris\Cpp1.cpp(24) : error C2059: syntax error : ')'
    C:\Documents and Settings\Chris\Cpp1.cpp(25) : error C2447: missing function header (old-style formal list?)
    C:\Documents and Settings\Chris\Cpp1.cpp(35) : error C2143: syntax error : missing ')' before ';'
    C:\Documents and Settings\Chris\Cpp1.cpp(35) : error C2059: syntax error : ')'
    C:\Documents and Settings\Chris\Cpp1.cpp(36) : error C2447: missing function header (old-style formal list?)
    C:\Documents and Settings\Chris\Cpp1.cpp(46) : error C2511: 'getWidth' : overloaded member function 'int (void)' not found in 'rectangle'
    C:\Documents and Settings\Chris\Cpp1.cpp(8) : see declaration of 'rectangle'
    C:\Documents and Settings\Chris\Cpp1.cpp(57) : error C2511: 'getLenght' : overloaded member function 'int (void)' not found in 'rectangle'
    C:\Documents and Settings\Chris\Cpp1.cpp(8) : see declaration of 'rectangle'

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    void rectangle::setWidth(double x;)
    {
        ...
    }
    
    void rectangle::setLength(double y;)
    {
        ...
    }
    And you can also remove those semicolons.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Look closer at your logic in the setWidth and setHeight functions, too.
    You're only born perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes being able to use other classes functions
    By rainmanddw in forum C++ Programming
    Replies: 6
    Last Post: 01-29-2006, 11:19 AM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  3. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  4. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM
  5. help with classes and member functions
    By syner in forum C++ Programming
    Replies: 4
    Last Post: 07-19-2002, 08:45 PM