Created
March 27, 2021 01:40
-
-
Save PaulMaynard/b3a412b027728476f6288a2a4eb35d95 to your computer and use it in GitHub Desktop.
CS410 bonus problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// my first program in C++ | |
#include <iostream> | |
using namespace std; | |
class Converter | |
{ | |
private: | |
Converter(){}; | |
public: | |
float fromFtoC(float); | |
float fromCtoF(float); | |
static Converter *getInstance() | |
{ | |
static Converter instance; | |
return &instance; | |
} | |
}; | |
float Converter::fromFtoC(float farenheit) | |
{ | |
return (farenheit - 32) * 5. / 9.; | |
} | |
float Converter::fromCtoF(float celsius) | |
{ | |
return 9. / 5. * celsius + 32; | |
} | |
int main() | |
{ | |
float farenheit; | |
cout << "Please enter a temperature: "; | |
cin >> farenheit; | |
Converter *c = Converter::getInstance(); | |
float celsius = c->fromFtoC(farenheit); | |
cout << "Converted to Celsius, this temperature is " << celsius << "!\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment