1. Find the error in the following partial code AND indicate the correction. The
ID: 3576018 • Letter: 1
Question
1. Find the error in the following partial code AND indicate the correction. There is only one error and it is in the code shown. It is not that lines of code are missing. It may be a syntax or logic error.
FLOAT MERRY[3][3], Y;
INT RUN, CAT, X;
//more code would be here
Y=MERRY[1][3];
COUT<<MERRY[0][0]<<MERRY[1][0];
2. Write just the do while code that will calculate: y=5x2 – 4x + 3. Assume the user enters the starting value of x in a variable called start, the stopping value of x in a variable called stop, and the increment value of x in a variable called incr. Note that all the loop has to do is calculate – no output required.
3.
What is the output of the following partial code?
INT MAIN()
{//variables would be defined here
A=5;
B=7;
Z=FUN(A,B);
COUT<<Z<<”AND”<<A;
}
INT FUN(INT A, INT Y )
{INT ANS;
A=A+5;
ANS=Y*A;
RETURN(ANS);}
4. Write the lines of code that will fill a 9X4 array called DATA, row by row, with data entered by the user. You must use loops in your code and you only need to write the code for this task - I do not need a complete program or variables defined.
5.
a) List all the arrays in this program.
b) What is the name of the data file pointer defined in this program?
c) Is the data file pointer allowing us to read from(input) OR write to (output) a data file?
OFSTREAM SANTA;
INT HOHO(FLOAT JINGLE);
INT MAIN()
{FLOAT X, YULE[5], ZAP;
INT STAR[5][4], Z, BELL[3];
SANTA.OPEN(“TEST.DAT”, IOS::OUT);
Z=0;
WHILE (Z<4)
{CIN>>YULE[Z];
Z=Z+1;
}
6.
Given an array DATA has been filled and looks like this: 1 2 3
4 5 6
Write the lines of code, using loop(s), to output this array like this:
1 4
2 5
3 6
You should NOT create a new array to accomplish this. Again, I need only the code to complete this task - not a complete program.
7.
Find the error in the following partial code AND indicate the correction. There is only one error and it is in the code shown. It is not that lines of code are missing. It may be a logic or syntax error.
INT Y, X ,I, Z;
Z=1;
X=0;
FOR(I=0, I<=5, I=I+1)
{Y=X*I + I*I;
COUT<<Y<<X<<I;
X=X+Z;
}
8.
Given the partial code:
How many values are sent to the function?
{FLOAT NUM[3];
INT X, Y, Z;
NUM[0]=5;
X=1;
Y=2;
Z=P0LY(X, Y);
COUT<<Z;
Explanation / Answer
1) The error is
Y = MERRY[1][3]
The array is of size 3x3 index from 0 to 2. Correcting it to 2.
FLOAT MERRY[3][3], Y;
INT RUN, CAT, X;
//more code would be here
Y=MERRY[1][2];
COUT<<MERRY[0][0]<<MERRY[1][0];
2)
x=start;
while(x<=stop)
{
cout<<5*x*x-4*x+3<<endl;
x+=incr;
}
3)
The output will be:
70 AND 5
4)
for(int i=0;i<9;i++)
{
for(int j=0;j<4;j++)
{
cin>>DATA[i][j];
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.