Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <fstream>
- using namespace std;
- class Vector {
- double x,y;
- char *fname;
- public:
- Vector(double,double);
- Vector();
- void print();
- double abs();
- Vector(char *);
- void save(char *);
- void add(Vector &);
- };
- Vector::Vector(double x, double y) {
- this->x = x;
- this->y = y;
- }
- Vector::Vector() {
- cin >> x >> y;
- }
- void Vector::print() {
- cout << "(" << x << "," << y << ")";
- }
- double Vector::abs() {
- return sqrt(x*x+y*y);
- }
- Vector::Vector(char *fname){
- ifstream i(fname);
- i>>x>>y;
- i.close();
- }
- void Vector::save(char *fname){
- ofstream o(fname);
- o<<x<<' '<<y;
- o.close();
- }
- void Vector::add(Vector &vek){
- x+=vek.x;
- y+=vek.y;
- }
- int main(int argc, char** argv) {
- Vector *v = new Vector();
- v->print();
- cout << v->abs();
- v->save("vector.txt");
- delete v;
- Vector *v2=new Vector("vector.txt");
- v2->print();
- Vector v3(4,5);
- v2->add(v3);
- v2->print();
- delete v2;
- //Vector v;
- //v.print();
- //cout << v.abs();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement