Basically, I need a list of planets, functions that willprompt me to add, remove
ID: 3618707 • Letter: B
Question
Basically, I need a list of planets, functions that willprompt me to add, remove, etc. Also the list should be sorted alphabetically.A. add planet (prompt for a name, mass, diameter or radius, [type1for planet,2 for planetoids, 3 for other], calculate the surfacearea, density, g)
B. Remove planet (prompt for a name)
C. find planet (prompt for a name, mass, diameter or radius,calculate the surface area, density, g)
D. list all (alphabetical order, assume they are spheres)
E. list planets (alphabetical order, assume they arespheres)
F. list planetoids (pluto) (alphabetical order, assume theyare spheres)
G. list other
It would be good if classess (private and public) will beincluded
Thanks to everyone in advance! :) Basically, I need a list of planets, functions that willprompt me to add, remove, etc. Also the list should be sorted alphabetically.
B. Remove planet (prompt for a name) C. find planet (prompt for a name, mass, diameter or radius,calculate the surface area, density, g) D. list all (alphabetical order, assume they are spheres) E. list planets (alphabetical order, assume they arespheres) F. list planetoids (pluto) (alphabetical order, assume theyare spheres) G. list other
It would be good if classess (private and public) will beincluded
Thanks to everyone in advance! :)
Explanation / Answer
public:
planetObjects()
{
//name = " ";
mass = 0.0;
radius = 0.0;
type = -1;
}
void setPlanetName()
{
cout<<" Please enter the name of the Planet : ";
cin>>name;
}
char* getPlantName()
{
return name;
}
void setMass()
{
cout<<" Please enter the mass : ";
cin>>mass;
}
float getMass()
{
return mass;
}
void setRadius()
{
cout<<" Please enter the Radius : ";
cin>>radius;
}
float getRadius()
{
return radius;
}
void setPlanetType()
{
cout<<" Please enter the type[type 1for planet,2 for planetoids, 3 for other] : ";
cin>>type;
}
int getPlanetType()
{
return type;
}
};
class PlanetOperations
{
private:
planetObjects objPlanets[25];
int planetsCount;
public:
PlanetOperations()
{
planetsCount = 0;
}
void addPlanet()
{
planetObjects objPlanet;
objPlanet.setPlanetName();
objPlanet.setMass();
objPlanet.setRadius();
objPlanet.setPlanetType();
objPlanets[planetsCount] = objPlanet;
planetsCount++;
sort();
cout<<" Planet added successfully!!!! ";
}
void removePlanet(char* planetName)
{
char* pName;
int nFound = -1;
planetObjects tmpPlanets[25];
int tmpCount = 0;
for(int i=0;i<planetsCount;i++)
{
pName = objPlanets[i].getPlantName();
if(strcmp(pName,planetName) == 0)
{
nFound = 1;
}
else
{
tmpPlanets[tmpCount] = objPlanets[i];
tmpCount++;
}
}
for(int j=0;j<tmpCount;j++)
{
objPlanets[j] = tmpPlanets[j];
}
planetsCount = tmpCount;
if(nFound != 1)
cout<<" Planet "<<planetName<<" Not found";
}
void findPlanet(char* name)
{
char* pName;
int nFound =-1;
float tmpRadius = 0;
float tmpVolume =0;
float tmpDensity = 0;
for(int i=0;i<planetsCount;i++)
{
pName = objPlanets[i].getPlantName();
if(strcmp(pName,name) == 0)
{
cout<<" Planet "<<name<<" found at poistion "<<(i+1);
tmpRadius = objPlanets[i].getRadius();
tmpVolume = (4/3) * 3.142 * tmpRadius * tmpRadius * tmpRadius;
tmpDensity = objPlanets[i].getMass()/tmpVolume;
cout<<" Planet Details : ";
cout<<" Name : "<<objPlanets[i].getPlantName();
cout<<" Mass : "<<objPlanets[i].getMass();
cout<<" Radius : "<<tmpRadius;
cout<<" Type : "<<objPlanets[i].getPlanetType();
cout<<" Surface Area : "<< ( 4 * 3.142 * tmpRadius * tmpRadius);
cout<<" Desnsity : "<< tmpDensity;
cout<<" ";
nFound = 1;
}
}
if(nFound != 1)
cout<<" Planet "<<name<<" Not Found";
}
void listDisplaySpecific(int Option)
{
float tmpRadius = 0;
float tmpVolume =0;
float tmpDensity = 0.0;
for(int i=0;i<planetsCount;i++)
{
int plantType = objPlanets[i].getPlanetType();
if(plantType == Option)
{
tmpRadius = objPlanets[i].getRadius();
tmpVolume = (4/3) * 3.142 * tmpRadius * tmpRadius * tmpRadius;
tmpDensity = objPlanets[i].getMass()/tmpVolume;
cout<<" Planet "<<(i+1)<<" : ";
cout<<" Name : "<<objPlanets[i].getPlantName();
cout<<" Mass &n
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.