Advertisement
Garey

Untitled

Jan 18th, 2020
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. // ConsoleApplication7.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. #include <vector>
  7. #include <fstream>
  8. #include <algorithm>
  9.  
  10. using namespace std;
  11.  
  12. class GCords {
  13. private:
  14.     double width;
  15.     double length;
  16. public:
  17.     GCords () {}
  18.     GCords(double g_width, double g_length) {
  19.         width = g_width;
  20.         length = g_length;
  21.     }
  22.  
  23.     GCords(const GCords& obj) {
  24.         this->width = obj.width;
  25.         this->length = obj.length;
  26.        
  27.     }
  28.  
  29.     double GetWidth() { return this->width; }
  30.     double GetLength() { return this->length; }
  31.  
  32.     void SetWidth(double width) { this->width = width; }
  33.     void SetLength(double length) { this->length = length; }
  34.  
  35.     double Distance() {
  36.         return width * width + length * length;
  37.  
  38.     }
  39.  
  40.     GCords operator+(const GCords obj) {
  41.         GCords cord1;
  42.         cord1.SetWidth(this->width + obj.width);
  43.         cord1.SetLength(this->length + obj.length);
  44.         return cord1;
  45.     }
  46.  
  47.     bool operator==(const GCords obj) {
  48.         if (this->length == obj.length && this->width == obj.width)
  49.         {
  50.             return true;
  51.         }
  52.         return false;
  53.     }
  54.     bool operator<(const GCords obj) {
  55.         if (this->length < obj.length && this->width < obj.width)
  56.         {
  57.             return true;
  58.         }
  59.         return false;
  60.     }
  61.  
  62.     friend istream& operator>>(istream& input, GCords& obj) {
  63.        
  64.         input >> obj.length;
  65.         input >> obj.width;
  66.         return input;
  67.     }
  68.  
  69.     friend ostream& operator<< (ostream& output, GCords& obj) {
  70.         output << obj.length;
  71.         output << obj.width;
  72.         return output;
  73.  
  74.     }
  75.  
  76.            
  77.    
  78.  
  79.  
  80.  
  81. };
  82. int main()
  83. {
  84.     GCords tochka1(-10.0,6.0);
  85.     GCords tochka2(-6.0, 10.0);
  86.     GCords tochka3 = tochka1 + tochka2;
  87.  
  88.     cout << tochka3.Distance();
  89.     std::cout << "Hello World!\n";
  90. }
  91.  
  92. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  93. // Debug program: F5 or Debug > Start Debugging menu
  94.  
  95. // Tips for Getting Started:
  96. //   1. Use the Solution Explorer window to add/manage files
  97. //   2. Use the Team Explorer window to connect to source control
  98. //   3. Use the Output window to see build output and other messages
  99. //   4. Use the Error List window to view errors
  100. //   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
  101. //   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement