1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
inline void keep_window_open(){ char ch; cin >> ch; }
//Function Prototypes;
void displayMenu();
double getMenuSelection(char var, double FtoC, double CtoF);
double getStartEndAndIncrement(double a, double b, double c);
double FtoC(double);
double CtoF(double);
void displayTable();
// Program Main*****************************************************;
int main()
{
cout << fixed << setprecision(1) << left;
void displayMenu();
double getStartEndAndIncrement(double a, double b, double c);
double getMenuSelection(char var, double FtoC, double CtoF);
void displayTable();
cin.ignore();
return 0; // End of Main**********************************;
}
// Instruction display;
void displayMenu()
{
cout << "Please enter the starting temperature, the increments you wish to see from the\n";
cout << "starting temp. to the ending temp. and the ending temperature and, if you wish\n";
cout << "to convert from Celsius to Fahrenheit type 'C' or, Fahrenheit to Celsius type 'F'.\n";
cout << "Type 'Q' to Quit.\n";
}
// Selecting conversion units;
double getMenuSelection(char var, double FtoC, double CtoF)
{
switch (var)
{
case 'f': case 'F':
return FtoC;
break;
case 'c': case 'C':
return CtoF;
break;
case 'q': case 'Q':
cout << "Good Bye!" << endl;
break;
default:
cout << "Invalid selection: try again.\n";
break;
}
}
// Getting starting temp, ending temp, and increments desired for table;
void getStartEndAndIncrement(double& a, double& b, double& c)
{
double startingTemp = a;
double endingTemp = b;
double incrementTemp = c;
}
// Fahrenheit to celsius conversion;
double FtoC(double& startingTemp)
{
startingTemp= (9 * startingTemp) / 5 + 32;
return startingTemp;
}
// Celsius to Fahrenheit conversion;
double CtoF(double& startingTemp)
{
startingTemp = 5 * (startingTemp - 32) / 9;
return startingTemp;
}
// Displays the temperatures in a table;
void displayTable(double i, double startingTemp, double incrementTemp, double endingTemp, char FtoC, char CtoF)
{
if (FtoC)
{
i = startingTemp;
cout << '\t' << "From " << (char)248 << "F" << '\t';
cout << '\t' << "To " << (char)248 << "C" << endl;
while (startingTemp <= endingTemp)
{
cout << '\t' << right << startingTemp << (char)248 << "F" << '\t';
cout << '\t' << right << startingTemp << (char)248 << "C" << endl;
i += incrementTemp;
}
}
if (CtoF)
{
i = startingTemp;
cout << '\t' << "From " << (char)248 << "C" << '\t';
cout << '\t' << "To " << (char)248 << "F" << endl;
while (startingTemp <= endingTemp)
{
cout << '\t' << right << startingTemp << (char)248 << "C" << '\t';
cout << '\t' << right << startingTemp << (char)248 << "F" << endl;
i += incrementTemp;
}
}
}
|