Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- #include <iostream>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "russian");
- system("pause");
- return 0;
- }
- */
- #include <iostream>
- #include <conio.h>
- #include <cmath>
- using namespace std;
- class Vector
- {
- private:
- int x;
- int y;
- int z;
- float l;
- public:
- Vector ()
- {
- x = 0;
- y = 0;
- z = 0;
- l = 0.0;
- }
- Vector (int vx,int vy, int vz)
- {
- x=vx;
- y=vy;
- z=vz;
- l = 0.0;
- }
- void LengthVector()
- {
- l = sqrt(pow(static_cast<float>(x), 2) + pow(static_cast<float>(y), 2) + pow(static_cast<float>(z), 2));
- }
- void showVector()
- {
- cout<<"(";
- cout<<x;
- cout<<";";
- cout<<y;
- cout<<";";
- cout<<z;
- cout<<")";
- cout<<endl;
- cout<<"Length of vector [ "<<l<< " ] " << endl;
- }
- void showSumVector()
- {
- cout<<x+y+z<<"";
- }
- Vector operator+(Vector);
- Vector operator%(Vector);
- Vector operator*(Vector);
- };
- Vector Vector :: operator+ (Vector B)
- {
- Vector tmp;
- tmp.x = x + B.x;
- tmp.y = y + B.y;
- tmp.z = z + B.z;
- return tmp;
- }
- Vector Vector :: operator% (Vector B)
- {
- Vector tmp;
- tmp.x = x * B.x;
- tmp.y = y * B.y;
- tmp.z = z * B.z;
- return tmp;
- }
- Vector Vector ::operator *(Vector B)
- {
- Vector tmp;
- tmp.x = y*B.z - B.y*z;
- tmp.y = z*B.x-B.z*x;
- tmp.z = x*B.y - B.x*y;
- return tmp;
- }
- int main ()
- {
- setlocale(0,"Rus");
- int x,y,i,j, k, z;
- cout<<"Enter vector a: "<<endl;
- cin >> x>>y>>z;
- cout<<"Enter vector b: "<<endl;
- cin>>i>>j>>k;
- Vector a(x,y,z);
- Vector b(i,j,k);
- a.LengthVector();
- b.LengthVector();
- Vector c = a+b;
- c.LengthVector();
- cout<<"Summ a(";a.showVector();
- cout<<") + b(";b.showVector();
- cout<<") = c(";c.showVector();
- cout<<")"<<endl;
- c = a%b;
- cout<<"SPro a(";a.showVector();
- cout<<") % b(";b.showVector();
- cout<<") = ";c.showSumVector();
- cout<<endl;
- c = a*b;
- cout<<"VPro a(";a.showVector();
- cout<<")*b(";b.showVector();
- cout<<")= c(";c.showVector();
- cout<<")"<<endl;
- cin.get();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement