Thread: Errors in OOP

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    2

    Errors in OOP

    Hi, I'm new to C++ but have to construct a program to solve basic engineering problems.

    I have several errors in my code and have no idea how to solve them - any ideas?

    Thanks

    Code:
    #include <iostream>
    #include <string>
    #include <cmath>
    
    
    using namespace std;
    class Second_Moment_Area
    {
    private:
        float secondMomentOfArea;
        float base;
        float depth;
    
    
    public:
    
    
        Second_Moment_Area( float paraSecondMomentOfArea, float paraBase, float paraDepth)  // normal constructor
        {
            secondMomentOfArea = paraSecondMomentOfArea; base = paraBase; depth = paraDepth;
        }
        Second_Moment_Area() {  secondMomentOfArea = base = depth = 0.0;}
        Second_Moment_Area(float secondMomentOfArea, float base, float depth)
    {
        void setSecondMomentOfArea (float paraSecondMomentOfArea);
        {
            this->secondMomentOfArea = secondMomentOfArea;
        }
    
    
        void setBase (float paraBase);
        {
        this->base = base;
        }
        void setDepth (float paraDepth);
        {
        this->depth = depth;
        }
        void calculateI ();
        {
            this->secondMomentOfArea = ((this->base * this->depth * this->depth * this->depth) / 12);
        }
    {
        void print  ()
    Second_Moment_Area(float paraSecondMomentOfArea)
    ~Second_Moment_Area
            cout<< "This result is   "<< secondMomentOfArea << endl;
        }
    };
    
    
    int main()
    {
        Second_Moment_Area secondMomentOfArea;
        secondMomentOfArea.setSecondMomentOfArea();
        Second_Moment_Area.calculateI();
        Second_Moment_Area.print();
        return 0;
    }
        };

  2. #2
    spaghetticode
    Guest
    Hard to say if we "have an idea" when you don't show us the errors.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    I'm not going through all of the errors in your code. There are simply too many.

    Instead, I'll point you to an approach you should always use when you get a slew of error messages from your compile.


    The basic method is: scroll back and look at the FIRST error message emitted. That will be located towards the top of your screen or window (although you may have to scroll back). Solve the coding problem which causes that error message, first.

    Don't try to work through the errors by looking at the last one reported (typically at the bottom of your screen or window). The first errors in your code tend to result in clear(er) error messages. But the errors confuse the compiler, so subsequent error messages may be misleading.

    If your screen or window does not support scrolling back, find a way to capture the error messages to a file. Then look at the first error messages in that file, not the first.

    You need to work out how to understand your compiler's error messages on your own. It is a fundamental skill.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    2
    The first error is in line 20 Second_Moment_Area (invalid redeclaration of member function)

    Then in the main function
    line 50 Second_Moment_Area has no member setSecondMomentOfArea
    the same is for calculateI in line 51 and print in line 52.

    Any help is much appreciated!

  5. #5
    spaghetticode
    Guest
    Take a look at lines 18 and 23 (especially 23) in the codebox of your first post.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by dennis.cpp View Post
    Take a look at lines 18 and 23 (especially 23) in the codebox of your first post.

    You problem looks like too many ";" and not enough "}" to this C programmer.

    Tim S.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I think the problem is that the OP has no idea on the syntax for classes.
    (HINT: Look it up!)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. errors
    By sniper22 in forum C++ Programming
    Replies: 3
    Last Post: 03-06-2006, 08:14 AM
  2. Why am I getting these errors??
    By maxthecat in forum Windows Programming
    Replies: 3
    Last Post: 02-03-2006, 01:00 PM
  3. Errors!
    By maxorator in forum Windows Programming
    Replies: 3
    Last Post: 12-15-2005, 08:59 PM
  4. errors.. errrors.. more errors
    By Klinerr1 in forum C++ Programming
    Replies: 17
    Last Post: 07-23-2002, 08:43 PM
  5. help with errors...
    By Gamma in forum C++ Programming
    Replies: 4
    Last Post: 04-13-2002, 07:11 PM