Last active
December 14, 2019 15:22
-
-
Save M1nified/c1175005760a0ad31ddc394d2d069ed9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Zaj3.cpp : This file contains the 'main' function. Program execution begins and ends there. | |
// | |
#include "pch.h" | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
class CelsiusDeg; | |
class Kelvin; | |
class CelsiusDeg { | |
double value = 0; | |
CelsiusDeg(double value) { | |
this->value = value; | |
} | |
public: | |
CelsiusDeg() { | |
} | |
CelsiusDeg operator + (const CelsiusDeg & x) { | |
return CelsiusDeg(this->value + x.value); | |
} | |
CelsiusDeg operator - (const CelsiusDeg & x) { | |
return CelsiusDeg(this->value - x.value); | |
} | |
CelsiusDeg & operator = (const CelsiusDeg & x) { | |
value = x.value; | |
return *this; | |
} | |
CelsiusDeg & operator =(double x) | |
{ | |
value = x; | |
return *this; | |
} | |
friend std::ostream & operator <<(std::ostream & os, const CelsiusDeg & i) | |
{ | |
os << i.value; | |
return os; | |
} | |
friend std::ostream & operator <<(std::ostream & os, CelsiusDeg & i) | |
{ | |
os << i.value; | |
return os; | |
} | |
friend std::istream & operator >>(std::istream & os, CelsiusDeg & i) | |
{ | |
os >> i.value; | |
return os; | |
} | |
//operator const Kelvin(){ | |
// Kelvin k; | |
// k = value - 273.15; | |
// return k; | |
//} | |
operator double() { | |
return value; | |
} | |
}; | |
class Kelvin { | |
double value = 0; | |
Kelvin(double value) { | |
this->value = value; | |
} | |
public: | |
Kelvin() { | |
} | |
Kelvin operator + (const Kelvin & x) { | |
return Kelvin(this->value + x.value); | |
} | |
Kelvin operator - (const Kelvin & x) { | |
return Kelvin(this->value - x.value); | |
} | |
Kelvin & operator = (const Kelvin & x) { | |
value = x.value; | |
return *this; | |
} | |
Kelvin & operator =(double x) | |
{ | |
value = x; | |
return *this; | |
} | |
friend std::ostream & operator <<(std::ostream & os, const Kelvin & i) | |
{ | |
os << i.value; | |
return os; | |
} | |
friend std::ostream & operator <<(std::ostream & os, Kelvin & i) | |
{ | |
os << i.value; | |
return os; | |
} | |
friend std::istream & operator >>(std::istream & os, Kelvin & i) | |
{ | |
os >> i.value; | |
return os; | |
} | |
operator const CelsiusDeg() { | |
CelsiusDeg k; | |
k = value + 273.15; | |
return k; | |
} | |
operator double() { | |
return value; | |
} | |
}; | |
int main() | |
{ | |
std::cout << "Hello World!\n"; | |
CelsiusDeg c1, c2; | |
Kelvin k1, k2; | |
c2 = 5.0; | |
k2 = 55.0; | |
cout << c2 << endl; | |
std::cout << (c1 + c2) << std::endl; | |
std::cout << (c1 - c2) << std::endl; | |
std::cout << (k1 + k2) << std::endl; | |
std::cout << (k1 - k2) << std::endl; | |
std::cout << (c1 + k2) << std::endl; | |
std::cout << (c2 - k1) << std::endl; | |
std::cout << (k2 + c1) << std::endl; | |
std::cout << (k1 - k2) << std::endl; | |
} | |
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu | |
// Debug program: F5 or Debug > Start Debugging menu | |
// Tips for Getting Started: | |
// 1. Use the Solution Explorer window to add/manage files | |
// 2. Use the Team Explorer window to connect to source control | |
// 3. Use the Output window to see build output and other messages | |
// 4. Use the Error List window to view errors | |
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project | |
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment