Adding and Deleting

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#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;
    }
}

               
I suggest looking into std::list to store your planets data. Then you can do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <list>

class Planet
{
public:
	Planet(const std::string& name) : mName(name) {}
	bool operator==(const Planet& planet)
	{
		return planet.Name() == mName;
	}

	std::string Name() const
	{
		return mName;
	}

private:
	std::string mName;
};

int main ()
{
	std::list<Planet> planets;

	// Add Earth and Mars
	planets.push_back(Planet("Earth"));
	planets.push_back(Planet("Mars"));

	// Delete earth
	planets.remove(Planet("Earth"));

	// Print all planets
	for (std::list<Planet>::iterator it = planets.begin(); it != planets.end(); ++it)
	{
		std::cout << it->Name() << '\n';
	}

	while (true) {}
	return 0;
} 


P.S: Your mercury is spelt wrong.
Last edited on
I recommend using a Vector like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#define M_PI 3.14
using namespace std;
string addPlanet, removePlanet;
vector<string> PlanetList;
vector<string>::iterator PlanetIter;
int choice;
bool gameOn = true;
void print(const string& item)
{cout<<item<<endl;
 set<string> sortedItems;}
int main()
{
    PlanetList.push_back("Mercury");
	PlanetList.push_back("Venus");
	PlanetList.push_back("Earth");
	PlanetList.push_back("Mars");
	PlanetList.push_back("Jupiter");
	PlanetList.push_back("Saturn");
	PlanetList.push_back("Uranus");
	PlanetList.push_back("Neptune");
	int numberOfPlanets = PlanetList.size();
    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 - Auto-Sort\n";
        cout << " 13 - 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:
            cout << "\nType the Planet's name to add: ";
			cin.get();
			getline(cin, addPlanet);
            PlanetList.push_back(addPlanet);
			sort(PlanetList.begin(), PlanetList.end());
			cin.clear();
			cin.sync();
			numberOfPlanets++;
			cout << "\nGame successfully added.\n" << endl;
                break;}
            {case 10:
            cout << "\nType the Planet's name to remove: ";
			cin.get();
			getline(cin, removePlanet);
			PlanetIter = find(PlanetList.begin(), PlanetList.end(), removePlanet);
			if (removePlanet == *PlanetIter) {
            cout << "\nPlanet found!" << endl;
            PlanetList.erase(PlanetIter);
            numberOfPlanets--;
            cout << "Title removed!\n" << endl;}
			else{cout << "Title not found\n";}
                break;}
            {case 11:
                set<string> sortedItems;
                for(int i = 1; i <= 8; ++i)
                {
                    string name;
                    cout << i << ". ";
                    cin >> name;
                    sortedItems.insert(name);}
                for_each(sortedItems.begin(), sortedItems.end(), &print);
                break;}
            {case 12:
                sort(PlanetList.begin(), PlanetList.end());
                cout << "\nYou currently have " << numberOfPlanets << " Planets in your list.\n" << endl;
                for (PlanetIter = PlanetList.begin(); PlanetIter != PlanetList.end(); ++PlanetIter) {
				cout <<"\t"<< *PlanetIter << endl;}
                break;}
            {case 13:
                cout << "End of Program.\n";
                gameOn = false;
                break;}
            {default:
                cout << "Not a Valid Choice. \n";
                cout << "Choose again.\n";
                cin >> choice;
                break;}
        }
    }
return 0;
}
Last edited on
The ony reason why I'm formatting the code the way I did is because I had an assignment that was similar to this but instead of the planets I had to use shapes to find surface area and some other formulas. I'll give that code a shot. I appreciate the help guys. Thanks
Last edited on
Complete Program Part 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
void print(const string& item)
{
cout<<item<<endl;
set<string> sortedItems;}
int main()
{
bool gameOn = true;
    PlanetList.push_back("Mercury");
	PlanetList.push_back("Venus");
	PlanetList.push_back("Earth");
	PlanetList.push_back("Mars");
	PlanetList.push_back("Jupiter");
	PlanetList.push_back("Saturn");
	PlanetList.push_back("Uranus");
	PlanetList.push_back("Neptune");
    numList.push_back("1");
	numList.push_back("2");
	numList.push_back("3");
	numList.push_back("4");
	numList.push_back("5");
	numList.push_back("6");
	numList.push_back("7");
	numList.push_back("8");
	numList.push_back("9");
	numList.push_back("10");
	numList.push_back("11");
	numList.push_back("12");
	numList.push_back("13");
	numList.push_back("14");
	int numberOfPlanets = PlanetList.size();
    while (gameOn != false){
        cout << "*******************************\n";
        numIter = numList.begin();
        for (PlanetIter = PlanetList.begin(); PlanetIter != PlanetList.end(); ++PlanetIter)
        {cout<<"  "<<*numIter<<"  - "<<*PlanetIter<<endl;
        numIter++;}
        cout << "  9  - Add A Planet\n";
        cout << " 10  - Delete A Planet\n";
        cout << " 11  - Sort\n";
        cout << " 12  - Auto-Sort\n";
        cout << " 13  - Quit\n";
        cout << "*******************************\n";
        cout << "Enter your choice and press return: ";
        cin >> choice;
        cout<<endl;
        switch (choice)
        {
            {case 1:
               cout<<"~~~~Mercury~~~~\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 Mercury 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 Venus 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 Earth 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 Mars 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 Jupiter 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 Saturn 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 Uranus 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 Neptune is:: "<<density<<"\n";
                double SurASphere= 4*M_PI*pow(rad,2.0);
                cout<<"The Surface Area:: "<<SurASphere<<"\n";
                break;}
            {case 9:
            cout << "\nType the Planet's name to add: ";
			cin.get();
			getline(cin, addPlanet);
            PlanetList.push_back(addPlanet);
			sort(PlanetList.begin(), PlanetList.end());
			cin.clear();
			cin.sync();
			numberOfPlanets++;
			cout << "\nGame successfully added.\n" << endl;
                break;}
            {case 10:
            for (PlanetIter = PlanetList.begin(); PlanetIter != PlanetList.end(); ++PlanetIter){cout <<"\t"<< *PlanetIter << endl;}
			cout << "\n";
            cout << "\nType the Planet's name to remove: ";
			cin.get();
			getline(cin, removePlanet);
			PlanetIter = find(PlanetList.begin(), PlanetList.end(), removePlanet);
			if (removePlanet == *PlanetIter) {
            cout << "\nPlanet found!" << endl;
            PlanetList.erase(PlanetIter);
            numberOfPlanets--;
            cout << "Title removed!\n" << endl;}
			else{cout << "Title not found\n";}
                break;}
            {case 11:
                set<string> sortedItems;
                for(int i = 1; i <= 8; ++i)
                {
                    string name;
                    cout << i << ". ";
                    cin >> name;
                    sortedItems.insert(name);}
                for_each(sortedItems.begin(), sortedItems.end(), &print);
                break;}
            {case 12:
                After_Auto_Sort();
                gameOn = false;
                break;}
            {case 13:
                cout << "End of Program.\n";
                gameOn = false;
                break;}
            {default:
                cout << "Not a Valid Choice. \n";
                cout << "Choose again.\n";
                cin >> choice;
                break;}
        }
    system("pause");
    system("cls");
    }
return 0;
}
Last edited on
Complete Program Part 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
void After_Auto_Sort()
{
bool gameOn = true;
sort(PlanetList.begin(), PlanetList.end()-2);
	PlanetList.push_back("Add A Planet");
	PlanetList.push_back("Delete A Planet");
	numIter=numList.end()-4;
	numList.erase(numIter);
    while (gameOn != false){
    int numberOfPlanets = PlanetList.size();
        cout << "*******************************\n";
        numIter = numList.begin();
        for (PlanetIter = PlanetList.begin(); PlanetIter != PlanetList.end()-2; ++PlanetIter)
        {cout<<" "<<*numIter<<"  - "<<*PlanetIter<<endl;
        numIter++;}
        cout<<" 11  - Quit\n";
        while(PlanetIter!=PlanetList.end()){++PlanetIter;
        cout<<" "<<*numIter<<"  - "<<*PlanetIter<<endl;
        numIter++;}
        cout << "*******************************\n";
        cout << "Enter your choice and press return: ";
        cin >> choice;
        cout<<endl;
        switch (choice)
        {
            {case 4:
               cout<<"~~~~Mercury~~~~\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 Mercury is:: "<<density<<"\n";
                double SurASphere= 4*M_PI*pow(rad,2.0);
                cout<<"The Surface Area:: "<<SurASphere<<"\n";
                break;}
            {case 8:
                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 Venus is:: "<<density<<"\n";
                double SurASphere= 4*M_PI*pow(rad,2.0);
                cout<<"The Surface Area:: "<<SurASphere<<"\n";
                break;}
            {case 1:
                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 Earth is:: "<<density<<"\n";
                double SurASphere= 4*M_PI*pow(rad,2.0);
                cout<<"The Surface Area:: "<<SurASphere<<"\n";
                break;}
            {case 3:
                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 Mars is:: "<<density<<"\n";
                double SurASphere= 4*M_PI*pow(rad,2.0);
               cout<<"The Surface Area:: "<<SurASphere<<"\n";
                break;}
            {case 2:
                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 Jupiter 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 Saturn 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 Uranus is:: "<<density<<"\n";
                double SurASphere= 4*M_PI*pow(rad,2.0);
                cout<<"The Surface Area:: "<<SurASphere<<"\n";
                break;}
            {case 5:
                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 Neptune is:: "<<density<<"\n";
                double SurASphere= 4*M_PI*pow(rad,2.0);
                cout<<"The Surface Area:: "<<SurASphere<<"\n";
                break;}
            {case 9:
            cout << "\nType the Planet's name to add: ";
			cin.get();
			getline(cin, addPlanet);
            PlanetList.push_back(addPlanet);
			cin.clear();
			cin.sync();
			numberOfPlanets++;
			cout << "\nPlanet successfully added.\n" << endl;
                break;}
            {case 10:
            for (PlanetIter = PlanetList.begin(); PlanetIter != PlanetList.end(); ++PlanetIter){cout <<"\t"<< *PlanetIter << endl;}
			cout << "\n";
            cout << "\nType the Planet's name to remove: ";
			cin.get();
			getline(cin, removePlanet);
			PlanetIter = find(PlanetList.begin(), PlanetList.end(), removePlanet);
			if (removePlanet == *PlanetIter) {
            cout << "\nPlanet found!" << endl;
            PlanetList.erase(PlanetIter);
            numberOfPlanets--;
            cout << "Planet removed!\n" << endl;}
			else{cout << "Planet not found\n";}
                break;}
            {case 11:
                cout << "End of Program.\n";
                gameOn = false;
                break;}
            {default:
                cout << "That Planet's Information I not in the Database. \n";
                cout << "Choose again.\n";
                break;}
        }
    system("pause");
    system("cls");
    }
return;
}
Topic archived. No new replies allowed.