/* Freezing And Boiling Points - The following table lists the freezing and
boiling points of several substances.
Substance Freezing Point (°F) Boiling Point (°F)
Ethyl alcohol -173 172
Mercury -38 676
Oxygen -362 -306
Water 32 212
This program asks the user to enter a temperature and then shows all the
substances that will freeze at that temperature and all that will boil at
that temperature. For example, if the user enters -20 the program should
report that water will freeze and oxygen will boil at that temperature. */
#include "Utility.h"
int main()
{
/* Hold constants for freezing and boiling points */
const double ETHYL_ALCOHOL_FP = -173,
ETHYL_ALCOHOL_BP = 172,
MERCURY_FP = -38,
MERCURY_BP = 676,
OXYGEN_FP = -362,
OXYGEN_BP = -306,
WATER_FP = 32,
WATER_BP = 212;
/* Hold temperature */
double temperature = 0;
/* Ask the user to enter a temperature */
cout << "Enter a temperature in degree Fahrenheit: ";
cin >> temperature;
/* Determine and display the substances freezing and boiling,
based upon the user input of a temperature */
if (temperature == OXYGEN_FP)
{
cout << "\nAt a temperature of " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will freeze: \n"
<< "Oxygen: -362 degree F.\n\n";
}
else if (temperature == OXYGEN_BP)
{
cout << "\nAt a temperature of " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will boil: \n"
<< "Oxygen: -306 degree F.\n\n";
}
else if (temperature >= OXYGEN_FP && temperature <= OXYGEN_BP)
{
cout << "\nAt a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to freeze: "
<< "\nOxygen: -362 degree F.\n"
<< "At a temperature above " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to boil: "
<< "\nOxygen: -306 degree F.\n";
}
else if (temperature == ETHYL_ALCOHOL_FP)
{
cout << "\nAt a temperature of " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will freeze: \n"
<< "Ethyl Alcohol: -173 degree F.\n\n";
}
else if (temperature >= OXYGEN_BP && temperature <= ETHYL_ALCOHOL_FP)
{
cout << "\nAt a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to freeze: "
<< "\nOxygen: -362 degree F.\n\n"
<< "At a temperature above " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to freeze: \n"
<< "Ethyl Alcohol: -173 degree F.\n\n"
<< "At a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to boil: "
<< "\nOxygen: -306 degree F.\n\n";
}
else if (temperature == MERCURY_FP)
{
cout << "\nAt a temperature of " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will freeze: \n"
<< "Mercury: -38 degree F.\n\n";
}
else if (temperature >= OXYGEN_BP && temperature <= MERCURY_FP)
{
cout << "\nAt a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to freeze: "
<< "\nOxygen: -362 degree F.\n"
<< "Ethyl Alcohol: -173 degree F.\n\n"
<< "At a temperature above " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to freeze: \n"
<< "Mercury -38 degree F.\n\n"
<< "At a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to boil: "
<< "\nOxygen: -306 degree F.\n\n";
}
else if (temperature == WATER_FP)
{
cout << "\nAt a temperature of " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will freeze: \n"
<< "Water: 32 degree F.\n\n";
}
else if (temperature >= OXYGEN_FP && temperature <= WATER_FP)
{
cout << "\nAt a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to freeze: "
<< "\nOxygen: -362 degree F.\n"
<< "Ethyl Alcohol: -173 degree F.\n"
<< "Mercury: - 38 degree F.\n"
<< "At a temperature above " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to freeze: \n"
<< "Water: 32 degree F.\n\n"
<< "At a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to boil: "
<< "\nOxygen: -306 degree F.\n\n";
}
else if (temperature == ETHYL_ALCOHOL_BP)
{
cout << "\nAt a temperature of " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will boil: \n"
<< "Ethyl Alcohol: 172 degree F.\n\n";
}
else if (temperature >= OXYGEN_FP && temperature <= ETHYL_ALCOHOL_BP)
{
cout << "\nAt a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to freeze: "
<< "\nOxygen: -362 degree F.\n"
<< "Ethyl Alcohol: -173 degree F.\n"
<< "Mercury: - 38 degree F.\n"
<< "Water: 32 degree F.\n\n"
<< "At a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to boil: "
<< "\nOxygen: -306 degree F.\n\n"
<< "At a temperature above " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to boil: "
<< "\nEthyl Alcohol: 172 degree F.\n\n";
}
else if (temperature == WATER_BP)
{
cout << "\nAt a temperature of " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will boil: \n"
<< "Water: 212 degree F.\n\n";
}
else if (temperature >= OXYGEN_BP && temperature <= WATER_BP)
{
cout << "\nAt a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to freeze: "
<< "\nOxygen: -362 degree F.\n"
<< "Ethyl Alcohol: -173 degree F.\n"
<< "Mercury: - 38 degree F.\n"
<< "Water: 32 degree F.\n\n"
<< "At a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to boil: "
<< "\nOxygen: -306 degree F.\n"
<< "\Ethyl Alcohol: 172 degree F.\n\n"
<< "At a temperature above " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to boil: "
<< "\nWater: 212 degree F.\n\n";
}
else if (temperature == MERCURY_BP)
{
cout << "\nAt a temperature of " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will boil: \n"
<< "Mercury: 676 degree F.\n\n";
}
else if (temperature >= OXYGEN_FP && temperature <= MERCURY_BP)
{
cout << "\nAt a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to freeze: "
<< "\nOxygen: -362 degree F.\n"
<< "Ethyl Alcohol: -173 degree F.\n"
<< "Mercury: - 38 degree F.\n"
<< "Water: 32 degree F.\n\n"
<< "At a temperature below " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to boil: "
<< "\nOxygen: -306 degree F.\n"
<< "Ethyl Alcohol: 172 degree F.\n"
<< "Water: 212 degree F.\n\n"
<< "At a temperature above " << temperature << " degree Fahrenheit, "
<< "the following substance(s) will start to boil: "
<< "\nMercury: 676 degree F.\n\n";
}
pauseSystem();
return 0;
}
Friday, November 25, 2016
Programming Challenge 4.22 - Freezing And Boiling Points
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment