Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <fstream>
- using namespace std;
- class Star{
- public:
- Star(string sName, int sMass, double sTemp);
- string getName();
- int getMass();
- double getTemp();
- void setMass(int nMass);
- void setTemp(double nTemp);
- private:
- string newName;
- int newMass;
- double newTemp;
- };
- Star::Star(string sName, int sMass, double sTemp){
- newName = sName;
- newMass = sMass;
- newTemp = sTemp;
- }
- string Star::getName(){
- return newName;
- }
- int Star::getMass(){
- return newMass;
- }
- double Star::getTemp(){
- return newTemp;
- }
- void Star::setMass(int nMass){
- newMass = nMass;
- }
- void Star::setTemp(double nTemp){
- newTemp = nTemp;
- }
- class Planet{
- public:
- Planet(string pName, int pMass, char pWater, double pDist);
- string getName();
- int getMass();
- char getWater();
- double getDist();
- void setMass(int nMass);
- void setWater(char nWater);
- void setDist(double nDist);
- private:
- string newName;
- int newMass;
- char newWater;
- double newDist;
- };
- Planet::Planet(string pName, int pMass, char pWater, double pDist){
- newName = pName;
- newMass = pMass;
- newWater = pWater;
- newDist = pDist;
- }
- string Planet::getName(){
- return newName;
- }
- int Planet::getMass(){
- return newMass;
- }
- char Planet::getWater(){
- return newWater;
- }
- double Planet::getDist(){
- return newDist;
- }
- void Planet::setMass(int nMass){
- newMass = nMass;
- }
- void Planet::setWater(char nWater){
- newWater = nWater;
- }
- void Planet::setDist(double nDist){
- newDist = nDist;
- }
- class Universe{
- public:
- Universe();
- void addStar(Star);
- void addPlanet(Planet);
- Star getStar(int indexPos);
- Planet getPlanet(int posIndex);
- void showUniverse();
- void writeToFile(string fileName);
- private:
- vector<Star> sVec;
- vector<Planet> pVec;
- };
- Universe::Universe(){
- }
- void Universe::addStar(Star aStar){
- sVec.push_back(aStar);
- }
- void Universe::addPlanet(Planet aPlanet){
- pVec.push_back(aPlanet);
- }
- Star Universe::getStar(int indexPos){
- vector<Star>::iterator iter = sVec.begin() + indexPos - 1;
- Star returnStar = *iter;
- return returnStar;
- }
- Planet Universe::getPlanet(int indexPos){
- vector<Planet>::iterator iter = pVec.begin() + indexPos - 1;
- Planet returnPlanet = *iter;
- return returnPlanet;
- }
- void Universe::showUniverse(){
- int starCount = 0;
- cout << "\nStars: \n";
- for(vector<Star>::iterator iter = sVec.begin(); iter != sVec.end(); ++iter){
- starCount++;
- cout << "Star #" << starCount << ": " << iter->getName() << ", Mass: " << iter->getMass() << ", Temperature: " << iter->getTemp() << "\n";
- }
- int planetCount = 0;
- cout << "\nPlanets: \n";
- for(vector<Planet>::iterator iter = pVec.begin(); iter != pVec.end(); ++iter){
- planetCount++;
- cout << "Planet #" << planetCount << ": " << iter->getName() << ", Mass: " << iter->getMass() << ", Has Water?: " << iter->getWater() << ", Distance: " << iter->getDist() << "\n";
- }
- }
- void Universe::writeToFile(string fileName){
- ofstream newFile(fileName);
- if(newFile.is_open()){
- int starCount = 0;
- for(vector<Star>::iterator iter = sVec.begin(); iter != sVec.end(); ++iter){
- starCount++;
- newFile << "Star #" << starCount << ": " << iter->getName() << ", Mass: " << iter->getMass() << ", Temperature: " << iter->getTemp() << "\n";
- }
- int planetCount = 0;
- for(vector<Planet>::iterator iter = pVec.begin(); iter != pVec.end(); ++iter){
- planetCount++;
- newFile << "Planet #" << planetCount << ": " << iter->getName() << ", Mass: " << iter->getMass() << ", Has Water?: " << iter->getWater() << ", Distance: " << iter->getDist() << "\n";
- }
- newFile.close();
- }
- }
- void askToWrite(Universe myUni);
- int main(){
- cout << "-----------------------------------------------\n";
- cout << "Welcome to Universe Simulator: by Ben Bollinger\n";
- cout << "-----------------------------------------------\n\n";
- Universe myUni;
- int starNum;
- cout << "Enter Number of Stars: ";
- cin >> starNum;
- int planetNum;
- cout << "\nEnter Number of Planets: ";
- cin >> planetNum;
- cout << "\n";
- for(int i = 0; i < starNum; i++){
- string stName;
- cout << "Enter Star Name: ";
- cin >> stName;
- int stMass;
- cout << "Enter Star Mass: ";
- cin >> stMass;
- double stTemp;
- cout << "Enter Star Temperature: ";
- cin >> stTemp;
- Star newStar(stName, stMass, stTemp);
- myUni.addStar(newStar);
- cout << "\n";
- }
- for(int i = 0; i < planetNum; i++){
- string stName;
- cout << "Enter Planet Name: ";
- cin >> stName;
- int stMass;
- cout << "Enter Planet Mass: ";
- cin >> stMass;
- char plWater;
- cout << "Enter y/n If Planet has Water: ";
- cin >> plWater;
- double plDist;
- cout << "Enter Planet's Distance: ";
- cin >> plDist;
- Planet newPlanet(stName, stMass, plWater, plDist);
- myUni.addPlanet(newPlanet);
- cout << "\n";
- }
- myUni.showUniverse();
- string yesorno;
- cout << "\nChange a Planet or Star? (y/n): ";
- cin >> yesorno;
- if(yesorno == "y"){
- string plOrSt;
- cout << "Planet or Star? (p/s): ";
- cin >> plOrSt;
- if(plOrSt == "p"){
- int planet;
- cout << "\nWhich Planet? (Enter Planet Number): ";
- cin >> planet;
- Planet modPlanet = myUni.getPlanet(planet);
- string change;
- cout << "Change Mass, Water, or Distance? (m, w, d): ";
- cin >> change;
- if(change == "m"){
- int nMass;
- cout << "Change Mass From " << modPlanet.getMass() << " to what?: ";
- cin >> nMass;
- modPlanet.setMass(nMass);
- cout << "\n" << modPlanet.getName() << "'s new mass is " << modPlanet.getMass();
- }else if(change == "w"){
- char nWater;
- cout << "Change Water From " << modPlanet.getWater() << " to what?: ";
- cin >> nWater;
- modPlanet.setWater(nWater);
- cout << "\n" << modPlanet.getName() << "'s new water var is " << modPlanet.getWater();
- }else if(change == "d"){
- double nDist;
- cout << "Change Distance From " << modPlanet.getDist() << " to what?: ";
- cin >> nDist;
- modPlanet.setDist(nDist);
- cout << "\n" << modPlanet.getName() << "'s new distance is " << modPlanet.getDist();
- }else{
- cout << "\nEnded\n";
- }
- }else if(plOrSt == "s"){
- int star;
- cout << "\nWhich Star? (Enter Star Number): ";
- cin >> star;
- Star modStar = myUni.getStar(star);
- string change;
- cout << "Change Mass, or Temperature? (m/t): ";
- cin >> change;
- if(change == "m"){
- int nMass;
- cout << "Change Mass From " << modStar.getMass() << " to what?: ";
- cin >> nMass;
- modStar.setMass(nMass);
- cout << "\n" << modStar.getName() << "'s new mass is " << modStar.getMass();
- }else if(change == "t"){
- char nTemp;
- cout << "Change Water From " << modStar.getTemp() << " to what?: ";
- cin >> nTemp;
- modStar.setTemp(nTemp);
- cout << "\n" << modStar.getName() << "'s new temperature is " << modStar.getTemp();
- }else{
- askToWrite(myUni);
- cout << "\nEnded\n";
- }
- }else{
- askToWrite(myUni);
- cout << "\nEnded\n";
- }
- }else{
- askToWrite(myUni);
- cout << "\nEnded\n";
- }
- cout << "\n\n";
- system("pause");
- }
- void askToWrite(Universe myUni){
- string writeInfo;
- cout << "\n\nWrite Information To File? (y/n): ";
- cin >> writeInfo;
- if(writeInfo == "y"){
- string fileName;
- cout << "Name of file?: ";
- cin >> fileName;
- myUni.writeToFile(fileName);
- }else{
- cout << "\nEnded\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement