Write a program that do the following unit conversion based on user menu selecti
ID: 3883303 • Letter: W
Question
Write a program that do the following unit conversion based on user menu selection: (use while or do-while loop until the user enter 'Quit' selection) Seconds to hours, minutes and seconds (must Implement as a function) Inputs an Integer that represents a length of time in seconds. The program should then output the number of hours, minutes, and seconds that corresponds to that number of seconds. For example, If the user inputs 50391 total seconds then the program should output 13 hours, 59 minutes, and 51 seconds. Your program must check for valid input (positive integer only) Fahrenheit to Celsius (must implement as a function) Inputs an Fahrenheit the program will convert to Celsius. For example, input 82 the program should output 27.7 degree F to degree C - Deduct 32, then multiply by 5, then divide by 9 Your program must check for valid input (number only) Celsius to Fahrenheit (must implement as a function) Inputs Celsius the program will convert to Fahrenheit. For example, input 12 the program should output 53.6 degree C to degree F - Multiply by 9. then divide by 5. then add 3 Your program must check for valid input (number only)Explanation / Answer
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <iomanip>
#include <cmath>
using namespace std;
float Farenheit(float);
float Celsius(float);
int main()
{
float temp1, temp2;
int ch;
do
{
cout<<" Menu";
cout<<" 1. Conversion from Seconds to Hours, Minutes, Seconds";
cout<<" 2. Conversion from Farenheit to Celsius";
cout<<" 3. Conversion from Celsius to Farenheit";
cout<<" Enter User Choice:";
cin>>ch;
switch(ch)
{
case 1:
int tot_sec, min, hr, minutes, seconds;
cout<<" Conversion from Seconds to Hours, Minutes, Seconds";
cout<<" Enter number of Seconds: ";
cin>>tot_sec;
if(tot_sec < 0)
cout<<" Enter Positive Integer only";
else if(tot_sec == 0)
cout<<" Enter Other then 0";
else if(tot_sec > 0)
{
hr = tot_sec / 3600;
min = tot_sec / 60;
minutes = min % 60;
seconds = tot_sec % 60;
cout<<" Total Seconds " <<tot_sec << " = " <<hr <<" Hours " <<minutes <<" Minutes " <<seconds <<" Seconds";
}
break;
case 2:
cout<<" Conversion from Farenheit to Celsius";
cout<<" Enter Temperature: ";
cin>>temp1;
if(cin.fail())
cout<<" Enter Correct Input for Farenheit";
if(!cin.fail())
{
Farenheit(temp1);
cout <<" Farenheit " <<temp1 <<" = " <<Farenheit(temp1) <<"C";
}
break;
case 3:
cout<<" Conversion from Celsius to Farenheit";
cout<<" Enter Celsius: ";
cin>>temp2;
if(!cin)
{
cout<<" Entered Integer only";
}
else
{
Celsius(temp2);
cout <<" Celsius " <<temp2 <<" = " <<Celsius(temp2) <<"F";
}
break;
}
}while((ch <= 1) && (ch < 4));
return 0;
}
float Farenheit(float temp1)
{
return ((temp1 - 32) * 5) / 9;
}
float Celsius(float temp2)
{
return ((temp2 * 9) / 5) + 32;
}
OUTPUT
Menu
1. Conversion from Seconds to Hours, Minutes, Seconds
2. Conversion from Farenheit to Celsius
3. Conversion from Celsius to Farenheit
Enter User Choice:1
Conversion from Seconds to Hours, Minutes, Seconds
Enter number of Seconds: 50392
Total Seconds 50392 = 13 Hours 59 Minutes 52 Seconds
Menu
1. Conversion from Seconds to Hours, Minutes, Seconds
2. Conversion from Farenheit to Celsius
3. Conversion from Celsius to Farenheit
Enter User Choice:2
Conversion from Farenheit to Celsius
Enter Temperature: 82
Farenheit 82 = 27.7778C
Menu
1. Conversion from Seconds to Hours, Minutes, Seconds
2. Conversion from Farenheit to Celsius
3. Conversion from Celsius to Farenheit
Enter User Choice:3
Conversion from Celsius to Farenheit
Enter Celsius: 12
Celsius 12 = 53.6F
Menu
1. Conversion from Seconds to Hours, Minutes, Seconds
2. Conversion from Farenheit to Celsius
3. Conversion from Celsius to Farenheit
Enter User Choice:
Menu
1. Conversion from Seconds to Hours, Minutes, Seconds
2. Conversion from Farenheit to Celsius
3. Conversion from Celsius to Farenheit
Enter User Choice:1
Conversion from Seconds to Hours, Minutes, Seconds
Enter number of Seconds: 0
Enter Other then 0
Menu
1. Conversion from Seconds to Hours, Minutes, Seconds
2. Conversion from Farenheit to Celsius
3. Conversion from Celsius to Farenheit
Enter User Choice:3
Conversion from Celsius to Farenheit
Enter Celsius: abc
Entered Integer only
Menu
1. Conversion from Seconds to Hours, Minutes, Seconds
2. Conversion from Farenheit to Celsius
3. Conversion from Celsius to Farenheit
Enter User Choice:1
Conversion from Seconds to Hours, Minutes, Seconds
Enter number of Seconds: -50391
Enter Positive Integer only
Menu
1. Conversion from Seconds to Hours, Minutes, Seconds
2. Conversion from Farenheit to Celsius
3. Conversion from Celsius to Farenheit
Enter User Choice:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.