Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.24 KB | None | 0 0
  1. /*
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     setlocale(LC_ALL, "russian");
  8.     system("pause");
  9.     return 0;
  10. }
  11. */
  12.    
  13.    
  14.  
  15.     #include <iostream>
  16.     #include <conio.h>
  17.     #include <cmath>
  18.     using namespace std;
  19.      
  20.     class Vector
  21.     {
  22.     private:
  23.             int x;
  24.             int y;
  25.                     int z;
  26.                     float l;
  27.            
  28.     public:
  29.             Vector ()
  30.             {
  31.                      x = 0;
  32.              y = 0;
  33.              z = 0;
  34.              l = 0.0;
  35.                    
  36.             }
  37.             Vector (int vx,int vy, int vz)
  38.             {
  39.                 x=vx;
  40.                 y=vy;
  41.                 z=vz;
  42.                 l = 0.0;
  43.             }
  44.      
  45.             void LengthVector()
  46.             {
  47.                 l = sqrt(pow(static_cast<float>(x), 2) + pow(static_cast<float>(y), 2) + pow(static_cast<float>(z), 2));
  48.             }
  49.      
  50.      
  51.             void showVector()
  52.             {
  53.                     cout<<"(";
  54.                                     cout<<x;
  55.                                     cout<<";";
  56.                                     cout<<y;
  57.                                 cout<<";";
  58.                                     cout<<z;
  59.                                     cout<<")";
  60.                                     cout<<endl;
  61.                                     cout<<"Length of vector [ "<<l<< " ] " << endl;
  62.                     }
  63.      
  64.            
  65.             void showSumVector()
  66.             {
  67.                     cout<<x+y+z<<"";
  68.             }
  69.            
  70.             Vector operator+(Vector);
  71.             Vector operator%(Vector);
  72.             Vector operator*(Vector);
  73.     };
  74.      
  75.     Vector Vector :: operator+ (Vector B)
  76.     {
  77.             Vector tmp;
  78.             tmp.x = x + B.x;
  79.             tmp.y = y + B.y;
  80.             tmp.z = z + B.z;
  81.            
  82.             return tmp;
  83.     }
  84.      
  85.     Vector Vector :: operator% (Vector B)
  86.     {
  87.             Vector tmp;
  88.             tmp.x = x * B.x;
  89.             tmp.y = y * B.y;
  90.             tmp.z = z * B.z;
  91.  
  92.            
  93.             return tmp;
  94.     }
  95.      
  96.     Vector Vector ::operator *(Vector B)
  97.     {
  98.         Vector tmp;
  99.             tmp.x = y*B.z - B.y*z;
  100.             tmp.y = z*B.x-B.z*x;
  101.             tmp.z = x*B.y - B.x*y;
  102.  
  103.             return tmp;
  104.     }
  105.      
  106.      
  107.     int main ()
  108.     {
  109.             setlocale(0,"Rus");
  110.             int x,y,i,j, k, z;
  111.             cout<<"Enter vector a: "<<endl;
  112.             cin >> x>>y>>z;
  113.             cout<<"Enter vector b: "<<endl;
  114.             cin>>i>>j>>k;
  115.             Vector a(x,y,z);
  116.             Vector b(i,j,k);
  117.             a.LengthVector();
  118.             b.LengthVector();
  119.             Vector c = a+b;
  120.             c.LengthVector();
  121.  
  122.             cout<<"Summ a(";a.showVector();
  123.                     cout<<") + b(";b.showVector();
  124.                     cout<<") = c(";c.showVector();
  125.                     cout<<")"<<endl;
  126.            c = a%b;
  127.             cout<<"SPro a(";a.showVector();
  128.                     cout<<") % b(";b.showVector();
  129.                     cout<<") = ";c.showSumVector();
  130.                     cout<<endl;
  131.                c = a*b;
  132.                 cout<<"VPro a(";a.showVector();
  133.                     cout<<")*b(";b.showVector();
  134.                     cout<<")= c(";c.showVector();
  135.                     cout<<")"<<endl;
  136.             cin.get();
  137.             cin.get();
  138.             return 0;
  139.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement