Skip to content

Instantly share code, notes, and snippets.

@PaulMaynard
Created March 27, 2021 01:40
Show Gist options
  • Save PaulMaynard/b3a412b027728476f6288a2a4eb35d95 to your computer and use it in GitHub Desktop.
Save PaulMaynard/b3a412b027728476f6288a2a4eb35d95 to your computer and use it in GitHub Desktop.
CS410 bonus problem
// 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