Like Tree1Likes
  • 1 Post By Elysia

Errors in OOP

This is a discussion on Errors in OOP within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm new to C++ but have to construct a program to solve basic engineering problems. I have several errors ...

  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
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    Hard to say if we "have an idea" when you don't show us the errors.
    Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
    Operating system: Fedora 19 (64-Bit) / Linux 3.11.6-200.fc19 / KDE SC 4.11.2
    Compiler: gcc 4.8.2 with Netbeans IDE 7.4

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,311
    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%.

  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
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    Take a look at lines 18 and 23 (especially 23) in the codebox of your first post.
    Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
    Operating system: Fedora 19 (64-Bit) / Linux 3.11.6-200.fc19 / KDE SC 4.11.2
    Compiler: gcc 4.8.2 with Netbeans IDE 7.4

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    2,587
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    I think the problem is that the OP has no idea on the syntax for classes.
    (HINT: Look it up!)
    King Mir likes this.
    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, 07:14 AM
  2. Why am I getting these errors??
    By maxthecat in forum Windows Programming
    Replies: 3
    Last Post: 02-03-2006, 12:00 PM
  3. Errors!
    By maxorator in forum Windows Programming
    Replies: 3
    Last Post: 12-15-2005, 07: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

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