Assignment 5 (CLASS Xi Computer Science C++)
Assignment 5 (CLASS Xi Computer Science C++)
Q3. What is the difference between user defined function and built in
function?
Q4. What is the effect of writing keyword const as a prefix to any formal
argument?
Q11. Which of the following are invalid array declaration and why :
(ii) Assign value 20 to element at 3rd row and 5th column of array
A.
Q13. What is the difference between local and global variable. Give example.
(A)#include<iostream.h> (B)#include<iostream.h>
{ {
b+=t; int a;
if(c!=100) a=add(i);
cout<<t<<b<<c<<”\n”; cout<<a;
} }
{ {
execute(p); j=j*j;
cout<<p<<q<”\n”; else
execute(p,q); j=j*2;
cout<<p<<q<”\n”; return(j);
} }
(C) #include<iostream.h> (d) #include<iostream.h>
{ {
for(i=1;i<=5;i++) b++;
a=add(i); else
cout<<a; b--;
} cout<<a<<”\t”<<b<<”\t”<<c<<”\n”;
int add(int j) }
{ void main( )
int b; {
else execute(p,q,q);
j=j*2; cout<<p<<”\t”<<q<”\n”;
return(j); execute(p,q);
} cout<<p<<”\t”<<q<”\n”;
execute(q,p,q);
cout<<p<<”\t”<<q<”\n”;
}
(E)#include<iostream.h> (F) )#include<iostream.h>
{ {
int a; int a;
a=add(i); a=i+p;
cout<<a<<j; i=a+::p
a=add(::j); cout<<a<<”\t”<<i<<”\t”<<p;
cout<<a<<::j; {
int p=4,a=3;
} p=p+a;
{ }
if(j>=4) }
j=j*j;
else
j=::j*2;
return(j);
{ {
for(k=4;k>=0;k--) i=++a[k];
cout<<a[k]<<”\n”; j=a[3]++;
} m=a[k++];
cout<<i<<”\t”
<<j<<”\t”<<k<<”\t”<<m;
}
(iii)void main() (iv)char t[]=”democracy at
work “
{
int b[4]; for(int i=0;t[i]!=10;i++)
b[i]=2*i; t[i]=@;
for(i=3;i>=0;i--) cout<<t;
cout<<”\n”<<<b[i];
}
(v)void main() (vi)void main()
{ {
cout<<p;
Q16. Find out error in the following program code and rewrite the correct code:
{ {
for(int j=0;j<n:j++)
cout<<m[i][j];
int t=p+q; }
p=+t; {
} cin>.a[i][j];
{ }
int a,b=5,c;
a=fun1(a:b);
cout<<a<<b;
b=fun1(a,b,c)
}
(c) int sum(const int a[],int s) (d) void main( )
{ { int a,b,c;
s+=a[i]; cout<<c;
a[0]=a[s-1]; }
} {
a=a+b;
b=b+b;
return(a,b);
}
(e) void main( ) (f) void main( )
{ {
cout<<sum k=c+a;
} cout<<c<<k;
a=a+b;
b=b+b;
return(b);