434,572 Members | 946 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,572 IT Pros & Developers. It's quick & easy.

# already done the code but the output come out wrong , some one help me

P: 2
#include<iostream>
using namespace std;
int setFirst(int alpha[],int beta[]);
int inputArray(int alpha[]);
double doubleArray(int alpha[],int beta[]);
void copyAlphaBeta(int matrix[][4], const int numberOfRows, const int
alpha[], const int beta[], int numSize);
int printArray(int print[],int n);

int main()
{
int alpha[20];
int beta[20];
int matrix[10][4];

inputArray(alpha);
cout<<"Alpha after reading 20 numbers"<<endl;
printArray(alpha, 20);
cout<<endl;

doubleArray(alpha, beta);
cout << "Beta after a call to doubleArray" << endl;
printArray(beta, 20);
cout<<endl;

copyAlphaBeta(matrix, 10, alpha, beta, 20);
for (int row=0; row<10;row++)
for (int col=0; col<4; col++)
{
if (col%4==0)
cout << endl;
cout<<matrix[row][col]<<'\t';
}
cout<<endl;

return 0;
}

int setFirst(int alpha[],int beta[])
{
for(int i=0;i<20;i++)
{
alpha[i]=0;
beta[i]=0;
}
cout<<endl;
}
int inputArray(int alpha[])
{
cout<<"Enter 20 integers:"<<endl;
for(int i=0;i<20;i++)
{

cin>>alpha[i];
}
cout<<endl;
return 0;
}
double doubleArray(int alpha[],int beta[])
{
for(int i=0;i<20;i++)
{
beta[i]=2*alpha[i];
}
cout<<endl;
return 0;
}
void copyAlphaBeta(int matrix[][4], const int numberOfRows, const int
alpha[], const int beta[], int numSize)
{
cout << endl;
cout << "Matrix after a call to copyAlphaBeta" << endl;

for(int r=0;r<numberOfRows;r++)
{
for(int c=0;c<4;c++)
{
for (int counter=0; counter<numSize; counter++)
{
if(r<5)
{
matrix[r][c]=alpha[counter];
}
else if (r>=5)
{
matrix[r][c]=beta[counter];
}
}
}
}

cout << endl;
}
int printArray(int print[],int n)
{
cout << endl;
for (int i=0;i<n;i++)
cout << print[i] << " ";
cout << endl;
}[/code]
Attached Files
 LAB TEST 2.pdf (430.3 KB, 35 views)
Dec 5 '18 #1