C++finalPL Final A
C++finalPL Final A
C. D.
void Test(int& u, double& v) void Test(int& u, double& v)
( [
cout << u << " " << v << endl; cout << u << " " << v << endl;
) ]
char ch='b';
int a=6;
if(ch>'B'||a==5)
cout<<1111<<endl;
1111
else
cout<<2222<<endl;
4444
if(ch<'a'&&a==6)
cout<<3333<<endl;
else
cout<<4444<<endl;
int z=3,a=9;
while(a<13)
{
0
cout<<a%z<<endl;
a+=2; 5
z+=3;
}
float x=0.5,sum=0;
do
{
sum+=x;
0.5
x*=3;
} 1.5
while(x<0);
cout<<sum<<endl;
cout<<x<<endl;
Code Output
float Arr[6]={-3,2.5,6,9,-3,-5};
for(int i=1 ; i<6 ; i+=2) 1
{ 3
cout<<i<<endl; 5
}
bool Test(int x)
{
if( x>3 && x<6 )
return true;
else
return false;
0
}
void main() 1
{
int n1=1 , n2=5;
cout<< Test( n1 )<<endl;
cout<< Test( n2 )<<endl;
}
int Test(int x)
{
static int c=2;
c++;
return x*c;
}
3
void main()
{ 8
int n=1;
cout<< Test( n ) << endl;
cout<< Test( n + 1 ) <<
endl;
}
Question 4: Find the Errors (Logical or syntax)in the following
pieces of code then correct them. 6 points
Code Correction
int Arr[3][3]={{1,2},{4,5,6}};
for(int i=0;i<=3;i++)
{
for(int j=0;j<=3;j++)
i<3
{
cout<<Arr[i][j];
}
}
float fun(int x) float fun(int x)
{ {
float b; float b;
b=(x*5+3)/x; b=(x*5+3)/x;
} return b;
void main() }
{
cout<<fun(5);
}
int x , y =5; x= 0
while ( y <= 10 ) while ( y <= 10 )
y = x + 2; { y = x + 2;
x++; x++;
cout << y; }
int A[5]={3,5,6,4,1}; int i=0;
int i;
while(i<5)
{ A[i]+=5;
i++;
}
for( int x = 0 ; x <= 10 ; x++); for( int x = 0 ; x <= 10 ; x++)
{
Cout<< x <<endl;
}
1 𝑠 R=1/(pow(s,2)-6)+s/(s+1);
𝑅= +
𝑠2 − 6 𝑠 + 1