0% found this document useful (0 votes)
461 views

Assignment 5 (CLASS Xi Computer Science C++)

The document contains questions related to functions and arrays in C++. It asks about advantages of functions, function signatures, differences between built-in and user-defined functions, effects of const keyword in parameters, uses of default arguments, differences between formal and actual parameters, types of arrays, array characteristics, indexes, element numbers and memory occupied in array declarations, valid and invalid array declarations, assigning values to array elements, differences between local and global variables, outputs of sample programs with functions and arrays, and finding/correcting errors in code snippets involving functions and arrays.

Uploaded by

Kanchan Khurana
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
461 views

Assignment 5 (CLASS Xi Computer Science C++)

The document contains questions related to functions and arrays in C++. It asks about advantages of functions, function signatures, differences between built-in and user-defined functions, effects of const keyword in parameters, uses of default arguments, differences between formal and actual parameters, types of arrays, array characteristics, indexes, element numbers and memory occupied in array declarations, valid and invalid array declarations, assigning values to array elements, differences between local and global variables, outputs of sample programs with functions and arrays, and finding/correcting errors in code snippets involving functions and arrays.

Uploaded by

Kanchan Khurana
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

ASSIGNMENT 5

(CLASS Xi computer science c++)

FUNCTION AND ARRAYS

Q1. Write down four advantages of function?

Q2. What do you understand by function signature/prototype?

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?

Q5. When are default arguments useful?

Q6. Define actual and formal parameters?

Q7. Name different type of arrays?

Q8. List the characteristics of an array?

Q9. What is index/subscript in array declaration?

Q10. Write numbers of element and byte occupied in following declaration of


array:

(i) int A[5][6] (ii) char c[5][10] (iii) float p[10]

(iv) long int k[7] (v) char name[15]

Q11. Which of the following are invalid array declaration and why :

(i) int m[+10] (ii) int a[0.9] (iii) int a[-10]

(iv) int p[5]

Q12. Write C++ statements for the following:

(i) Assign value 10 to 6th element of array called marks.

(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.

Q14. Write down output of the following program code:

(A)#include<iostream.h> (B)#include<iostream.h>

void execute(int &b,int c=50) void main( )

{ {

int t=b+c; int i=4;

b+=t; int a;

if(c!=100) a=add(i);

cout<<t<<b<<c<<”\n”; cout<<a;

} }

void main( ) int add(int j)

{ {

int p=90,q=10; if(j>=4)

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>

void main( ) void execute(int a,int &b,int c=50)

{ {

int i,a; if( ++a>c)

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; {

b=j*j; int p=3,q=5;

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 j=5; int p=9;

void main( ) void main( )

{ {

int i=4,j=5; int i=4,p=5;

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;

int add(int j) cout<<a<<p;

{ }

if(j>=4) }

j=j*j;

else

j=::j*2;

return(j);

Q15. Write down output of the following program code:

(i) void main() (ii) void main()

{ {

int a[5]={9,3,66,6,21}; int a[6]={10,12,15,20,25,30};

int k; int i,jk=1,m;

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++)

for(int i=0;i<4;i++) if(i%2==0)

b[i]=2*i; t[i]=@;

for(i=3;i>=0;i--) cout<<t;

cout<<”\n”<<<b[i];

}
(v)void main() (vi)void main()

{ {

char w[7] Char p[]=”coMputeR scieNce”;


[20]={“Monday”,”Tuesday”,
for(int i=0;p[i]!=’\0’;i++)
”wenesday”,”Thursday”,
{
”Friday”,”Saturday”,”Sunday”};
if(islower(p[i])
for(int i=0;i<7;i++)
p[i]=toupper(p[i];
cout<<w[i]<<”\n”;
else if(isupper(p[i])
}
p[i]=tolower(p[i];

cout<<p;

Q16. Find out error in the following program code and rewrite the correct code:

(a) void main ( ) (b) void display(int m[][],int p,int q)

{ {

int fun1(int p,int q=10,int r) for(int i=0;i<m;i++)

for(int j=0;j<n:j++)
cout<<m[i][j];

int t=p+q; }

cout<<p<<q void main( )

p=+t; {

q=q+p int a[10[10],m,n

cout<<P<<q<<t; for(int i=0;i<m:i++)

return(p+q); for(int j=0,j<n,j++)

} cin>.a[i][j];

void main() display(a,m,n);

{ }

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;

for(int i=0;i<s;i++) c=div(a,b);

s+=a[i]; cout<<c;

a[0]=a[s-1]; }

return(s); int div(int a,int b)

} {

a=a+b;

b=b+b;
return(a,b);

}
(e) void main( ) (f) void main( )

{ {

int s[2,4]; const int k=8;

for(int i=0;i<2;i++) int a=9;b=5,c;

for(int j=0;j<=4;j++) c=div(a,b);

cout<<sum k=c+a;

} cout<<c<<k;

int div(int a,int b)

a=a+b;

b=b+b;

return(b);

You might also like