Coe

  • July 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Coe as PDF for free.

More details

  • Words: 426
  • Pages: 2
#include #include #include #include using namespace std; // Global variables double celsius; double kelvin; double fahrenheit; // Class encapsulates temperature converter class Temperature { public: void converter(char choise); void showmenu(); bool isvalid(char ch); }; // Display the converter void Temperature::converter(char choise) { switch(choise) { case '1': cout << "Enter the temperature in Celsius: "; cin >> celsius; fahrenheit = (celsius * 1,8) + 32; cout << celsius << " Celsius = " << fahrenheit << " Fahrenheit.\n\n"; break; case '2': cout << "Enter the temperature in Fahrenheit: "; cin >> fahrenheit; celsius = (fahrenheit - 32) * (5 / 9); cout << fahrenheit << " Fahrenheit = " << celsius << " Celsius.\n\n"; break; case '3': cout << "Enter temperature in Kelvin: "; cin >> kelvin; fahrenheit = (kelvin * 1,8) - 459,67; cout << kelvin << " Kelvin = " << fahrenheit << " Fahrenheit.\n\n"; break; case '4': cout << "Enter temperature in Fahrenheit: "; cin >> fahrenheit; kelvin = (fahrenheit + 459,67) * (5 / 9); cout << fahrenheit << " Fahrenheit = " << kelvin << " Kelvin.\n\n"; break; case '5': cout << "Enter temperature in Celsius: "; cin >> celsius; kelvin = celsius - 273,3; cout << celsius << " Celsius = " << kelvin << " Kelvin.\n\n"; break; case '6': cout << "Enter temperature in Kelvin: "; cin >> kelvin; celsius = kelvin + 273,3; cout << kelvin << " Kelvin - " << celsius << " Celsius.\n\n";

break; }; // End of switch }; //End of converter part void Temperature::showmenu() { cout << "This program can be used to convert temperatures. "; cout << "Choose one of the following\nconversions. Typ only the number corresponding to the conversion.\n\n"; cout << "1. Celsius -> Fahrenheit\n"; cout << "2. Fahrenheit -> Celsius\n"; cout << "3. Kelvin -> Fahrenheit\n"; cout << "4. Fahrenheit -> Kelvin\n"; cout << "5. Celsius -> Kelvin\n"; cout << "6. Kelvin -> Celsius\n\n"; cout << "To exit the program press 'q'\n"; } // Return true if choise is valid. bool Temperature::isvalid(char ch) { if (ch < '1' || ch > '6' && ch != 'q') return false; else return true; } //end of isvalid part // Start main function int main() { char choise; Temperature tmpob; // Create an instance of the Temperature class. // Use the temperature object to display information. for(;;) { do { tmpob.showmenu(); cout << "Type your choise: "; cin >> choise; } while(!tmpob.isvalid(choise)); // While isvalid returns true. if (choise == 'q') break; cout << "\n";

}

tmpob.converter(choise); } return 0;

Related Documents

Coe
July 2020 18
Coe-lyndon.docx
April 2020 11
Coe Place
November 2019 11
Coe Party
July 2020 9
Proyecto Coe
November 2019 15
02268-coe
October 2019 11