home study engineering computer science questions and an

home / study / engineering / computer science / questions and answers / use single pointers only eg. int*x and not int**x ... Question: Use single pointers only eg. int*x and not int**x ... Bookmark use single pointers only eg. int*x and not int**x and vectors (ONE DIMENTIONAL) to answer the questions bellow. and do not use any\" malloc.h\" or similar file make a function for concatention C++ CODE ONLY Matrix concatenation In this exercise you are invited to write a program that performs a horizontal concatenation of two n*m matrices: Example: n =3, m = 5 Matrix a : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Matrix b : 16 17 18 19 20 6 7 8 9 10 11 12 13 14 15 Horizontal Concatenation Matrix: 1 2 3 4 5 16 17 18 19 20 6 7 8 9 10 6 7 8 9 10 11 12 13 14 15 11 12 13 14 15 Your program should create two functions: 1) concatenate() that takes 2 vectors as parameters and return an array containing the two vectors Example: for m =5 Vector a: 1 2 3 4 5 Vector b: 6 7 8 9 10 Concatenated array: 1 2 3 4 5 6 7 8 9 10 2) horizontalConcatenation() that takes two matrices as parameters and returns a matrix representing their concatenation. This function should use the concatenate () function. MAKE A C++ CODE

Solution

As per my understanding, I am providing the complete solution of this problem.

#include\"iostream\"
using namespace std;
void concat(int *a, int *b, int *c, int n, int m)
{
        int i,j;
        for(i=1;i<=n;i++)
        {
                for( j = 1 ; j <= 2*m ; j++ )
                        if(j <= m)
                        {
                                c[((i-1)*2*m)+j] = a[((i-1)*m)+j];
                        }
                        else
                        {
                                c[((i-1)*2*m)+j] = b[((i-1)*m)+(j-m)];
                        }
        }
}
int main()
{
        int a[100],b[100],c[200],n,m,i,j;
        cout<<\"\ Please n and m metrics of 2D array\ \";
        cin>>n>>m;
        cout<<\"Please Enter first array\";
        for(i=1;i<=n*m;i++)
                cin>>a[i];
        cout<<\"Please Enter second array\";
        for(i=1;i<=n*m;i++)
                cin>>b[i];
        concat(a,b,c,n,m);
        cout<<\"Print the Final Output\ \";
        for(i=1;i<=n;i++)
        {
                for( j = 1 ; j <= 2*m ; j++ )
                        cout<<c[((i-1)*2*m)+j]<<\"\\t\";
                cout<<\"\ \";
        }
        return 0;
}

home / study / engineering / computer science / questions and answers / use single pointers only eg. int*x and not int**x ... Question: Use single pointers only

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site