Not Yet Answered # 2D vector

Lucaci Andrew 140 Discussion Starter islam.fci.3 Discussion Starter islam.fci.3 tinstaafl 854 Discussion Starter islam.fci.3 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

It's kinda hard for us to figure out your problems since you didn't share them with us.

0

I want to let the user to input elements of the vector....

then i want to multiply two 2D vectors

i wrote a code but there is logic errors

0

PLZ.. write the code of entering two 2D vectors and multiply them ,then show results,

using class that take elements of the vector ,multiply and show result

*Edited 3 Years Ago by islam.fci.3*

0

Show the code and outline the errors. Unless you're willing to pay someone to do the work for you, in which case you should be in Jobs and Resumes forum.

0

it's the code , debug it and tell me what is the error

```
#include <iostream>
using namespace std;
#include <vector>
class matrix
{
protected:
int r,c; //r is rows c is columns
char op; // op is the operarion
vector<vector<double> > elements; //vector for matrix elements
public:
matrix() //constructor for initializing r,c,op and vector to 0
{
r='c';c='a'; op='b';
for ( int i = 0; i < 5; i++ ) {
elements.push_back ( vector<double>() );
for ( int j = 0; j < 5; j++ )
{
elements[i].push_back ( 0 );}
}
}
////////////////////////////////////////////////////////////
void get_data() //get elements of the matrix from the user
{
char a;
double n;
cout<<"\n\nEnter type of the matrix in form r*c\n\n";
cin>>r>>a>>c;
cout<<"Enter the element of the matrix\n\n";
for ( int i = 0; i < r; i++ ) {
elements.push_back ( vector<double>() );
for ( int j = 0; j < c; j++ )
{
cin>>n;
elements[i].push_back (n );}
}
}
////////////////////////////////////////////////////////////
void operation(matrix mat1,matrix mat2) //do operations on two matrices
{
cout<<"Enter the operation you want (+,-,*)\n\n";
cin>>op;
switch(op) //if the operation +,-,*
{
case '+':
if(mat1.r==mat2.r&&mat1.c==mat2.c) //if the matrices have the same type it can sum
{
for(int i=0;i<mat1.r;i++){
for(int j=0;j<mat1.c;j++){
elements[i][j]=mat1.elements[i][j]+mat2.elements[i][j];}
}
}
else
cout<<"\nERROR You Enterd Tow Matrices Of Different Type\n\n";
break;
////////////////////////////////////////////////////////////
case'-':
if(mat1.r==mat2.r&&mat1.c==mat2.c) //if the matrices have the same type it can subtract
{
for(int i=0;i<mat1.r;i++){
for(int j=0;j<mat1.c;j++){
elements[i][j]=mat1.elements[i][j]-mat2.elements[i][j];}
}
}
else
cout<<"\nERROR You Enterd Tow Matrices Of Different Type\n\n";
break;
////////////////////////////////////////////////////////////
case'*':
if(mat1.c==mat2.r) //if number of first matrix columns equal number of second matrix rows
{
for ( int i = 0; i < mat1.r; i++ ) //initialize the vector of the result to 0
{
elements.push_back ( vector<double>() );
for ( int j = 0; j < mat2.c; j++ ){
elements[i].push_back (0 );}}
////////////////////////////////////////////////////////////
for(int i=0;i<mat1.r;i++) //multiplying
{
for(int j=0;j<mat2.c;j++)
{
for(int k=0;k<mat1.c;k++)
elements[i][j]=elements[i][j]+mat1.elements[i][k]+mat2.elements[k][j];
}
}
}
else
{ cout<<"\n Input matrices can not be multiplied\n";
cout<<" The number of columns in first matrix must equal number of rows of the second matrix\n";}
break;
default:
cout<<"\nYou Entered Error sign\n\n";
}
}
////////////////////////////////////////////////////////////
void sow_data(matrix mat1,matrix mat2) //show the result
{
if(op=='+'||'-') //if the operation is + or -
{
for(int i=0;i<mat1.r;i++){
for(int j=0;j<mat1.c;j++)
cout<<elements[i][j]<<' ';
cout<<"\n\n";
}
}
else if(op=='*') //if the operation is multiplying
{
for(int i=0;i<mat1.r;i++){
for(int j=0;j<mat2.c;j++)
cout<<elements[i][j]<<' ';
cout<<"\n\n";
}
}
else
cout<<"\nERROR\n";
}
};
int main()
{
matrix mat,mat1,mat2;
mat1.get_data();
mat2.get_data();
mat.operation(mat1,mat2);
mat.sow_data(mat1,mat2);
return 0;
}
```

*Edited 3 Years Ago by islam.fci.3*

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...