Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <vector>
- #include <cmath>
- #include <cctype>
- using namespace std;
- struct Point {
- double x;
- double y;
- string s;
- Point(string s){
- this->s = s;
- x = 0;
- y = 0;
- }
- Point(string s, int x, int y){
- this->s = s;
- this->x = x;
- this->y = y;
- }
- void print(){
- cout << s << ": (" << x << "," << y << ")" << endl;
- }
- void read(){
- cout << s << " taskas, ivesk dvi koordinates: ";
- cin >> x >> y;
- this->s = s;
- }
- double getDistance(Point q){
- double dx = this->x-q.x;
- double dy = this->y-q.y;
- return sqrt(dx*dx + dy*dy);
- }
- };
- int main(){
- Point p1("Pirmas", 1, 2), p2("Antras", 4, 5), p3("Trecias");
- p3.read();
- cout << "Turime tris taskus: " << endl;
- p1.print();
- p2.print();
- p3.print();
- cout << "Atstumas tarp p1 ir p2 yra " << p1.getDistance(p2) << endl;
- cout << "Atstumas tarp p1 ir p3 yra " << p1.getDistance(p3) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement