Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- class CelsiusDeg {
- public:
- double value;
- CelsiusDeg() {
- value = 0;
- }
- CelsiusDeg(double value) {
- this->value = value;
- }
- CelsiusDeg operator +(const CelsiusDeg & c) {
- return double(this->value + c.value);
- }
- CelsiusDeg operator -(const CelsiusDeg & c) {
- return double(this->value - c.value);
- }
- };
- class Kelvin {
- public:
- double value;
- Kelvin() {
- value = -273;
- }
- Kelvin(double value) {
- this->value = value;
- }
- Kelvin operator +(const Kelvin & c) {
- return double(this->value + c.value);
- }
- Kelvin operator -(const Kelvin & c) {
- return double(this->value - c.value);
- }
- };
- std::ostream& operator << (std::ostream &stream, const CelsiusDeg &celsiusDeg) {
- return stream << celsiusDeg.value;
- }
- std::ostream& operator << (std::ostream &stream, const Kelvin &kelvin) {
- return stream << kelvin.value;
- }
- double operator + (const Kelvin &kelvin, const CelsiusDeg &celcius) {
- return double(kelvin.value + celcius.value);
- }
- double operator - (const Kelvin &kelvin, const CelsiusDeg &celcius) {
- return double(kelvin.value - celcius.value);
- }
- void coutEndl() {
- std::cout << std::endl;
- }
- int main() {
- uint8_t stop;
- CelsiusDeg celciusDeg1;
- CelsiusDeg celciusDeg2(20);
- Kelvin kelvin1;
- Kelvin kelvin2(10);
- std::string celciusScale = " [deg C] ";
- std::string kelvinScale = " [deg K] ";
- std::cout << celciusDeg1 << celciusScale << "+ " << celciusDeg2 << celciusScale << "= " << celciusDeg1 + celciusDeg2 << celciusScale << std::endl;
- std::cout << celciusDeg1 << celciusScale << "- " << celciusDeg2 << celciusScale << "= " << celciusDeg1 - celciusDeg2 << celciusScale << std::endl;
- coutEndl();
- std::cout << kelvin1 << kelvinScale << "+ " << kelvin2 << kelvinScale << "= " << kelvin1 + kelvin2 << kelvinScale << std::endl;
- std::cout << kelvin1 << kelvinScale << "- " << kelvin2 << kelvinScale << "= " << kelvin1 - kelvin2 << kelvinScale << std::endl;
- coutEndl();
- std::cout << kelvin1 << kelvinScale << "+ " << celciusDeg2 << celciusScale << "= " << kelvin1 + celciusDeg2 << std::endl;
- std::cout << kelvin1 << kelvinScale << "- " << celciusDeg2 << celciusScale << "= " << kelvin1 - celciusDeg2 << std::endl;
- coutEndl();
- std::cout << kelvin2 << kelvinScale << "+ " << celciusDeg1 << celciusScale << "= " << kelvin2 + celciusDeg1 << std::endl;
- std::cout << kelvin2 << kelvinScale << "- " << celciusDeg1 << celciusScale << "= " << kelvin2 - celciusDeg1 << std::endl;
- std::cin >> stop;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement