Thread: Having issue in running this code

  1. #1
    Registered User
    Join Date
    Oct 2017
    Posts
    6

    Having issue in running this code

    Code:
    
    
    Code:
    //the Elevation.h file 
    #ifndef ELEVATION_H
    #define ELEVATION_H
    
    
    
    
    class Elevation
    {
        public:
            Elevation(int d, int m, int y, int a, int b, int c, int e);
            void movingwater();
            void infiltration();
    
    
        private:
            int firstelevation;
            int secondelevation;
            int thirdelevation;
            int fourthelevation;
            int fifthelevation;
            int sixthelevation;
            int seventhelevation;
    };
    
    
    #endif // ELEVATION_H
    
    
    
    
    
    
    //the Shapiro.h file 
    #ifndef SHAPIRO_H
    #define SHAPIRO_H
    
    
    #include "Elevation.h"
    using namespace std;
    
    
    class Shapiro
    {
        public:
            Elevation be;
            Elevation bo;
            Shapiro();
            Shapiro(Elevation be, Elevation bo);
            void Hapiro();
    
    
        private:
            Elevation altitudeone;
            Elevation altitudetwo;
    };
    
    
    #endif // SHAPIRO_H
    
    
    
    
    
    
    
    
    
    
    //the Elevation.cpp file 
    #include "Elevation.h"
    #include<iostream>
    using namespace std;
    
    
    Elevation::Elevation(int d, int m, int y, int a, int b, int c, int e)
    {
      firstelevation=d;
      secondelevation=m;
      thirdelevation=y;
      fourthelevation=a;
      fifthelevation=b;
      sixthelevation=c;
      seventhelevation=e;
    }
    void Elevation::movingwater(){
    
    
    
    
            cout << " water is removable " << endl;
    
    
    }
    
    
    
    
    void Elevation::infiltration(){
    
    
            cout << " water is not removable " << endl;
    
    
    
    
        }
    
    
    
    
    //the Shapiro.cpp file 
    #include "Shapiro.h"
    #include "Elevation.h"
    #include<iostream>
    using namespace std;
    
    
    Shapiro::Shapiro()
    {
    }
    
    
    Shapiro::Shapiro(Elevation be, Elevation bo)
    :altitudeone(be), altitudetwo(bo)
    {
    
    
    }
    void Shapiro::Hapiro(){
    
    
            if(altitudeone>altitudetwo){
                altitudeone.movingwater();
                int water=10;
                altitudeone-=water;
                altitudetwo+=water;
                cout << " water is removed " << altitudeone << altitudetwo << endl;
                }
             else {
             altitudetwo.infiltration();
                 int water=3;
                 altitudetwo-=water-1;
                cout << " water is infiltrated " << altitudetwo << endl;
    
    
            }}
    
    
    
    
    
    
    //the main.cpp file 
    
    
    #include <iostream>
    #include "Shapiro.h"
    #include "Elevation.h"
    
    
    using namespace std;
    
    
    int main()
    {
        Elevation objone(890, 900, 1000, 1765, 743, 545, 590);
        Elevation objtwo(890, 900, 1000, 1765, 743, 545, 590);
        Shapiro aso (objone, objtwo);
    
    
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,581
    Do you have a specific problem or question about the code you posted?

  3. #3
    Registered User
    Join Date
    Oct 2017
    Posts
    6
    yes the error is:
    ns\src\Shapiro.cpp |6| error: no matching function for call to 'Elevation::Elevation()'|

    I dont know how to use a class working with an operator in another class

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,581
    Look at your Elevation class definition:

    Code:
     
    class Elevation
    {
        public:
            Elevation(int d, int m, int y, int a, int b, int c, int e);
    ...
    Now look at the line in question:

    Code:
     
    Shapiro::Shapiro(Elevation be, Elevation bo)
    ...
    Where have you defined an Elevation constructor that takes no arguments?

  5. #5
    Registered User
    Join Date
    Oct 2017
    Posts
    6
    Here is the reason that I have written seven int int elevation class; I want the user to enter for example seven elevation to the program and then let the program to compare two by two and if the first elevation that is entered is bigger than the second one so I want the program to move the water otherwise i want it to infiltrate the water by using infiltration (or Evaporation).

    Because, this seems difficult to me to add another condition for the program to test (like test if the temperature is more than zero do Evaporation otherwise do Infiltration), so I ignored to add another function (named Evaporation) to let the program to evaporate the water in case of having bigger number entered in the second place and also having temperature more than zero.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,581
    Please post the complete error messages, all of them, exactly as they appear in your development environment.

    If you create a constructor with multiple arguments then the compiler will no longer supply the default no argument constructor and you will always need to use that multiple argument constructor.

  7. #7
    Registered User
    Join Date
    Oct 2017
    Posts
    6
    C:\Users\sedaei\Desktop\New folder (4)\new\Shapiro.cpp|7|error: no matching function for call to 'Elevation::Elevation()'|


    C:\Users\sedaei\Desktop\New folder (4)\new\Shapiro.cpp|21|error: no match for 'operator>' (operand types are 'Elevation' and 'Elevation')|


    C:\Users\sedaei\Desktop\New folder (4)\new\Shapiro.cpp|24|error: no match for 'operator-=' (operand types are 'Elevation' and 'int')|


    C:\Users\sedaei\Desktop\New folder (4)\new\Shapiro.cpp|26|error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'Elevation')|

  8. #8
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    830
    There are several issues with your code that aren't easily solved because they require syntax that you're likely not familiar with yet.

    I think you should start by comparing two ranges of numbers and make sure that works. After that you can think about classes.
    Code:
    // How would you compare these to determine which date is later?
    int date1[] = {2000, 3, 8};
    int date2[] = {2000, 9, 2};
    
    // How about these two?
    struct date {
        int year;
        int month;
        int day;
    };
    
    date d1 {2010, 8, 2};
    date d2 {2012, 5, 17};

  9. #9
    Registered User
    Join Date
    Oct 2017
    Posts
    6
    I have tried this but it makes errors;
    Code:
    #include <iostream>
    #include <string>
    #include<cstdlib>
    #include <cmath>
    
    
    using namespace std;
    
    
    void later (int y1, int m1, int d1, int y2, int m2, int d2);
    {
        if (int y1 > int y2){
    
    
            return true;
        } else {
           if (int m1> int m2){
            return true;
    
    
           }else {if (int d1> int d2){
            return true;
           }
           else
            return false;
    
    
        }
    }}
    int main()
    {
        int y1=2000, m1=3, d1=8;
        int y2=2000, m2=9, d2=2;
    
    
        cout << later (int y1, int m1, int d1, int y2, int m2, int d2) << endl;
        ireturn 0;
    
    
        };
    
    
    }
    Last edited by Nazila Sedaei; 11-01-2017 at 01:45 PM.

  10. #10
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    830
    Sorry, I stayed away from the forum while it was so terribly slow (fixed now it seems).

    How did you arrive at using classes already, without getting familiar with simpler code first? My suggestion would be to restart from the beginning (I found learncpp.com very helpful myself), and go more slowly, step-by-step until you have a solid grasp of the syntax/concepts. That's the best way to learn and you'll feel more confident in what you're doing.

    We'll gladly help you if you get stuck anywhere, but this forum is not a replacement for a book or teacher.

  11. #11
    Registered User
    Join Date
    Nov 2017
    Posts
    3
    Please highlight the specific issue you are having and the error message displayed. That's the only way to get help
    Last edited by Salem; 11-12-2017 at 02:25 AM. Reason: spammy links deleted

  12. #12
    Registered User
    Join Date
    May 2009
    Posts
    3,970
    Brush up on if statements and how to call/invoke a function.

    Hint: Neither of those normally use the "int" keyword.

    Tim S.
    Last edited by stahta01; 11-12-2017 at 05:44 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code now running but......
    By BenAber in forum C Programming
    Replies: 1
    Last Post: 04-27-2014, 08:42 AM
  2. problem running code
    By michaelp in forum C++ Programming
    Replies: 4
    Last Post: 02-19-2008, 08:52 PM
  3. Running Exe in C++ Code.
    By Ti22 in forum C++ Programming
    Replies: 5
    Last Post: 03-23-2006, 01:29 PM
  4. running code EXACTLY once
    By Trauts in forum C++ Programming
    Replies: 12
    Last Post: 07-11-2003, 12:24 PM

Tags for this Thread