Thursday, April 18, 2013

Write a C++ program that can print a temperature conversion


This program prints out a conversion table of temperatures, after
prompting the user for upper and lower bounds of the table in Fahrenheit, 
and the temperature difference between table entries


#include <iostream>
#include <iomanip>
using namespace std;

double celsius_of(int fahr);
double absolute_value_of(int fahr);

void print_preliminary_message();
void input_table_specifications(int& lowest_entry, int& highest_entry, int& step_size);
void print_message_echoing_input(int lowest_entry, int highest_entry, int step_size); 
void print_table(int lowest_entry, int highest_entry, int step_size); 

/* START OF MAIN PROGRAM */
int main() 
{ 
 int lower = 0;  /* for the lowest Fahrenheit entry in the table */
 int upper = 0;  /* for the highest Fahrenheit entry in the table */
 int step = 1;   /* for the difference in Fahrenheit between entries */

 /* set the tabbing functions in iostream.h to left-justify */
 cout << setiosflags (ios::left);

 /* print a message explaining what the program does: */
 print_preliminary_message();

 /* prompt the user for table specifications in Fahrenheit: */
 input_table_specifications(lower, upper, step);
 
 /* print an appropriate message including an echo of the input: */
 print_message_echoing_input(lower, upper, step);
 
 /* Print the table (including the column headings): */
 print_table(lower, upper, step);
 
 return 0;
}
/* END OF MAIN PROGRAM */


/* FUNCTION TO CONVERT FAHRENHEIT TO CELSIUS */
double celsius_of(int fahr)
{
 return (static_cast<double>(5)/9) * (fahr - 32);
}
/* END OF FUNCTION */
 

/* FUNCTION TO CONVERT FAHRENHEIT TO ABSOLUTE VALUE */
double absolute_value_of(int fahr)
{
 return ((static_cast<double>(5)/9) * (fahr - 32)) + 273.15;
}
/* END OF FUNCTION */
 

/* START OF FUNCTION */
void print_preliminary_message()
{
 cout << "This program prints out a conversion table of temperatures." << endl << endl;
}
/* END OF FUNCTION */ 
 

/* START OF FUNCTION */
void input_table_specifications(int& lowest_entry, int& highest_entry, int& step_size)
{
 cout << "Enter the minimum (whole number) temperature" << endl;
 cout << "you want in the table, in Fahrenheit: ";
 cin >> lowest_entry;
 cout << "Enter the maximum temperature you want in the table: ";
 cin >> highest_entry;
 cout << "Enter the temperature difference you want between table entries: ";
 cin >> step_size;
 cout << endl << endl;
}
/* END OF FUNCTION */
 

/* START OF FUNCTION */
void print_message_echoing_input(int lowest_entry, int highest_entry, int step_size)
{
 cout << "Tempertature conversion table from " << lowest_entry << " Fahrenheit" << endl;
 cout << "to " << highest_entry << " Fahrenheit, in steps of ";
 cout << step_size << " Fahrenheit:" << endl << endl;
}
/* END OF FUNCTION */
 

/* START OF FUNCTION */
void print_table(int lowest_entry, int highest_entry, int step_size)
{
 int fahr; 

 /* Print table heading */
 cout.width(17);
 cout << "Fahrenheit";
 cout.width(13);
 cout << "Celsius" << "Absolute Value" << endl << endl;

 /* set format of individual values */
 cout.precision(2); 
 cout.setf(ios::fixed); 

 /* print table from lowest_entry to highest_entry */
 for (fahr = lowest_entry ; fahr <= highest_entry ; fahr += step_size) {
  cout << "   ";
  cout.width(15);
  cout << fahr;
  cout.width(15);
  cout << celsius_of(fahr) << absolute_value_of(fahr) << endl;
 }
}
/* END OF FUNCTION */


OUTPUT:
This program prints out a conversion table of temperatures.

Enter the minimum (whole number) temperature
you want in the table, in Fahrenheit: 5
Enter the maximum temperature you want in the table: 55
Enter the temperature difference you want between table entries: 5


Tempertature conversion table from 5 Fahrenheit
to 55 Fahrenheit, in steps of 5 Fahrenheit:

Fahrenheit       Celsius      Absolute Value

   5              -15.00         258.15
   10             -12.22         260.93
   15             -9.44          263.71
   20             -6.67          266.48
   25             -3.89          269.26
   30             -1.11          272.04
   35             1.67           274.82
   40             4.44           277.59
   45             7.22           280.37
   50             10.00          283.15
   55             12.78          285.93


---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
--------------------------------------------------
Temperature Conversion - C And C++ C program of Temperature conversion Celsius to Fahrenheit Temperature Conversion Table (with step size) The formula for converting centigrade temperatures to Fahrenheit How to Create a Temperature Conversion Function Celsius Temperature Table Temperature Program - C And C++‎ Temperature Converter Celsius-to-Fahrenheit Conversion - C And C++

IT Certification Category (English)640x480

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Top Online Courses From ProgrammingKnowledge

Python Course http://bit.ly/2vsuMaS
Java Coursehttp://bit.ly/2GEfQMf
Bash Coursehttp://bit.ly/2DBVF0C
Linux Coursehttp://bit.ly/2IXuil0
C Course http://bit.ly/2GQCiD1
C++ Coursehttp://bit.ly/2V4oEVJ
PHP Coursehttp://bit.ly/2XP71WH
Android Coursehttp://bit.ly/2UHih5H
C# Coursehttp://bit.ly/2Vr7HEl
JavaFx Coursehttp://bit.ly/2XMvZWA
NodeJs Coursehttp://bit.ly/2GPg7gA
Jenkins Course http://bit.ly/2Wd4l4W
Scala Coursehttp://bit.ly/2PysyA4
Bootstrap Coursehttp://bit.ly/2DFQ2yC
MongoDB Coursehttp://bit.ly/2LaCJfP
QT C++ GUI Coursehttp://bit.ly/2vwqHSZ