fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <class T>
  6. class Vector
  7. {
  8. public:
  9. T a,b,c;
  10. void read()
  11. {
  12. cout<<"Enter x part";
  13. cin>>a;
  14. cout<<"Enter y part";
  15. cin>>b;
  16. cout<<"Enter z part";
  17. cin>>c;
  18.  
  19. }
  20. void display()
  21. {
  22. cout<<a<<"i+"<<b<<"j+"<<c<<"k";
  23. }
  24. Vector operator+(Vector v2)
  25. {
  26. Vector v3;
  27. v3.a=a+v2.a;
  28. v3.b=b+v2.b;
  29. v3.c=c+v2.c;
  30. return(v3);
  31. }
  32. Vector operator*(Vector v2)
  33. {
  34. Vector v3;
  35. v3.a=b*v2.c-c*v2.b;
  36. v3.b=c*v2.a-a*v2.c;
  37. v3.c=a*v2.b-b*v2.a;
  38. return(v3);
  39. }};
  40. int main()
  41. {
  42. int ch;
  43. Vector<int>v1;
  44. Vector<int>v2;
  45. Vector<int>v3;
  46. Vector<float>v4;
  47. Vector<float>v5;
  48. Vector<float>v6;
  49. do
  50. {
  51. cout<<"Choose one\n1.Integer Addition\n2.Float Addition\n3.Integer Cross Product";
  52. cout<<"\n4.Float Cross Product\n5.Exit\n";
  53. cout<<"Enter the choice";
  54. cin>>ch;
  55. switch(ch)
  56. {
  57. case 1:v1.read();
  58. v2.read();
  59. v3=v1+v2;
  60. cout<<"Integer Sum = ";
  61. v3.display();
  62. break;
  63. case 2:v4.read();
  64. v5.read();
  65. v6=v4+v5;
  66. cout<<"Float Sum = ";
  67. v6.display();
  68. break;
  69. case 3:v1.read();
  70. v2.read();
  71. v3=v1*v2;
  72. cout<<"Integer Cross Product = ";
  73. v3.display();
  74. break;
  75. case 4:v4.read();
  76. v5.read();
  77. v6=v4+v5;
  78. cout<<"Float Cross Product = ";
  79. v6.display();
  80. break;
  81. case 5:cout<<"Exiting the program";
  82. break;
  83. default:cout<<"Invalid Choice";
  84. }
  85. }while(ch!=5);
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
Success #stdin #stdout 0s 3480KB
stdin
1
1
2
3
2
3
4
2
1
2
3
2
3
4
3
1
2
3
2
3
4
4
1
2
3
2
3
4
5
stdout
Choose one
1.Integer Addition
2.Float Addition
3.Integer Cross Product
4.Float Cross Product
5.Exit
Enter the choiceEnter x partEnter y partEnter z partEnter x partEnter y partEnter z partInteger Sum = 3i+5j+7kChoose one
1.Integer Addition
2.Float Addition
3.Integer Cross Product
4.Float Cross Product
5.Exit
Enter the choiceEnter x partEnter y partEnter z partEnter x partEnter y partEnter z partFloat Sum = 3i+5j+7kChoose one
1.Integer Addition
2.Float Addition
3.Integer Cross Product
4.Float Cross Product
5.Exit
Enter the choiceEnter x partEnter y partEnter z partEnter x partEnter y partEnter z partInteger Cross Product = -1i+2j+-1kChoose one
1.Integer Addition
2.Float Addition
3.Integer Cross Product
4.Float Cross Product
5.Exit
Enter the choiceEnter x partEnter y partEnter z partEnter x partEnter y partEnter z partFloat Cross Product = 3i+5j+7kChoose one
1.Integer Addition
2.Float Addition
3.Integer Cross Product
4.Float Cross Product
5.Exit
Enter the choiceExiting the program