# OOP Lab7

Oct 27th, 2021
690
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <math.h>
3. #include <string>
4. #include <fstream>
5. using namespace std;
6.
7. class Point {
8. private:
9.     int x;
10.     int y;
11.     int z;
12. public:
13.     Point(int x1 = 0,int y1 = 0, int z1 = 0) {
14.         x = x1;
15.         y = y1;
16.         z = z1;
17.     }
18.
19.     int getx() {
20.         return x;
21.     }
22.
23.     int gety() {
24.         return y;
25.     }
26.
27.     int getz() {
28.         return z;
29.     }
30.
31.     friend istream& operator>> (istream& in, Point& point);
32.     friend ostream& operator<< (ostream& out, const Point& point);
33. };
34.
35. ostream& operator<< (ostream& out, const Point& point) {
36.     out << "Point(" << point.x << ", " << point.y << ", " << point.z << ")";
37.     return out;
38. }
39.
40. istream& operator>> (std::istream& in, Point& point)
41. {
42.     in >> point.x;
43.     in >> point.y;
44.     in >> point.z;
45.
46.     return in;
47. }
48.
49. int main() {
50.     cout << "Enter the number of objects: ";
51.     int n;
52.     cin >> n;
53.     Point* point = new Point[n];
54.     /*for (int idx = 0; idx < n; idx++) {
55.         cout << "Enter coordinates of point (3 nums):\n";
56.         cin >> point[idx];
57.     }
58.     for (int idx = 0; idx < n; idx++)
59.         cout << point[idx] << "\n";*/
60.
61.     ifstream in("input.txt");
62.     ofstream out("output.txt");
63.     for (int idx = 0; idx < n; idx++)
64.         in >> point[idx];
65.     for (int idx = 0; idx < n; idx++)
66.         out << point[idx] << "\n";
67. }
68.
RAW Paste Data