1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
#include<iostream>
#include<sstream>
#include <cstdlib>
#include<string>
using namespace std;
void set_Matrix(float row,float col,string ptr[][100])
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
cin>>ptr[i][j];
}
}
}
void get_Matrix(float row,float col,string ptr[][100])
{ for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
cout<<"\t";
cout<<ptr[i][j]<<"\t";
}
cout<<endl;
}
}
void ADD_MATRIX(int row,int col,string ptr[][100],string ptr2[][100])
{
string ptr3[100][100];
string ptr7[100][100];
ostringstream ssÍž
float ptr4[100][100];
ptr4[100][100]= atof(ptr[100][100].c_str());
float ptr5[100][100];
ptr5[100][100]= atof(ptr2[100][100].c_str());
float ptr6[100][100];
ptr6[100][100]= atof(ptr3[100][100].c_str());
for(int i=0;i<row;i++)
{
for (int j=0;j<col;j++)
{
ptr6[i][j]=ptr4[i][j]+ptr5[i][j];
}
}
}
void sub_MATRIX(int row,int col,string ptr[][100],string ptr2[][100])
{
string ptr3[100][100];
for(int i=0;i<row;i++)
{
for (int j=0;j<col;j++)
{
//ptr3[i][j]=ptr[i][j]-ptr2[i][j];
}
}
get_Matrix(row,col,ptr3);
}
void multi_MATRIX(int row,int col,string ptr[][100],string ptr2[][100])
{
string ptr3[100][100];
for(int i=0;i<row;i++)
{
for (int j=0;j<col;j++)
{
//ptr3[i][j]=ptr[i][j]*ptr2[i][j];
}
}
get_Matrix(row,col,ptr3);
}
int main()
{
string ptr[100][100];
int row;
int col;
//int **ptr;
/* *ptr=new int[row];
for(int i=0;i<col;i++)
{
ptr[i]=new int[col];
}*/
cout<<"Please Enter The Number of row : ";
cin>>row;
cout<<"Please Enter The Number of column : " <<endl;
cin>>col;
cout<<"Please Enter The First Matrix : " <<endl;
set_Matrix(row,col,ptr);
get_Matrix(row,col,ptr);
string choice;
do
{
cout<<"Press + to Perform Addition"<<endl;
cout<<"Press - to Perform Substraction"<<endl;
cout<<"Press * to Perform Multiplication"<<endl;
cout<<"Press 0 to exit";
cout<<"Enter your choice : ";
cin>>choice;
switch(choice[0])
{
case'+':
{
string ptr2[100][100];
int row2,col2;
cout<<"Please Enter The Second Matrix : " <<endl;
cin>>row2;
cout<<"Please Enter The Number of column : " <<endl;
cin>>col2;
cout<<"Please Enter The Second Matrix : " <<endl;
set_Matrix(row2,col2,ptr2);
if(row2!=row ||col2!=col )
{
choice[0]='0';
cout<<"ERROR !! "<<endl;
break;
}
ADD_MATRIX(row,col,ptr,ptr2);
break;
}
case '-':
{
string ptr2[100][100];
int row2,col2;
cout<<"Please Enter The Second Matrix : " <<endl;
cin>>row2;
cout<<"Please Enter The Number of column : " <<endl;
cin>>col2;
cout<<"Please Enter The Second Matrix : " <<endl;
set_Matrix(row,col,ptr2);
if(row2!=row ||col2!=col )
{
cout<<"ERROR !! "<<endl;
choice[0]=='0';
}
sub_MATRIX(row2,col2,ptr,ptr2);
break;
}
case '*':
{
string ptr2[100][100];
int row2,col2;
cout<<"Please Enter The Second Matrix : " <<endl;
cout<<"Please Enter The Second Matrix : " <<endl;
cin>>row2;
cout<<"Please Enter The Number of column : " <<endl;
cin>>col2;
set_Matrix(row2,col2,ptr2);
if(row2!=row ||col2!=col )
{
cout<<"ERROR !! "<<endl;
choice[0]=='0';
}
multi_MATRIX(row,col,ptr,ptr2);
break;
}
}
}while(choice[0]!='0');
}
|