423,846 Members | 2,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,846 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
File Type: pdf LAB TEST 2.pdf (430.3 KB, 6 views)
1 Week Ago #1
Share this Question
Share on Google+
2 Replies


P: 2
Look the output at attached file, thanks.
My due is tonight, help me asap,ty
1 Week Ago #2

weaknessforcats
Expert Mod 5K+
P: 9,196
Have you stepped through this code using your debugger?

If not, this is an excellent time to learn how to use it, Debugging code is just as important as being able to write it.

Just run the code using the debugger and step through it. You will see the values of all of your variables as you go.
1 Week Ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.