Advertisement
Garey

primernoOOP

Jan 25th, 2020
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 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. #include <string>
  10. #include <numeric>
  11.  
  12. using namespace std;
  13.  
  14. class GCords {
  15. private:
  16. double width;
  17. double length;
  18. public:
  19. GCords () {
  20. width = 0.0;
  21. length = 0.0;
  22. }
  23. GCords(double g_width, double g_length) {
  24. width = g_width;
  25. length = g_length;
  26. }
  27.  
  28. GCords(const GCords& obj) {
  29. this->width = obj.width;
  30. this->length = obj.length;
  31.  
  32. }
  33.  
  34. double GetWidth() { return this->width; }
  35. double GetLength() { return this->length; }
  36.  
  37. void SetWidth(double width) { this->width = width; }
  38. void SetLength(double length) { this->length = length; }
  39.  
  40. double Distance() {
  41. return width * width + length * length;
  42.  
  43. }
  44.  
  45. GCords operator+(const GCords obj) {
  46. GCords cord1;
  47. cord1.SetWidth(this->width + obj.width);
  48. cord1.SetLength(this->length + obj.length);
  49. return cord1;
  50. }
  51.  
  52. bool operator==(const GCords obj) {
  53. if (this->length == obj.length && this->width == obj.width)
  54. {
  55. return true;
  56. }
  57. return false;
  58. }
  59. bool operator<(const GCords obj) {
  60. if (this->length < obj.length && this->width < obj.width)
  61. {
  62. return true;
  63. }
  64. return false;
  65. }
  66.  
  67. friend istream& operator>>(istream& input, GCords& obj) {
  68.  
  69. input >> obj.length;
  70. input >> obj.width;
  71. return input;
  72. }
  73.  
  74. friend ostream& operator<< (ostream& output, GCords& obj) {
  75. output << obj.length;
  76. output << obj.width;
  77. return output;
  78.  
  79. }
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. };
  87.  
  88. class Student {
  89. private:
  90. string name;
  91. vector <GCords> cords;
  92.  
  93. public:
  94.  
  95. Student() {}
  96. Student(string fname) {
  97. fstream asd(fname);
  98.  
  99.  
  100. asd >> name;
  101.  
  102.  
  103. while (!asd.eof()) {
  104. double value1,value2;
  105.  
  106. asd >> value1 >> value2;
  107.  
  108. cords.push_back(GCords(value1, value2));
  109.  
  110. }
  111. }
  112.  
  113. string GetName() {return name;}
  114. vector <GCords> GetCords() { return cords;}
  115.  
  116. double sumDistance() {
  117. //return accumulate(cords.begin(), cords.end(), 0.0);
  118. }
  119.  
  120. friend istream& operator>>(istream& input, Student& obj) {
  121. input >> obj.name;
  122. //input >> obj.cords;
  123. return input;
  124. }
  125.  
  126. friend ostream& operator<<(ostream& output, const Student& obj) {
  127. output << obj.name;
  128. for (auto element : obj.cords) {
  129. output << element;
  130. }
  131.  
  132. return output;
  133. }
  134. };
  135. int main()
  136. {
  137. try {
  138. GCords tochka1(-10.0, 6.0);
  139. GCords tochka2(-6.0, 10.0);
  140. GCords tochka3 = tochka1 + tochka2;
  141. Student student("C:\\Users\\my\\source\\repos\\ConsoleApplication7\\Debug\\test.txt");
  142.  
  143. cout << student;
  144. }
  145. catch(exception err){
  146.  
  147. }
  148.  
  149.  
  150.  
  151. }
  152.  
  153. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  154. // Debug program: F5 or Debug > Start Debugging menu
  155.  
  156. // Tips for Getting Started:
  157. // 1. Use the Solution Explorer window to add/manage files
  158. // 2. Use the Team Explorer window to connect to source control
  159. // 3. Use the Output window to see build output and other messages
  160. // 4. Use the Error List window to view errors
  161. // 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
  162. // 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