diff --git a/ClassTemplate/classtemplate.cpp b/ClassTemplate/classtemplate.cpp new file mode 100644 index 00000000..ebc0a0e7 --- /dev/null +++ b/ClassTemplate/classtemplate.cpp @@ -0,0 +1,372 @@ +#include +#include +using namespace std; + +template +class matrix +{ + t a[50][50],b[50][50]; + int r1,c1,r2,c2; + + public: + void accept(); + void add(); + void multiply(); + void transpose(); + void saddlepoint(); +}; + +template +void matrix::accept() +{ + cout<<"Enter number of rows in matrix a:"; + cin>>r1; + + cout<<"Enter number of rows in matrix a:"; + cin>>c1; + + cout<<"Enter number of columns in matrix b:"; + cin>>r2; + + cout<<"Enter number of columns in matrix b:"; + cin>>c2; + + cout<<"\nEnter the elements of matrix 1:"; + for(int i=0;i>a[i][j]; + + cout<<"\nEnter the elements of matrix 2:"; + for(int i=0;i>b[i][j]; +} + +template +void matrix::add() +{ + cout<<"sum\n"; + t d[r1][c1]; + for(int i=0;i +void matrix::multiply() +{ + cout<<"Product\n"; + t d[c1][r2]; + if(r1==c2) + { + for(int i=0;i +void matrix::transpose() +{ + cout<<"Transpose\n"; + for(int i=0;i +void matrix::saddlepoint() +{ + int n,k,m; + for(int i=0;i=a[i][j]) + { + n=a[i][j]; + k=j; + } + } + m=a[0][k]; + for(i=0;iobj1; + matrix obj2; + for(;;) + { + cout<<"MENU\n1)int value\n2)Float value\n3)Exit\nEnter your choice:"; + cin>>ch; + switch(ch) + { + case 1: + obj1.accept(); + do + { + cout<<"MENU\n1)Addition\n2)Multiplication\n3)Transpose\n4)Saddlepoint\n5)Back to above menu\nEnter your choice:"; + cin>>ch; + switch(ch) + { + case 1:obj1.add(); + break; + + case 2:obj1.multiply(); + break; + + case 3:obj1.transpose(); + break; + + case 4:obj1.saddlepoint(); + break; + + case 5:break; + } + cout<<"Continue[y/n]:"; + cin>>choice; + } + while(choice=='y'); + + break; + + case 2: + obj2.accept(); + do + { + cout<<"MENU\n1)Addition\n2)Multiplication\n3)Transpose\n4)Saddlepoint\n5)Back to above menu\nEnter your choice:"; + cin>>ch; + switch(ch) + { + case 1:obj2.add(); + break; + + case 2:obj2.multiply(); + break; + + case 3:obj2.transpose(); + break; + + case 4:obj2.saddlepoint(); + break; + + case 5:break; + } + cout<<"Continue[y/n]:"; + cin>>choice; + } + while(choice=='y'); + break; + + case 3:exit(0); + + cout<<"Continue[y/n]:"; + cin>>choice; + if(choice=='n') + break; + } + } +} + + + + +OUTPUT: + +MENU +1)int value +2)Float value +3)Exit +Enter your choice:1 +Enter number of rows in matrix a:2 +Enter number of rows in matrix a:2 +Enter number of columns in matrix b:2 +Enter number of columns in matrix b:2 + +Enter the elements of matrix 1:2 +2 +2 +2 + +Enter the elements of matrix 2:1 +0 +0 +1 + +MENU +1)Addition +2)Multiplication +3)Transpose +4)Saddlepoint +5)Back to above menu +Enter your choice:1 + +sum +32 +23 + +Continue[y/n]:y + +MENU +1)Addition +2)Multiplication +3)Transpose +4)Saddlepoint +5)Back to above menu +Enter your choice:2 + +Product +22 +22 +Continue[y/n]:y + +MENU +1)Addition +2)Multiplication +3)Transpose +4)Saddlepoint +5)Back to above menu +Enter your choice:3 + +Transpose +22 +22 +Continue[y/n]:y + +MENU +1)Addition +2)Multiplication +3)Transpose +4)Saddlepoint +5)Back to above menu +Enter your choice:4 + +Saddle point of the matrix is 2 +Continue[y/n]:y + +MENU +1)Addition +2)Multiplication +3)Transpose +4)Saddlepoint +5)Back to above menu +Enter your choice:5 +Continue[y/n]:n + +MENU +1)int value +2)Float value +3)Exit +Enter your choice:2 +Enter number of rows in matrix a:2 +Enter number of rows in matrix a:2 +Enter number of columns in matrix b:2 +Enter number of columns in matrix b:2 + +Enter the elements of matrix 1:1.33 +26.11 +9.11 +6.77 + +Enter the elements of matrix 2:1 +0 +0 +1 +MENU +1)Addition +2)Multiplication +3)Transpose +4)Saddlepoint +5)Back to above menu +Enter your choice:1 + +sum +2.33 26.11 +9.11 7.77 +Continue[y/n]:y + +MENU +1)Addition +2)Multiplication +3)Transpose +4)Saddlepoint +5)Back to above menu +Enter your choice:2 + +Product +1.33 26.11 +9.11 6.77 +Continue[y/n]:y + +MENU +1)Addition +2)Multiplication +3)Transpose +4)Saddlepoint +5)Back to above menu +Enter your choice:3 + +Transpose +1.33 9.11 +26.11 6.77 +Continue[y/n]:y + +MENU +1)Addition +2)Multiplication +3)Transpose +4)Saddlepoint +5)Back to above menu +Enter your choice:4 + +Saddle point of the matrix is 1.33 +Continue[y/n]:y + +MENU +1)Addition +2)Multiplication +3)Transpose +4)Saddlepoint +5)Back to above menu +Enter your choice:5 +Continue[y/n]:n + +MENU +1)int value +2)Float value +3)Exit +Enter your choice:3 + +