nekoleon64 0 Newbie Poster

// Planet.h "Header file"

    #include <string>

    using namespace std;


class Planet
{
      public:
             // Constructors
      Planet();
      // Post: your weight and the Planet's weight set to Earth.
      Planet(string);
      // Takes in string value and sets it to planet name, or defaults to earth if not valid

      float PlanetWt(float) const; //observer, uses earth weight as argument and returns weight on chosen planet

      string properName() const; //observer, properly displays name of planet name      

      private:
      string PlanetName;
};   `Inline Code Example Here` 

My implementation file "Planet.cpp"

include <iostream>
include "Planet.h"
using namespace std;

const float Mercury = 0.4155f;
      const float Venus = 0.8975f;    
      const float Earth = 1.0f;    
      const float Moon = 0.166f;    
      const float Mars = 0.3507f;    
      const float Jupiter = 2.5374f;    
      const float Saturn = 1.0677f;    
      const float Uranus = 0.8947f;    
      const float Neptune = 1.1794f;    
      const float Pluto = 0.0899f;

Planet::Planet()
{
          PlanetName = "Earth";
}

Planet::Planet(string SomePlanet)
{
       char chPlanetLet;
       string NewPlanet;
       bool DataOK
       int i;
       int strLength;

       strLength = SomePlanet.length();

       for (i = 0; i < strLength; i++)
       {
           chPlanetLet = toupper(SomePlanet[i]);
           NewPlanet += chPlanetLet;
       }

       while (!DataOK)
       {
             if(NewPlanet = "MERCURY")
             {
                 PlanetName = "Mercury";
                 DataOk = 1;
             }
             else if (NewPlanet == "VENUS")
             {
                  PlanetName = "Venus";
                  DataOK = true;
             }
             else if (NewPlanet == "MOON"
             {
                  PlanetName = "Moon";
                  DataOK = true;
             }
             else if (NewPlanet == "MARS")
             {
                  PlanetName = "Mars";
                  DataOK = true;
             }
             else if (NewPlanet == "JUPITER")
             {
                  PlanetName = "Jupiter";
                  DataOK = true;
             }
             else if (NewPlanet == "SATURN")
             {
                  PlanetName = "Saturn";
                  DataOK = true;
             }
             else if (NewPlanet == "URANUS")
             {
                  PlanetName = "Uranus";
                  DataOK = true;
             }
             else if (NewPlanet == "NEPTUNE")
             {
                  PlanetName = "Neptune";
                  DataOK = true;
             }
             else if (NewPlanet == "PLUTO")
             {
                  PlanetName = "Neptune";
                  DataOK = true;
             }
             else
             {
                 cout << "Invalid planet name, please enter the correct spelling for the planet..." << endl;
             }
       }
}

float Planet::PlanetWt(float NewPLWT)
{
     float NewPLWT;

     if (PlanetName == "MERCURY")
        NewPLWT = fltSomePLWT * fltMercury;
     else if (PlanetName == "VENUS")
          NewPLWT = fltSomePLWT * fltVenus;
     else if (PlanetName == "MOON")
          NewPLWT = fltSomePLWT * fltMoon;
     else if (PlanetName == "MARS")
          NewPLWT = fltSomePLWT * fltMars;
     else if (PlanetName == "JUPITER")
          NewPLWT = fltSomePLWT * fltJupiter;
     else if (PlanetName == "SATURN")
          NewPLWT = fltSomePLWT * fltSaturn;
     else if (PlanetName == "URANUS")
          NewPLWT = fltSomePLWT * fltUranus;
     else if (PlanetName == "NEPTUNE")
          NewPLWT = fltSomePLWT * fltNeptune;
    else if (PlanetName == "PLUTO")
          NewPLWT = fltSomePLWT * fltPluto;

    return NewPLWT;
}

string Planet::properName()const
{
       return PlanetName;
} `Inline Code Example Here` 

And my driver client program PnWclient.cpp

include "Planet.h"
include <iostream>
using namespace std;

int main()
{
    float UserWeight;
    float NewUserWt;
    string UserPN;
    string NewUserPN;

    cout << "Please enter your earth weight in pounds (e.g. 155)..." << endl;
    cin >> UserWeight;

    cout << "\nEnter a planet name to see what your weight would be there..." << endl;
    cin >> UserPN;

    Planet SomePlanet(UserPN); // calculate new object with user specified planet name

    NewUserWt = SomePlanet.PlanetWt(UserWeight);
    // calculates users weight in chosen planet

    NewUserPN = SomePlanet.properName();
    // stores properly typed planet name

    cout << endl << endl << "Your weight on " << UserPN << " would be " << NewUserWt << endl;
    _getch();

    return 0;
} `Inline Code Example Here` 

This is what I'm working on, I have to do the same program I did last time but this time in class, I have a slight problem though here's are some errors. I'm almost done, but I sought out a few errors that I had. I need to finish this one so I won't take to long past its due date. Read Carefully

In file included from J:\C++ folder\Planet.cpp:2:
J:\C++ folder\/Planet.h:9: error: field string' has incomplete type J:\C++ folder\/Planet.h:14: error:string' does not name a type
J:\C++ folder\/Planet.h:17: error: string' does not name a type J:\C++ folder\Planet.cpp:16: error:Planet' has not been declared
J:\C++ folder\Planet.cpp:17: error: ISO C++ forbids declaration of Planet' with no type J:\C++ folder\Planet.cpp: In functionint Planet()':
J:\C++ folder\Planet.cpp:18: error: PlanetName' undeclared (first use this function) J:\C++ folder\Planet.cpp:18: error: (Each undeclared identifier is reported only once for each function it appears in.) J:\C++ folder\Planet.cpp: At global scope: J:\C++ folder\Planet.cpp:21: error:Planet' is not a class or namespace
J:\C++ folder\Planet.cpp:22: error: ISO C++ forbids declaration of Planet' with no type J:\C++ folder\Planet.cpp: In functionint Planet(std::string)':
J:\C++ folder\Planet.cpp:25: error: expected primary-expression before "bool"
J:\C++ folder\Planet.cpp:25: error: expected ;' before "bool" J:\C++ folder\Planet.cpp:31: error:i' undeclared (first use this function)
J:\C++ folder\Planet.cpp:37: error: DataOK' undeclared (first use this function) J:\C++ folder\Planet.cpp:39: error: could not convert(&NewPlanet)->std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const char*)"MERCURY"))' to bool' J:\C++ folder\Planet.cpp:41: error:PlanetName' undeclared (first use this function)
J:\C++ folder\Planet.cpp:42: error: DataOk' undeclared (first use this function) J:\C++ folder\Planet.cpp:50: error: expected)' before '{' token
J:\C++ folder\Planet.cpp:88: error: expected primary-expression before '}' token
J:\C++ folder\Planet.cpp:88: error: expected ;' before '}' token J:\C++ folder\Planet.cpp: At global scope: J:\C++ folder\Planet.cpp:91: error:Planet' is not a class or namespace
J:\C++ folder\Planet.cpp: In function float PlanetWt(float)': J:\C++ folder\Planet.cpp:93: error: declaration of 'float NewPLWT' shadows a parameter J:\C++ folder\Planet.cpp:95: error:PlanetName' undeclared (first use this function)
J:\C++ folder\Planet.cpp:96: error: fltSomePLWT' undeclared (first use this function) J:\C++ folder\Planet.cpp:96: error:fltMercury' undeclared (first use this function)
J:\C++ folder\Planet.cpp:98: error: fltVenus' undeclared (first use this function) J:\C++ folder\Planet.cpp:100: error:fltMoon' undeclared (first use this function)
J:\C++ folder\Planet.cpp:102: error: fltMars' undeclared (first use this function) J:\C++ folder\Planet.cpp:104: error:fltJupiter' undeclared (first use this function)
J:\C++ folder\Planet.cpp:106: error: fltSaturn' undeclared (first use this function) J:\C++ folder\Planet.cpp:108: error:fltUranus' undeclared (first use this function)
J:\C++ folder\Planet.cpp:110: error: fltNeptune' undeclared (first use this function) J:\C++ folder\Planet.cpp:112: error:fltPluto' undeclared (first use this function)
J:\C++ folder\Planet.cpp: At global scope:
J:\C++ folder\Planet.cpp:117: error: Planet' is not a class or namespace J:\C++ folder\Planet.cpp:118: error: non-member functionstd::string properName()' cannot have const' method qualifier J:\C++ folder\Planet.cpp: In functionstd::string properName()':
J:\C++ folder\Planet.cpp:119: error: `PlanetName' undeclared (first use this function)

Execution terminated

And the same thing for my PnWclient.

In file included from J:\C++ folder\PnWclient.cpp:1:
J:\C++ folder\/Planet.h:9: error: field string' has incomplete type J:\C++ folder\/Planet.h:14: error:string' does not name a type
J:\C++ folder\/Planet.h:17: error: string' does not name a type J:\C++ folder\PnWclient.cpp: In functionint main()':
J:\C++ folder\PnWclient.cpp:19: error: Planet' undeclared (first use this function) J:\C++ folder\PnWclient.cpp:19: error: (Each undeclared identifier is reported only once for each function it appears in.) J:\C++ folder\PnWclient.cpp:19: error: expected;' before "SomePlanet"
J:\C++ folder\PnWclient.cpp:21: error: SomePlanet' undeclared (first use this function) J:\C++ folder\PnWclient.cpp:28: error:_getch' undeclared (first use this function)

Execution terminated

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.