Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4.  
  5. class CelsiusDeg {
  6.  
  7.  
  8. public:
  9.  
  10. double value;
  11.  
  12. CelsiusDeg() {
  13. value = 0;
  14. }
  15.  
  16. CelsiusDeg(double value) {
  17. this->value = value;
  18. }
  19.  
  20. CelsiusDeg operator +(const CelsiusDeg & c) {
  21. return double(this->value + c.value);
  22. }
  23.  
  24. CelsiusDeg operator -(const CelsiusDeg & c) {
  25. return double(this->value - c.value);
  26. }
  27. };
  28.  
  29. class Kelvin {
  30.  
  31.  
  32. public:
  33.  
  34. double value;
  35.  
  36. Kelvin() {
  37. value = -273;
  38. }
  39.  
  40. Kelvin(double value) {
  41. this->value = value;
  42. }
  43.  
  44. Kelvin operator +(const Kelvin & c) {
  45. return double(this->value + c.value);
  46. }
  47.  
  48. Kelvin operator -(const Kelvin & c) {
  49. return double(this->value - c.value);
  50. }
  51.  
  52. };
  53.  
  54.  
  55. std::ostream& operator << (std::ostream &stream, const CelsiusDeg &celsiusDeg) {
  56. return stream << celsiusDeg.value;
  57. }
  58.  
  59. std::ostream& operator << (std::ostream &stream, const Kelvin &kelvin) {
  60. return stream << kelvin.value;
  61. }
  62.  
  63. double operator + (const Kelvin &kelvin, const CelsiusDeg &celcius) {
  64. return double(kelvin.value + celcius.value);
  65. }
  66.  
  67. double operator - (const Kelvin &kelvin, const CelsiusDeg &celcius) {
  68. return double(kelvin.value - celcius.value);
  69. }
  70.  
  71.  
  72. void coutEndl() {
  73. std::cout << std::endl;
  74. }
  75.  
  76. int main() {
  77. uint8_t stop;
  78.  
  79. CelsiusDeg celciusDeg1;
  80. CelsiusDeg celciusDeg2(20);
  81. Kelvin kelvin1;
  82. Kelvin kelvin2(10);
  83. std::string celciusScale = " [deg C] ";
  84. std::string kelvinScale = " [deg K] ";
  85.  
  86. std::cout << celciusDeg1 << celciusScale << "+ " << celciusDeg2 << celciusScale << "= " << celciusDeg1 + celciusDeg2 << celciusScale << std::endl;
  87. std::cout << celciusDeg1 << celciusScale << "- " << celciusDeg2 << celciusScale << "= " << celciusDeg1 - celciusDeg2 << celciusScale << std::endl;
  88.  
  89. coutEndl();
  90.  
  91. std::cout << kelvin1 << kelvinScale << "+ " << kelvin2 << kelvinScale << "= " << kelvin1 + kelvin2 << kelvinScale << std::endl;
  92. std::cout << kelvin1 << kelvinScale << "- " << kelvin2 << kelvinScale << "= " << kelvin1 - kelvin2 << kelvinScale << std::endl;
  93.  
  94. coutEndl();
  95.  
  96. std::cout << kelvin1 << kelvinScale << "+ " << celciusDeg2 << celciusScale << "= " << kelvin1 + celciusDeg2 << std::endl;
  97. std::cout << kelvin1 << kelvinScale << "- " << celciusDeg2 << celciusScale << "= " << kelvin1 - celciusDeg2 << std::endl;
  98.  
  99. coutEndl();
  100.  
  101. std::cout << kelvin2 << kelvinScale << "+ " << celciusDeg1 << celciusScale << "= " << kelvin2 + celciusDeg1 << std::endl;
  102. std::cout << kelvin2 << kelvinScale << "- " << celciusDeg1 << celciusScale << "= " << kelvin2 - celciusDeg1 << std::endl;
  103.  
  104.  
  105. std::cin >> stop;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement