CA50
Cyborg Agent
I am currently working on a c++ program to do all the martix operations like addition, subtraction, multiplication and transpose.
But i am little weak in that "Function call / declaration etc." , so i am feeling difficulties in coding the program.
I am sending my partially completed code:
Please tell me how to initialize a function to add and display, and also the function itself.
But i am little weak in that "Function call / declaration etc." , so i am feeling difficulties in coding the program.
I am sending my partially completed code:
Please tell me how to initialize a function to add and display, and also the function itself.
Code:
#include<iostream.h>
#include<conio.h>
#define max_row 10
#define max_col 10
int main()
{
//theis program will add two matrix of 3x4
int mat1[max_row][max_col],mat2[max_row][max_col],mat3[max_row][max_col],row,col,i,j,value,n;
cout<<"\n\t\t\t OPERATIONS ON MATRICES\n\t\t Coded by CA50 on 22/03/10 08:40\n\n";
cout<<"Enter the number of rows for MATRIX 1 (max is 10):\a ";
cin>>row;
cout<<"Enter the number of columns for MATRIX 1 (max is 10):\a ";
cin>>col;
if((row<=max_row)&&(col<=max_col))
{
cout<<"\nYou have sucessfully created MATRIX 1 of ("<<row<<"x"<<col<<").\n";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cout<<"Enter value for row-"<<i<<" col-"<<j<<" ";
cin>>value;
mat1[i][j]=value;
}
}
}
else
{
cout<<"\n\n\aMatrix generation failed. You have exceeded the maximum size limitation.\n";
getch();
exit(0);
}
cout<<"\n";
cout<<"Enter the number of rows for MATRIX 2 (max is 10):\a ";
cin>>row;
cout<<"Enter the number of columns for MATRIX 2 (max is 10):\a ";
cin>>col;
if((row<=max_row)&&(col<=max_col))
{
cout<<"\nYou have sucessfully created MATRIX 2 of ("<<row<<"x"<<col<<").\n";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cout<<"Enter value for row-"<<i<<" col-"<<j<<" ";
cin>>value;
mat2[i][j]=value;
}
}
}
else
{
cout<<"\n\n\aMatrix generation failed. You have exceeded the maximum size limitation.\n";
getch();
exit(0);
}
//menu creation
system("cls");
cout<<"\n\t\t\t OPERATIONS ON MATRICES\n\t\t Coded by CA50 on 22/03/10 08:40\n\n";
cout<<"----- MATRIX MENU -----\n1. Matrix addtion.\n2. Matrix Subtraction.\n3. Matrix multiplication.\n4. Transpose of a matrix.\nEnter your choice ";
cin>>n;
switch(n)
{
case 1:
cout<<"\nThe result of matrix addition is:\n";
//call matrix addition function here
case 2:
//call matrix subtraction function
case 3:
//call matrix multiplication function
case 4:
//call transpose function
default :
cout<<"\n\nINVALID CHOICE\n\nPress any key to exit...";
getch();
exit (0);
}
return 0;
}