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

I need help to analyze the difference and similarities between: SOLUTION 1 & 3 S

ID: 3853053 • Letter: I

Question

I need help to analyze the difference and similarities between:

SOLUTION 1 & 3

SOLUTION 2 & 3 below per c+++. Thank you

SOLUTION 1

struct temperatureType

{

       int fahrenheit;

       int centigrade;

};

#include <iostream>

using namespace std;

char choiceMenu();

void getFahrenheit(temperatureType &);

void getCentigrade(temperatureType &);

void calcFahrenheit(temperatureType &);

void calcCentigrade(temperatureType &);

void print(temperatureType &);

void main()

{

       char choice, loopChoice;

       temperatureType oneConversion;

       oneConversion.fahrenheit = 0;

       oneConversion.centigrade = 0;

       cout << "Do you want to run the temperature conversion program? " << endl;

       cout << "Enter a Y or N here: " << flush;

       cin >> loopChoice;

       while (loopChoice == 'Y' || loopChoice == 'y')

       {

              choice = choiceMenu();

              if (choice == '1')

              {

                     getCentigrade(oneConversion);

                     calcFahrenheit(oneConversion);

                     print(oneConversion);

              }

              else if (choice == '2')

              {

                     getFahrenheit(oneConversion);

                     calcCentigrade(oneConversion);

                     print(oneConversion);

              }

              else

              {

                     cout << " Invalid entry!!!" << endl << endl;

              }

              cout << " Do you want to run the temperature conversion program again? " << endl;

              cout << "Enter a Y or N here: " << flush;

              cin >> loopChoice;

       }

}

char choiceMenu()

{

       char tempChar;

      

       system("cls");

       cout << "To convert C -> F enter 1 : " << endl;

       cout << "To convert F -> C enter 2 : " << endl << endl;

       cout << "Enter choice here: " << flush;

       cin >> tempChar;

       return tempChar;

}

void getFahrenheit(temperatureType &Conversion)

{

       cout << "Enter number in fahrenheit : ";

       cin >> Conversion.fahrenheit;

}

void getCentigrade(temperatureType &Conversion)

{

       cout << "Enter number in Centigrade : ";

       cin >> Conversion.centigrade;

}

void calcFahrenheit(temperatureType &Conversion)

{

       Conversion.fahrenheit = Conversion.centigrade * 9.0 / 5.0 + 32;

}

void calcCentigrade(temperatureType &Conversion)

{

       Conversion.centigrade = ( Conversion.fahrenheit - 32 ) * 5.0 / 9.0;

}

void print(temperatureType &Conversion)

{

       cout << " Fahrenheit of " << Conversion.fahrenheit << " is " << Conversion.centigrade << " in Centigrade" << endl << endl;

}

SOLUTION 2

struct temperatureType

{

       int fahrenheit;

       int centigrade;

       void getFahrenheit();

       void getCentigrade();

       void calcFahrenheit();

       void calcCentigrade();

       void print();

};

#include <iostream>

using namespace std;

char choiceMenu();

void main()

{

       char choice, loopChoice;

       temperatureType oneConversion;

       cout << "Do you want to run the temperature conversion program? " << endl;

       cout << "Enter a Y or N here: " << flush;

       cin >> loopChoice;

       while (loopChoice == 'Y' || loopChoice == 'y')

       {

              choice = choiceMenu();

              if (choice == '1')

              {

                     oneConversion.getCentigrade();

                     oneConversion.calcFahrenheit();

                     oneConversion.print();

              }

              else if (choice == '2')

              {

                     oneConversion.getFahrenheit();

                     oneConversion.calcCentigrade();

                     oneConversion.print();

              }

              else

              {

                     cout << " Invalid entry!!!" << endl << endl;

              }

              cout << " Do you want to run the temperature conversion program again? " << endl;

              cout << "Enter a Y or N here: " << flush;

              cin >> loopChoice;

       }

}

char choiceMenu()

{

       char tempChar;

      

       system("cls");

       cout << "To convert C -> F enter 1 : " << endl;

       cout << "To convert F -> C enter 2 : " << endl << endl;

       cout << "Enter choice here: " << flush;

       cin >> tempChar;

       return tempChar;

}

void temperatureType::getFahrenheit()

{

       cout << "Enter number in fahrenheit : ";

       cin >> fahrenheit;

}

void temperatureType::getCentigrade()

{

       cout << "Enter number in Centigrade : ";

       cin >> centigrade;

}

void temperatureType::calcFahrenheit()

{

       fahrenheit = centigrade * 9.0 / 5.0 + 32;

}

void temperatureType::calcCentigrade()

{

       centigrade = ( fahrenheit - 32 ) * 5.0 / 9.0;

}

void temperatureType::print()

{

       cout << " Fahrenheit of " << fahrenheit << " is " << centigrade << " in Centigrade" << endl << endl;

}

SOLUTION 3

#include "stdafx.h"

#include <iostream>

using namespace std;

void menu();

struct temperature

{

       float ce;

       float fah;

       float convertToFah(float ce)

       {

              return ce*9/5+32;

       }

       float convertToCel(float fah)

       {

              return (fah-32)*5/9;

       }

};

int main()

{

       int ch;

do {

       cout << "Enter 1 to do the conversions 2 to quit:";

       cin >> ch;

       menu();

} while (ch == 1);

return 0;

}

void menu()

{

       temperature t;

       int choice;

       float value;

       cout << "Enter 1 to convert from Fahrenheit to Celsius and 2 to convert Celsius to Fahrenheit" << endl;

       cin >> choice;

       switch (choice)

       {

       case 1:

                     cout << "Enter the value in Fahrenheit:";

                     cin >> value;

                     cout << "The value in celsius is" << t.convertToCel(value) << endl;

                     break;

              case 2:

                     cout << "Enter the value in Celsius:";

                     cin >> value;

                     cout << " The value in Fahrenheit is " << t.convertToFah(value) << endl;

                     break;

              default:break;

       }

}

Explanation / Answer

Difference between 1 and 3:

In Solution 3 we are implementing the methods inside the structure so we are calling using struct variable whereas in 1, we are calling directly without using struct variable.

In 1, we are writing many methods to execute the logic whereas in 3 we are using only 2 methods. This reduces the length and also runs efficiently.

Difference between 1 and 2

In 2, we are declaring the methods and variables in the structure so we are directly calling the methods by using the structure variable whereas in 1, we are only declaring the variables as structure so we are creating a structure variable and as we have given the parameter in the method as struct type so we are directly calling those methods without using any structure variable.

Similarity:

In both we are declaring the variables inside the struct. We are using the same methods and using switch case .

Difference between 2 and 3

In 2, we are declaring the methods and variables in the structure so we are directly calling the methods by using the structure variable and in Solution 3 we are implementing the methods inside the structure so we are calling using struct variable  in 3 we are using only two methods. This reduces the length and also runs efficiently.

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