Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //***************************************************
- //www.engineerindy.com
- //@ Tutorial
- //@ DevC++ 4.9.9.2
- //@ Windows7
- ///**************************************************
- #include <iostream>
- #include <fstream>
- #include <conio.h>
- using namespace std;
- struct matrix
- {
- char name;
- int x,y;
- int a[20][20];
- };
- struct matrix one[10];
- struct matrix tran[5];
- struct matrix result[5];
- int z=0,y=0,t=0,g=0;
- void insert()
- {
- int number;
- int r=1,c=1;
- //row and column
- cout<<" Please input name of matrix [1 charecter] : ";
- cin>>one[z].name;
- cout<<" Please input size of matrix [row] : ";
- cin>>one[z].x;
- cout<<" Please input size of matrix [column] : ";
- cin>>one[z].y;
- cout<<"\n";
- for(int i=0;i<(one[z].x*one[z].y);i++)
- {
- cout<<" Please input value position "<<r<<","<<c<<" : ";
- cin>>one[z].a[r][c];
- c++;
- if(c>one[z].y)
- {
- c=1;
- r++;
- }
- }
- cout<<"\n matrix "<<one[z].name<<"["<<one[z].x<<"]["<<one[z].y<<"]\n";
- cout<<" ";
- for(int j=1;j<=(one[z].x);j++)
- {
- for(int n=1;n<=(one[z].y);n++)
- {
- cout<<one[z].a[j][n]<<" ";
- }
- cout<<"\n ";
- }
- cout<<"\n";
- z++;
- }
- void showresult()
- {
- if(result[g].x!=0)
- {
- cout<<"\n matrix "<<result[g].name<<"["<<result[g].x<<"]["<<result[g].y<<"]\n";
- cout<<" ";
- for(int j=1;j<=(result[g].x);j++)
- {
- for(int n=1;n<=(result[g].y);n++)
- {
- cout<<result[g].a[j][n]<<" ";
- }
- cout<<"\n ";
- }
- cout<<"\n";
- g++;
- }
- else
- cout<<"\n size of matrix Unequal or don't have variable\n\n";
- }
- void cal()
- {
- int j,i,n,m;
- char x[3];
- cout<<" Please Input LOGIC : ";
- cin>>x;
- cout<<" Please enter name of result matrix : ";
- cin>>result[g].name;
- //cout<<x;
- if(((x[1]=='+')&&(x[2]!=0))||((x[1]=='-')&&(x[2]!=0)))
- {
- //size of matrix must sam
- for(i=0;i<10;i++)
- {
- if(one[i].name==x[0])//first
- {
- for(j=0;j<10;j++)
- {
- if(one[j].name==x[2])//second
- {
- if((one[i].x==one[j].x)&&(one[i].y==one[j].y))//check colum and row must sam together
- {
- result[g].x=one[j].x;
- result[g].y=one[j].y;
- for(m=1;m<=one[i].x;m++)//row
- {
- for(n=1;n<=one[i].y;n++)//column
- {
- if(x[1]=='+')
- {
- result[g].a[m][n]=(one[i].a[m][n]+one[j].a[m][n]);
- }
- else if(x[1]=='-')
- {
- result[g].a[m][n]=(one[i].a[m][n]-one[j].a[m][n]);
- }
- }
- }
- break;
- }
- }
- else if(tran[j].name==x[2])
- {
- if((one[i].x==tran[j].x)&&(one[i].y==tran[j].y))//check colum and row must sam together
- {
- result[g].x=tran[j].x;
- result[g].y=tran[j].y;
- for(m=1;m<=tran[i].x;m++)//row
- {
- for(n=1;n<=tran[i].y;n++)//column
- {
- if(x[1]=='+')
- {
- result[g].a[m][n]=(one[i].a[m][n]+tran[j].a[m][n]);
- }
- else if(x[1]=='-')
- {
- result[g].a[m][n]=(one[i].a[m][n]-tran[j].a[m][n]);
- }
- }
- }
- break;
- }
- }
- else if(result[j].name==x[2])
- {
- if((one[i].x==result[j].x)&&(one[i].y==result[j].y))//check colum and row must sam together
- {
- result[g].x=one[i].x;
- result[g].y=one[i].y;
- for(m=1;m<=result[i].x;m++)//row
- {
- for(n=1;n<=result[i].y;n++)//column
- {
- if(x[1]=='+')
- {
- result[g].a[m][n]=(one[i].a[m][n]+result[j].a[m][n]);
- }
- else if(x[1]=='-')
- {
- result[g].a[m][n]=(one[i].a[m][n]-result[j].a[m][n]);
- }
- }
- }
- break;
- }
- }
- }
- }
- else if(tran[i].name==x[0])
- {
- for(j=0;j<10;j++)
- {
- if(tran[j].name==x[2])//second
- {
- if((tran[i].x==tran[j].x)&&(tran[i].y==tran[j].y))//check colum and row must sam together
- {
- result[g].x=tran[j].x;
- result[g].y=tran[j].y;
- for(m=1;m<=tran[i].x;m++)//row
- {
- for(n=1;n<=tran[i].y;n++)//column
- {
- if(x[1]=='+')
- {
- result[g].a[m][n]=(tran[i].a[m][n]+tran[j].a[m][n]);
- }
- else if(x[1]=='-')
- {
- result[g].a[m][n]=(tran[i].a[m][n]-tran[j].a[m][n]);
- }
- }
- }
- break;
- }
- }
- else if(one[j].name==x[2])
- {
- if((tran[i].x==one[j].x)&&(tran[i].y==one[j].y))//check colum and row must sam together
- {
- result[g].x=tran[j].x;
- result[g].y=tran[j].y;
- for(m=1;m<=one[i].x;m++)//row
- {
- for(n=1;n<=one[i].y;n++)//column
- {
- if(x[1]=='+')
- {
- result[g].a[m][n]=(tran[i].a[m][n]+one[j].a[m][n]);
- }
- else if(x[1]=='-')
- {
- result[g].a[m][n]=(tran[i].a[m][n]-one[j].a[m][n]);
- }
- }
- }
- break;
- }
- }
- else if(result[j].name==x[2])
- {
- if((tran[i].x==result[j].x)&&(tran[i].y==result[j].y))//check colum and row must sam together
- {
- result[g].x=tran[i].x;
- result[g].y=tran[i].y;
- for(m=1;m<=result[i].x;m++)//row
- {
- for(n=1;n<=result[i].y;n++)//column
- {
- if(x[1]=='+')
- {
- result[g].a[m][n]=(tran[i].a[m][n]+result[j].a[m][n]);
- }
- else if(x[1]=='-')
- {
- result[g].a[m][n]=(tran[i].a[m][n]-result[j].a[m][n]);
- }
- }
- }
- break;
- }
- }
- }
- }
- else if(result[i].name==x[0])
- {
- for(j=0;j<10;j++)
- {
- if(tran[j].name==x[2])//second
- {
- while((result[i].x==tran[j].x)&&(result[i].y==tran[j].y))//check colum and row must sam together
- {
- result[g].x=tran[j].x;
- result[g].y=tran[j].y;
- for(m=1;m<=result[i].x;m++)//row
- {
- for(n=1;n<=result[i].y;n++)//column
- {
- if(x[1]=='+')
- {
- result[g].a[m][n]=(result[i].a[m][n]+tran[j].a[m][n]);
- }
- else if(x[1]=='-')
- {
- result[g].a[m][n]=(result[i].a[m][n]-tran[j].a[m][n]);
- }
- }
- }
- break;
- }
- }
- else if(one[j].name==x[2])
- {
- while((result[i].x==one[j].x)&&(result[i].y==one[j].y))//check colum and row must sam together
- {
- result[g].x=result[i].x;
- result[g].y=result[i].y;
- for(m=1;m<=result[i].x;m++)//row
- {
- for(n=1;n<=result[i].y;n++)//column
- {
- if(x[1]=='+')
- {
- result[g].a[m][n]=(result[i].a[m][n]+one[j].a[m][n]);
- }
- else if(x[1]=='-')
- {
- result[g].a[m][n]=(result[i].a[m][n]-one[j].a[m][n]);
- }
- }
- }
- break;
- }
- }
- else if(result[j].name==x[2])
- {
- while((result[i].x==result[j].x)&&(result[i].y==result[j].y))//check colum and row must sam together
- {
- result[g].x=result[j].x;
- result[g].y=result[j].y;
- for(m=1;m<=result[i].x;m++)//row
- {
- for(n=1;n<=result[i].y;n++)//column
- {
- if(x[1]=='+')
- {
- result[g].a[m][n]=(result[i].a[m][n]+result[j].a[m][n]);
- }
- else if(x[1]=='-')
- {
- result[g].a[m][n]=(result[i].a[m][n]-result[j].a[m][n]);
- }
- }
- }
- break;
- }
- }
- }
- }
- //3
- }
- showresult();
- }
- else if(((x[1]=='*')&&(x[2]!=0))||((x[1]=='/')&&(x[2]!=0)))
- {
- //column of first must sam with row of secen
- cout<<"\n We are currently developing.\n\n";
- }
- else
- {
- cout<<"\n Syntax of LOGIC error\n";
- showresult();
- }
- }
- void trans()
- {
- char v;
- cout<<" Transpose matrix : ";
- cin>>v;
- for(int i=0;i<10;i++)
- {
- if((one[i].name)==v)
- {
- for(int j=1;j<=one[i].x;j++)
- {
- for(int n=1;n<=one[i].y;n++)
- {
- tran[y].a[n][j]=one[i].a[j][n];
- }
- }
- tran[y].x=one[i].y;
- tran[y].y=one[i].x;
- cout<<"\n Enter name of Transpose Matrix : ";
- cin>>tran[y].name;
- cout<<"\n Transpose Matrix "<<tran[y].name<<"["<<tran[y].x<<"]["<<tran[y].y<<"]\n";
- break;
- }
- else if((result[i].name)==v)
- {
- for(int j=1;j<=result[i].x;j++)
- {
- for(int n=1;n<=result[i].y;n++)
- {
- tran[y].a[n][j]=result[i].a[j][n];
- }
- }
- tran[y].x=result[i].y;
- tran[y].y=result[i].x;
- cout<<"\n Enter name of Transpose Matrix : ";
- cin>>tran[y].name;
- cout<<"\n Transpose Matrix "<<tran[y].name<<"["<<tran[y].x<<"]["<<tran[y].y<<"]\n";
- break;
- }
- else if((tran[i].name)==v)
- {
- for(int j=1;j<=tran[i].x;j++)
- {
- for(int n=1;n<=tran[i].y;n++)
- {
- tran[y].a[n][j]=tran[i].a[j][n];
- }
- }
- tran[y].x=tran[i].y;
- tran[y].y=tran[i].x;
- cout<<"\n Enter name of Transpose Matrix : ";
- cin>>tran[y].name;
- cout<<"\n Transpose Matrix "<<tran[y].name<<"["<<tran[y].x<<"]["<<tran[y].y<<"]\n";
- break;
- }
- else
- {
- cout<<"\n Don't have this matrix\n";
- break;
- }
- }
- cout<<" ";
- for(int o=1;o<=(tran[y].x);o++)
- {
- for(int p=1;p<=(tran[y].y);p++)
- {
- cout<<tran[y].a[o][p]<<" ";
- }
- cout<<"\n ";
- }
- cout<<"\n";
- y++;
- }
- void constant()
- {
- char b,c;
- int a,i,n,m;
- cout<<" Enter constant number : ";
- cin>>a;
- cout<<" ['*'= Mutiply]['/'= Devide] : ";
- cin>>b;
- if(b=='*')
- {
- cout<<" Enter matrix that you want mutiply : ";
- cin>>c;
- cout<<" Enter name of result matrix : ";
- cin>>result[g].name;
- for(i=0;i<10;i++)
- {
- if(one[i].name==c)
- {
- for(m=1;m<=one[i].x;m++)//row
- {
- for(n=1;n<=one[i].y;n++)//column
- {
- result[g].a[m][n]=(one[i].a[m][n]*a);
- }
- }
- result[g].x=one[i].x;
- result[g].y=one[i].y;
- showresult();
- break;
- }
- else if(result[i].name==c)
- {
- for(m=1;m<=result[i].x;m++)//row
- {
- for(n=1;n<=result[i].y;n++)//column
- {
- result[g].a[m][n]=(result[i].a[m][n]*a);
- }
- }
- result[g].x=result[i].x;
- result[g].y=result[i].y;
- showresult();
- break;
- }
- else if(tran[i].name==c)
- {
- for(m=1;m<=tran[i].x;m++)//row
- {
- for(n=1;n<=tran[i].y;n++)//column
- {
- result[g].a[m][n]=(tran[i].a[m][n]*a);
- }
- }
- result[g].x=tran[i].x;
- result[g].y=tran[i].y;
- showresult();
- break;
- }
- }
- }
- else if(b=='/')
- {
- cout<<" Enter matrix that you want devide : ";
- cin>>c;
- cout<<" Enter name of result matrix : ";
- cin>>result[g].name;
- for(i=0;i<10;i++)
- {
- if(one[i].name==c)
- {
- for(m=1;m<=one[i].x;m++)//row
- {
- for(n=1;n<=one[i].y;n++)//column
- {
- result[g].a[m][n]=(one[i].a[m][n]/a);
- }
- }
- result[g].x=one[i].x;
- result[g].y=one[i].y;
- showresult();
- break;
- }
- else if(result[i].name==c)
- {
- for(m=1;m<=result[i].x;m++)//row
- {
- for(n=1;n<=result[i].y;n++)//column
- {
- result[g].a[m][n]=(result[i].a[m][n]/a);
- }
- }
- result[g].x=result[i].x;
- result[g].y=result[i].y;
- showresult();
- break;
- }
- else if(tran[i].name==c)
- {
- for(m=1;m<=tran[i].x;m++)//row
- {
- for(n=1;n<=tran[i].y;n++)//column
- {
- result[g].a[m][n]=(tran[i].a[m][n]/a);
- }
- }
- result[g].x=tran[i].x;
- result[g].y=tran[i].y;
- showresult();
- break;
- }
- }
- }
- else
- {
- cout<<"\n You must Enter ['*' or '/']\n\n";
- }
- }
- int main()
- {
- char number;
- cout<<"\n WELCOME TO CALCULATED OF MATRIX PROGEAM\n\n";
- cout<<" ****************************************************\n";
- cout<<" MENUS\n";
- cout<<" 1.Insert Matrix\n";
- cout<<" 2.Calculated\n";
- cout<<" 3.Transpose\n";
- cout<<" 4.Compute with constant\n";
- cout<<" 5.End progrem\n";
- cout<<" ****************************************************\n\n\n";
- do
- {
- cout<<" Please enter number : ";
- cin>>number;
- if(number=='1')
- {
- insert();
- }
- else if(number=='2')
- {
- cal();
- }
- else if(number=='3')
- {
- trans();
- }
- else if(number=='4')
- {
- constant();
- }
- else if(number=='5')
- {
- cout<<"\n T-H-A-N-K-Y-O-U";
- break;
- }
- else
- {
- cout<<" E-R-R-O-R\n";
- }
- }
- while(number!='5');
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement