Advertisement
steverobinson

Scalar Product

Oct 12th, 2010
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. /*      Scalar Product        */
  2. /*       Language: C++        */
  3.  
  4.  
  5.  
  6. #include <iostream.h>
  7. #include <conio.h>
  8.  
  9. template <class type>
  10. class vector
  11. {
  12.     type a,b,c;
  13.  
  14.     public:
  15.        /* vector()
  16.         {
  17.             seconds=minute=hour=0;
  18.         }*/
  19.  
  20.         vector(type ta,type tb,type tc)
  21.         {
  22.            a = ta;
  23.            b=tb;
  24.            c=tc;
  25.         }
  26.  
  27.         type scalar_product(vector& vct1)
  28.         {
  29.             type result=(a*vct1.a)+(b*vct1.b)+(c*vct1.c);
  30.             return result;
  31.         }
  32. };
  33.  
  34.  
  35. int main()
  36. {
  37.     system("cls");
  38.  
  39.         /**********************************  Int  Vectors ****************************************/
  40.  
  41.  
  42.     int a,b,c;
  43.  
  44.     cout<<"\nEnter Vector 1 of Integer Type( (a)i / (b)j / (c)k ) : \n";
  45.     cin>>a>>b>>c;
  46.     cout<<"\nGiven Vector is: "<<a<<"i+"<<b<<"j+"<<c<<"k\n";
  47.     vector  <int> vct_int_1 (a,b,c);
  48.  
  49.     cout<<"\nEnter Vector 2 of Integer Type( (a)i / (b)j / (c)k ) : \n";
  50.     cin>>a>>b>>c;
  51.     cout<<"\nGiven Vector is: "<<a<<"i+"<<b<<"j+"<<c<<"k\n";
  52.     vector <int> vct_int_2 (a,b,c);
  53.  
  54.     int pdt_int;
  55.     cout<<"\nScalar Product of the Given two Integer Vectors is: "<<vct_int_1.scalar_product(vct_int_2);
  56.  
  57.     /**********************************  Float Vectors ****************************************/
  58.  
  59.     float d,e,f;
  60.  
  61.     cout<<"\n\n\nEnter Vector 1 of Integer Type( (a)i / (b)j / (c)k ) : \n";
  62.     cin>>d>>e>>f;
  63.     cout<<"\nGiven Vector is: "<<d<<"i+"<<e<<"j+"<<f<<"k\n";
  64.     vector <float> vct_float_1 (d,e,f);
  65.  
  66.     cout<<"\nEnter Vector 2 of Integer Type( (a)i / (b)j / (c)k ) : \n";
  67.     cin>>d>>e>>f;
  68.     cout<<"\nGiven Vector is: "<<d<<"i+"<<e<<"j+"<<f<<"k\n";
  69.     vector <float> vct_float_2 (d,e,f);
  70.  
  71.     float pdt_float;
  72.     cout<<"\nScalar Product of the Given two Float Vectors is: "<<vct_float_1.scalar_product(vct_float_2);
  73.  
  74.  
  75.     getch();
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement