Let me try again my name is Leonard Norwood Jr.
I'm doing my homework where I have to write a program that outputs the users's weight on different planets.
Should sound familiar
With classes, I need to have one default constuctor that will create an object representing earth. The class as an observer operator that takes a weight on EArth as argument and returns the weight of the planet, Another observer takes the rest of the planets, returns them as string with proper capitalization.
// Header file Planet.h (Specification file)
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;
};
//main project file PnWclient.cpp
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;
return 0;
}
//implementation file Planet.cpp
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;
cin >> SomePlanet;
}
}
}
float Planet::PlanetWt(float NewUserWt) const
{
float NewPLWT;
if (PlanetName == "MERCURY")
NewPLWT = NewUserWt * Mercury;
else if (PlanetName == "VENUS")
NewPLWT = NewUserWt * Venus;
else if (PlanetName == "MOON")
NewPLWT = NewUserWt * Moon;
else if (PlanetName == "MARS")
NewPLWT = NewUserWt * Mars;
else if (PlanetName == "JUPITER")
NewPLWT = NewUserWt * Jupiter;
else if (PlanetName == "SATURN")
NewPLWT = NewUserWt * Saturn;
else if (PlanetName == "URANUS")
NewPLWT = NewUserWt * Uranus;
else if (PlanetName == "NEPTUNE")
NewPLWT = NewUserWt * Neptune;
else if (PlanetName == "PLUTO")
NewPLWT = NewUserWt * Pluto;
return NewPLWT;
}
string Planet::properName()const
{
return PlanetName;
}
This is the error I got from Planet.cpp
[Linker error] undefined reference to `WinMain@16'
ld returned 1 exit status
And these errors are from the PnWclient.cpp
C:\Users\Leonard\AppData\Local\Temp/ccKadaaa.o(.text+0x234):PnWclient.cpp: undefined reference to Planet::Planet(std::string)' C:\Users\Leonard\AppData\Local\Temp/ccKadaaa.o(.text+0x299):PnWclient.cpp: undefined reference to
Planet::PlanetWt(float) const'
C:\Users\Leonard\AppData\Local\Temp/ccKadaaa.o(.text+0x2ae):PnWclient.cpp: undefined reference to `Planet::properName() const'
collect2: ld returned 1 exit status
So what do I do about these linker errors?