Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help on c++ homework. thanks Need help updating code from last assignment t

ID: 3607741 • Letter: N

Question

Need help on c++ homework. thanks

Need help updating code from last assignment to this assignment above

here is code to update below.

#include

using namespace std;

double mercury(double oWeight) {

return oWeight * 0.38;

}

double venus(double oWeight) {

return oWeight * 0.91;

}

double mars(double oWeight) {

return oWeight * 0.38;

}

double moon(double oWeight) {

return oWeight * 0.17;

}

int main() {

double userInput;

again:

cout << "Enter weight on earth: " << endl;

cin >> userInput ;

if(userInput <= 0) {

cout << "Can't go below 0, Please try again" << endl;

goto again;

}

do {

cout << "*****************************" << endl;

cout << "* Main Menu:" << endl;

cout << "* Select planet to convert earth's weight to:" << endl;

cout << "1) Mercury" << endl;

cout << "2) Venus" << endl;

cout << "3) Mars" << endl;

cout << "4) Moon" << endl;

cout << "5) All planets" << endl;

cout << "6) Exit" << endl;

cout << "*****************************" << endl;

int userselection;

cout << "choose #:";

cin >> userselection;

switch(userselection) {

case(1):

cout << "Earth's weight: " << userInput << " lbs."

<< endl << "Mercury's weight: " << mercury(userInput) << " lbs."

<< endl;

break;

case(2):

cout << "Earth's weight: " << userInput << " lbs."

<< endl << "Venus weight: " << venus(userInput) << " lbs."

<< endl;

break;

case(3):

cout << "Earth's weight: " << userInput << " lbs."

<< endl << "Mars's weight: " << mars(userInput) << " lbs."

<< endl;

break;

case(4):

cout << "Earth's weight: " << userInput << " lbs."

<< endl << "Moon's weight: " << moon(userInput) << " lbs."

<< endl;

break;

case(5):

cout << "Earth's weight: " << userInput << " lbs."

<< endl << "Mercury's weight: " << mercury(userInput) << " lbs."

<< endl << "Venus weight: " << venus(userInput) << " lbs."

<< endl << "Mars weight: " << mars(userInput) << " lbs."

<< endl << "Moon's weight: " << moon(userInput) << " lbs."

<< endl;

break;

case(6):

cout << "Goodbye!" << endl;

break;

default:

cout << "Wrong selection. Try again..." << endl;

}

}while(userInput!=6);

return 0;

}

Update Program to Class Structure Create a class called Weight. Create getter and setter methods that will solve the problem Use main to organize the execution of the program Update your program to us a menu that will not close until the user selects quit option. Program should contain a menu. Enter 1. For Mercury Weight (After the user enters 1 the program will output weight converted to Mercury weight.) Enter 2. For Venus Weight (After the user enters 1 the program will output weight converted to Venus weight. ) Enter 3. For Mars Weight Enter 4. For Earth Moon Weight Enter 5: For all Conversions Enter 6: To Quit

Explanation / Answer

Hello, I have modified the code as per the requirements.

//file.cpp

#include <iostream>

using namespace std;

/*class to store earth's weight and returns corresponding weights of any planets*/

class Weight{

    double weight;

    public:

    /*setting weight on earth*/

    void setWeight(double w){

        weight=w;

    }

    /*getting weight on earth*/

    double getWeight(){

        return weight;

    }

    /*getting weight on mercury*/

    double getWeightInMercury(){

        return weight* 0.38;

    }

    /*getting weight on venus*/

    double getWeightInVenus(){

        return weight* 0.91;

    }

    /*getting weight on mars*/

    double getWeightInMars(){

        return weight* 0.38;

    }

    /*getting weight on moon*/

    double getWeightInMoon(){

        return weight * 0.17;

    }

};

double getUserInputWeight(); /*function to get user input weight*/

void showMenu(Weight w); /*function to display the menu*/

int main()

{

double input=getUserInputWeight(); /*getting weight from user */

Weight weight; /*creating a Weight object*/

weight.setWeight(input); /*setting the weight on earth*/

showMenu(weight); /*displays the menu*/

}

/*gets the user input*/

double getUserInputWeight(){

    double userInput;

    cout << "Enter weight on earth: " << endl;

    cin >> userInput ;

    if(userInput <= 0) {

        cout << "Can't go below 0, Please try again" << endl;

        return getUserInputWeight();

    }

    return userInput;

}

/*displays the menu*/

void showMenu(Weight w){

    bool quit=false; /*a variable to denote if the user selected quit option*/

    while(!quit){ /*will loop again and again until the quit variable is true*/

        cout << "*****************************" << endl;

        cout << "* Main Menu:" << endl;

        cout << "* Select planet to convert earth's weight to:" << endl;

        cout << "1) Mercury" << endl;

        cout << "2) Venus" << endl;

        cout << "3) Mars" << endl;

        cout << "4) Moon" << endl;

        cout << "5) All planets" << endl;

        cout << "6) Exit" << endl;

        cout << "*****************************" << endl;

        int userselection;

        cout << "choose #:";

        cin >> userselection;

        switch(userselection){

            case(1):

            cout << "Earth's weight: " << w.getWeight() << " lbs."

            << endl << "Mercury's weight: " <<w.getWeightInMercury() << " lbs."

            << endl;

            break;

            case(2):

            cout << "Earth's weight: " << w.getWeight()<< " lbs."

            << endl << "Venus weight: " << w.getWeightInVenus()<< " lbs."

            << endl;

            break;

            case(3):

            cout << "Earth's weight: " << w.getWeight() << " lbs."

            << endl << "Mars's weight: " << w.getWeightInMars() << " lbs."

            << endl;

            break;

            case(4):

            cout << "Earth's weight: " << w.getWeight()<< " lbs."

            << endl << "Moon's weight: " <<w.getWeightInMoon() << " lbs."

            << endl;

            break;

            case(5):

            cout << "Earth's weight: " << w.getWeight() << " lbs."

            << endl << "Mercury's weight: " << w.getWeightInMercury() << " lbs."

            << endl << "Venus weight: " << w.getWeightInVenus() << " lbs."

            << endl << "Mars weight: " << w.getWeightInMars() << " lbs."

            << endl << "Moon's weight: " << w.getWeightInMoon()<< " lbs."

            << endl;

            break;

            case(6):

            cout << "Goodbye!" << endl;

            quit=true; /*user selected to quit, so there wont be any more looping*/

            break;

            default:

            cout << "Wrong selection. Try again..." << endl;

        }

    }

}

/*output*/

Enter weight on earth:

2

*****************************

* Main Menu:

* Select planet to convert earth's weight to:

1) Mercury

2) Venus

3) Mars

4) Moon

5) All planets

6) Exit

*****************************

choose #:1

Earth's weight: 2 lbs.

Mercury's weight: 0.76 lbs.

*****************************

* Main Menu:

* Select planet to convert earth's weight to:

1) Mercury

2) Venus

3) Mars

4) Moon

5) All planets

6) Exit

*****************************

choose #:3

Earth's weight: 2 lbs.

Mars's weight: 0.76 lbs.

*****************************

* Main Menu:

* Select planet to convert earth's weight to:

1) Mercury

2) Venus

3) Mars

4) Moon

5) All planets

6) Exit

*****************************

choose #:5

Earth's weight: 2 lbs.

Mercury's weight: 0.76 lbs.

Venus weight: 1.82 lbs.

Mars weight: 0.76 lbs.

Moon's weight: 0.34 lbs.

*****************************

* Main Menu:

* Select planet to convert earth's weight to:

1) Mercury

2) Venus

3) Mars

4) Moon

5) All planets

6) Exit

*****************************

choose #:6

Goodbye!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote