i am writing a program to list the 8 planets, then you select which planet you want. it gives you the mass of the planet, the radius, then you use the mass and radius of the planet to find the surface area(sphere formula) and the density of the planet. along with those options, you have to add and delete a planet from the list and then sort them alphabetically. All i am having trouble with is the adding and deleting part.
the code the adding and deleting from the list would go in cases 9 and 10.
heres my code as of this point.
the code the adding and deleting from the list would go in cases 9 and 10.
heres my code as of this point.
Code:
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
void print(const std::string& item)
{
std::cout << item << std::endl;
std::set<std::string> sortedItems;}
int main()
{
int choice;
bool gameOn = true;
while (gameOn != false){
cout << "*******************************\n";
cout << " 1 - Murcury\n";
cout << " 2 - Venus\n";
cout << " 3 - Earth\n";
cout << " 4 - Mars\n";
cout << " 5 - Jupiter\n";
cout << " 6 - Saturn\n";
cout << " 7 - Uranus\n";
cout << " 8 - Neptune\n";
cout << " 9 - Add A Planet\n";
cout << " 10 - Delete A Planet\n";
cout << " 11 - Sort\n";
cout << " 12 - Quit\n";
cout << "*******************************\n";
cout << " Enter your choice and press return: ";
cin >> choice;
switch (choice)
{
{case 1:
cout<<"~~~~Murcury~~~~\n";
cout<<"The Mass is 3.3022x10^23 KG.\n";
cout<<"The Radius is 4,880 KM.\n";
double mass=3.3022*pow(10,23);
double rad=4880;
double volumeSphere= (4/3)*M_PI*pow(rad,3.0);
double density=mass/volumeSphere;
cout<<"The Density of Murcury is:: "<<density<<"\n";
double SurASphere= 4*M_PI*pow(rad,2.0);
cout<<"The Surface Area:: "<<SurASphere<<"\n";
break;}
{case 2:
cout<<"~~~~Venus~~~~\n";
cout<<"The Mass is 4.8685x10^24 KG.\n";
cout<<"The Radius is 12,103.6 KM.\n";
double mass=4.8685*pow(10,24);
double rad=12103.6;
double volumeSphere= (4/3)*M_PI*pow(rad,3.0);
double density=mass/volumeSphere;
cout<<"The Density of Murcury is:: "<<density<<"\n";
double SurASphere= 4*M_PI*pow(rad,2.0);
cout<<"The Surface Area:: "<<SurASphere<<"\n";
break;}
{case 3:
cout<<"~~~~Earth~~~~\n";
cout<<"The Mass is 5.972x10^24.\n";
cout<<"The Radius is 12,756.3 KM.\n";
double mass=5.972*pow(10,24);
double rad=12756.3 ;
double volumeSphere= (4/3)*M_PI*pow(rad,3.0);
double density=mass/volumeSphere;
cout<<"The Density of Murcury is:: "<<density<<"\n";
double SurASphere= 4*M_PI*pow(rad,2.0);
cout<<"The Surface Area:: "<<SurASphere<<"\n";
break;}
{case 4:
cout<<"~~~~Mars~~~~\n";
cout<<"The Mass is 6.4219x10^23 KG.\n";
cout<<"The Radius is 6,794KM.\n";
double mass=4.8685*pow(10,23);
double rad=6794;
double volumeSphere= (4/3)*M_PI*pow(rad,3.0);
double density=mass/volumeSphere;
cout<<"The Density of Murcury is:: "<<density<<"\n";
double SurASphere= 4*M_PI*pow(rad,2.0);
cout<<"The Surface Area:: "<<SurASphere<<"\n";
break;}
{case 5:
cout<<"~~~~Jupiter~~~~\n";
cout<<"The Mass is 1.900ex10^27 KG.\n";
cout<<"The Radius is 142984KM.\n";
double mass=4.8685*pow(10,27);
double rad=142984;
double volumeSphere= (4/3)*M_PI*pow(rad,3.0);
double density=mass/volumeSphere;
cout<<"The Density of Murcury is:: "<<density<<"\n";
double SurASphere= 4*M_PI*pow(rad,2.0);
cout<<"The Surface Area:: "<<SurASphere<<"\n";
break;}
{case 6:
cout<<"~~~~Saturn~~~~\n";
cout<<"The Mass is 5.68x10^26 KG.\n";
cout<<"The Radius is 120,536 km.\n";
double mass=5.68*pow(10,26);
double rad=120536;
double volumeSphere= (4/3)*M_PI*pow(rad,3.0);
double density=mass/volumeSphere;
cout<<"The Density of Murcury is:: "<<density<<"\n";
double SurASphere= 4*M_PI*pow(rad,2.0);
cout<<"The Surface Area:: "<<SurASphere<<"\n";
break;}
{case 7:
cout<<"~~~~Uranus~~~~\n";
cout<<"The Mass is 8.683x10^25 KG.\n";
cout<<"The Radius is 51,118 KM.\n";
double mass= 8.683*pow(10,25);
double rad=51118;
double volumeSphere= (4/3)*M_PI*pow(rad,3.0);
double density=mass/volumeSphere;
cout<<"The Density of Murcury is:: "<<density<<"\n";
double SurASphere= 4*M_PI*pow(rad,2.0);
cout<<"The Surface Area:: "<<SurASphere<<"\n";
break;}
{case 8:
cout<<"~~~~Neptune~~~~\n";
cout<<"The Mass is 1.0247x10^26 KG.\n";
cout<<"The Radius is 49,532 KM.\n";
double mass=1.0247*pow(10,26);
double rad=49532;
double volumeSphere= (4/3)*M_PI*pow(rad,3.0);
double density=mass/volumeSphere;
cout<<"The Density of Murcury is:: "<<density<<"\n";
double SurASphere= 4*M_PI*pow(rad,2.0);
cout<<"The Surface Area:: "<<SurASphere<<"\n";
break;}
{case 9:
break;}
{case 10:
break;}
{case 11:
std::set<std::string> sortedItems;
for(int i = 1; i <= 8; ++i)
{
std::string name;
std::cout << i << ". ";
std::cin >> name;
sortedItems.insert(name);
}
std::for_each(sortedItems.begin(), sortedItems.end(), &print);
break;}
{case 12:
cout << "End of Program.\n";
gameOn = false;
break;}
{default:
cout << "Not a Valid Choice. \n";
cout << "Choose again.\n";
cin >> choice;
break;}
}
return 0;
}
}
Comment