Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication7.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include "pch.h"
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <algorithm>
- #include <string>
- #include <numeric>
- using namespace std;
- class GCords {
- private:
- double width;
- double length;
- public:
- GCords () {
- width = 0.0;
- length = 0.0;
- }
- GCords(double g_width, double g_length) {
- width = g_width;
- length = g_length;
- }
- GCords(const GCords& obj) {
- this->width = obj.width;
- this->length = obj.length;
- }
- double GetWidth() { return this->width; }
- double GetLength() { return this->length; }
- void SetWidth(double width) { this->width = width; }
- void SetLength(double length) { this->length = length; }
- double Distance() {
- return width * width + length * length;
- }
- GCords operator+(const GCords obj) {
- GCords cord1;
- cord1.SetWidth(this->width + obj.width);
- cord1.SetLength(this->length + obj.length);
- return cord1;
- }
- bool operator==(const GCords obj) {
- if (this->length == obj.length && this->width == obj.width)
- {
- return true;
- }
- return false;
- }
- bool operator<(const GCords obj) {
- if (this->length < obj.length && this->width < obj.width)
- {
- return true;
- }
- return false;
- }
- friend istream& operator>>(istream& input, GCords& obj) {
- input >> obj.length;
- input >> obj.width;
- return input;
- }
- friend ostream& operator<< (ostream& output, GCords& obj) {
- output << obj.length;
- output << obj.width;
- return output;
- }
- };
- class Student {
- private:
- string name;
- vector <GCords> cords;
- public:
- Student() {}
- Student(string fname) {
- fstream asd(fname);
- asd >> name;
- while (!asd.eof()) {
- double value1,value2;
- asd >> value1 >> value2;
- cords.push_back(GCords(value1, value2));
- }
- }
- string GetName() {return name;}
- vector <GCords> GetCords() { return cords;}
- double sumDistance() {
- //return accumulate(cords.begin(), cords.end(), 0.0);
- }
- friend istream& operator>>(istream& input, Student& obj) {
- input >> obj.name;
- //input >> obj.cords;
- return input;
- }
- friend ostream& operator<<(ostream& output, const Student& obj) {
- output << obj.name;
- for (auto element : obj.cords) {
- output << element;
- }
- return output;
- }
- };
- int main()
- {
- try {
- GCords tochka1(-10.0, 6.0);
- GCords tochka2(-6.0, 10.0);
- GCords tochka3 = tochka1 + tochka2;
- Student student("C:\\Users\\my\\source\\repos\\ConsoleApplication7\\Debug\\test.txt");
- cout << student;
- }
- catch(exception err){
- }
- }
- // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
- // Debug program: F5 or Debug > Start Debugging menu
- // Tips for Getting Started:
- // 1. Use the Solution Explorer window to add/manage files
- // 2. Use the Team Explorer window to connect to source control
- // 3. Use the Output window to see build output and other messages
- // 4. Use the Error List window to view errors
- // 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
- // 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