Rectangle tangle help???

This is a discussion on Rectangle tangle help??? within the C++ Programming forums, part of the General Programming Boards category; Hello all! I am in a beginner c++ class and have been struggling with this problem. I get a lot ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    23

    Rectangle tangle help???

    Hello all! I am in a beginner c++ class and have been struggling with this problem. I get a lot of error warnings but don't know what to do to fix it. I tried everything that I can think of and am now just guessing but without any success. Hope someone can suggest a strategy. Thanks, as always in advance.

    The most recent error warning.....

    error C2143: syntax error : missing ';' before 'tag::id'

    fatal error C1004: unexpected end of file found
    Error executing cl.exe.

    Code:
    #include <iostream>
    
    using namespace std;
    
    class Rectangle
    {
    public:
    	Rectangle(double = 1, double = 1);
    	double setlength( double l );
    	double setwidth( double w );
    	
    	double getlength();
    	double getwidth();
    
    	void area();
    	void perimeter();
    
    private:
    	double length;
    	double width;
    };
    
    Rectangle::Rectangle( double l, double w )
    
    Rectangle::setlength( double l )
    {
    	length = ( l >= 0.0 && l <= 20.0 ) ? l = 0;
    }
    
    Rectangle::setwidth( double w )
    {
    	width = ( w >= 0.0 && w <= 20.0 ) ? w = 0;
    }
    
    void Rectangle::area()
    {
    	return ( l * w );
    }
    
    void Rectangle::perimeter()
    {
    	return ( 2 * ( l * w ));
    }
    
    int main()
    {
    Rectangle rect( 4,  5 );
    
    	cout << " The area of the rectangle is " << rect.area() << endl;
    	cout << " The perimeter of the rectangle is " << rect.perimeter() << endl;
    
    	return 0;
    }
    Last edited by bluenoser; 03-12-2003 at 09:25 PM.

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >Rectangle::Rectangle( double l, double w )
    ...
    >Rectangle(double = 1, double = 1);

    well, for starters, this constructor is missing a method body which cannot be initialized this way

    here's a hint..

    Code:
    Rectangle( double l, double w )
    {
         // initialize vars here
    }

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >Rectangle::Rectangle( double l, double w )

    You should have some code for that. That's what's causing the problem, I think.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    23
    Just an update folks, I've tried a few different takes on your suggestions and now the least I get is 10 errors. Was I missing any tags? When would a ',' preceed a ';'. That is one of the errors that repeatedly occurs. Thanks all!!

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Possibly you were confused so I cleared it up a bit. I can't find any tag::id. Anyways thats what you should do to make your thing compile.

    Code:
    class Rectangle
    {
    public:
    	Rectangle( double l, double w );
    	double setlength( double l );
    	double setwidth( double w );
    	
    	double getlength();
    	double getwidth();
    
    	void area();
    	void perimeter();
    
    private:
    	double length;
    	double width;
    };
    
    Rectangle::Rectangle( double l, double w )
    {
    	// you're code here to make the rectangle
    }

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    23
    Hey, Thanks everyone for the help. I still don't have it working although it's not from lack of trying and I'm off to Toronto on a 6:00 a.m. flight until Monday so I'll give it thought all week-end. I am glad though that the rest of my code looks ok to you since I am not 100% sure yet about all the syntax. This forum helped me through my C class and I am sure glad that you guys ( 'generic guys = inclusive = and gals' ) are around and willing to assist. Thanks again .....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rectangle class
    By blackant in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2009, 08:33 AM
  2. segmetation fault (reading and writing file in c)
    By tasosa in forum C Programming
    Replies: 5
    Last Post: 04-13-2009, 06:04 AM
  3. GUI structure in C
    By officedog in forum C Programming
    Replies: 36
    Last Post: 11-19-2008, 01:33 PM
  4. Point passed rectangle...
    By Hunter2 in forum Game Programming
    Replies: 15
    Last Post: 10-10-2003, 09:57 AM
  5. Collision detection algorithm
    By Hannwaas in forum Game Programming
    Replies: 5
    Last Post: 11-30-2001, 12:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21