Advertisement
szdani96

Untitled

Oct 2nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. class Vector {
  7. double x,y;
  8.  
  9. char *fname;
  10. public:
  11. Vector(double,double);
  12. Vector();
  13. void print();
  14. double abs();
  15. Vector(char *);
  16. void save(char *);
  17. void add(Vector &);
  18. };
  19.  
  20. Vector::Vector(double x, double y) {
  21. this->x = x;
  22. this->y = y;
  23. }
  24.  
  25. Vector::Vector() {
  26. cin >> x >> y;
  27. }
  28.  
  29. void Vector::print() {
  30. cout << "(" << x << "," << y << ")";
  31. }
  32.  
  33. double Vector::abs() {
  34. return sqrt(x*x+y*y);
  35. }
  36. Vector::Vector(char *fname){
  37. ifstream i(fname);
  38. i>>x>>y;
  39. i.close();
  40. }
  41. void Vector::save(char *fname){
  42. ofstream o(fname);
  43. o<<x<<' '<<y;
  44. o.close();
  45. }
  46. void Vector::add(Vector &vek){
  47. x+=vek.x;
  48. y+=vek.y;
  49. }
  50. int main(int argc, char** argv) {
  51. Vector *v = new Vector();
  52. v->print();
  53. cout << v->abs();
  54. v->save("vector.txt");
  55.  
  56. delete v;
  57. Vector *v2=new Vector("vector.txt");
  58. v2->print();
  59. Vector v3(4,5);
  60. v2->add(v3);
  61. v2->print();
  62. delete v2;
  63. //Vector v;
  64. //v.print();
  65. //cout << v.abs();
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement