In: Computer Science
Code: (Text File Also Included in End)
Output:
Files:
Code:
#include <iostream>
#include<string>
using namespace std;
void print(string msg){ // Method for print simple string
cout << msg << "\n";
}
void printDouble(double val){ // Method for print a double
cout << val << "\n";
}
/*
A multiplierMethod which takes multiplier in method call
and takes value input from user and multiplies both and
prints result.
*/
void multiplierMethod(double multiplier){
double val;
print("Type value to be Converted");
cin >> val;
print("Converted Output:");
printDouble(val * multiplier);
}
int main() // Main Method
{
double multiplier; // Variable for store
multiplier
print("*** Universal Converter***");
while(true){ // Infinite Loop
// Printing Menu
print("Choose Menu:");
print("1: Time Converter");
print("2: Length Converter");
print("3: Weight Converter");
print("4: Currency
Converter");
print("5: Temperature
Converter");
int Menu;
cin >> Menu; // Taking Menu
input
switch(Menu){ // Switching over
input
case 1: // Time
Conversion is choosen
{ //
Printing Sub Menu for Time Conversion
print("Choose Conversion");
print("1: Minutes To Second");
print("2: Second To Minutes");
print("3: Hours To Second");
print("4: Second to Hours");
print("5: Hours to Minutes");
int time;
cin >> time; // Time conversion Type
switch(time){ // Switching over selected
input
case 1: multiplierMethod(60);
break;
case 2:
multiplierMethod(1.0/60); break;
case 3:
multiplierMethod(3600); break;
case 4:
multiplierMethod(1.0/3600); break;
case 5: multiplierMethod(60);
break;
}
}
break;
case 2: //
Length Conversion is choosen
{ // There can
be many cases of length, So insted of
// providing menu, simply asking
multiplier
print("Type multiplier(Ex. Meter to Cm =
1000):");
cin >> multiplier;
multiplierMethod(multiplier);
break;
}
case 3: //
Weight Conversion is choosen
{
print("Type multiplier(Ex. Kg to g =
1000):");
cin >> multiplier;
multiplierMethod(multiplier);
break;
}
case 4: //
Currency conversion is choosen
{
print("Type multiplier(Ex. Pound to Dollar =
1.30):");
cin >> multiplier;
multiplierMethod(multiplier);
break;
}
case 5: //
Temperature conversion is choosen
{
print("Choose Conversion:");
print("1: Celcius to Farenheit");
print("2: Farenheit to Celcius");
string temp;
cin >> temp;
double val;
print("Type value to be Converted");
cin >> val;
print("Converted Output:");
if (temp == "1"){
printDouble((val * 9/5) +
32);
}else{
printDouble((val - 32) *
5/9);
}
break;
}
default:
print("Wrong
Menu, Choose Again!");
break;
}
}
return 0;
}