Delhi Public School Navi Mumbai Revision Examination 2016-17. I. Answer The Following Questions
Delhi Public School Navi Mumbai Revision Examination 2016-17. I. Answer The Following Questions
NAVI MUMBAI
REVISION EXAMINATION 2016-17.
char ch , out[10]="\0";
cin>>ch;
switch(ch)
{
case 'a' : strcat(out,"a");
case 'b' : strcat(out, "b");
case 'c' : strcat(out,"c");
break;
case 'd' : strcat(out,"d");
default : strcat(out,"Not abcd");
break; }
4.Explain the sizeof( ) operator with an example
5.What is typedef? Explain with example.
6.What is a macro. Explain with an example.
IV. Give the output for the following code snippets. Assume all header files are
included.
void main()
{int x=5 , y=22;
doupd(::x,y);
cout<<x<<":"<<y<<":"<<::x<<endl;
doupd(y,x);
cout<<x<<":"<<y<<":"<<::x<<endl;
}
f. [2]
void main()
{ int y=0;
while(y<=10)
{ int x=1;
do{x++;
if(x%3==2) cout<<"#";
}while(x<3);
y+=6; cout<<"%";
}}
g. [2]
void main()
{ int a[ ]={18,12,45,54,71},i;
for(i=0;i<4;i++)
if(!(a[i]%9))
a[i+1]=a[i]*2;
else
a[i]=a[i+1];
for(i=0;i<5;i++)
cout<<a[i]<<"@";}
V Identify the syntax errors in the following codes. Rewrite the corrected code
and underline the corrections. [2 + 2]
a. #define pi = 3.1451
#define circlearea(int x) ( pi *x*x);
void main( )
{ float area; int r;
cin>>r; area = circlearea(x);
cout<<area;
}
b. main( )
{struct bank
{ char cname[25] ; char ccode[5];
char loantype[15] ;
float depamt;
}customer;
Customer cust; strcpy(cname , “Raju”);
cust.ccode = “C105”; cust.depamt = 25000 ;
customer = cust;
cout<<customer.ccode<<bank.cname<<cust.depamt;
}
VI Do the following
A. Write a program to accept a single character from the user. [2]
Use a SINGLE NESTED CONDITIONAL(TERNARY) OPERATOR to check for the following
If digit is entered display “DIGIT”
If alphabet is entered display the alphabet in uppercase
For any other entry display “SYMBOL”
B. Write a program to read a line of text in a string. Display
total number of words and
total number of characters in the text. [3]
C. Pivot index of an array is an index number where the sum of numbers on the left (from that
point ) is equal to the sum of numbers on the right(from that point).
Example if the array is
3 1 2 41 0 6
Write a function checkpivot(int a[ ]) that would accept a one dimensional integer array as
argument and find the pivot index. If there is a pivot index the index number should be displayed
else the message “NO PIVOT INDEX FOUND” should be displayed.
E. In a 2D array if each descending diagonal from left to right has the same number then the
matrix is called a TOEPLIZ matrix. Example : [4]
6 7 8 9 2
4 6 7 8 9
1 4 6 7 8
0 1 4 6 7
Write a function TZ( ) that would accept a 2 dimensional integer array , its total rows and its total
column as arguments. The function checks if the given array is a TOEPLIZ matrix or not. If yes
the function should return 1 else the function should return -1. Write main( ) to accept values into
the array , call the function and display appropriate message after checking the returned value.
ANSWER KEY
I
1. a. Low level language are written in binary language whereas a HLL should be processed so
as to make it understandable to the computer. Language processors convert HLL to machine
language.
b. RAM is volatile while ROM is nonvolatile.
2. Transistors replaced vacuum tubes, core memory developed, First operating systems
developed, programming in machine and assembly language, magnetic tapes and disks were
used.
3. Corrective maintenance – When a program after completion is put to operations some errors
due to unexpected situations ,untested areas may occur. this is fixed and this type of maintenance
is corrective maintenance.
Preventive maintenance - If possible errors could be anticipated before they actually occur
maintenance could bedone to avoid them. This is preventive maintenance.
4.
int main()
{
for(int i=0 ; i<=10 ; i++)
if(i%2)
cout<<i<<’ ‘;
else
cout<<i+2;
return 0;
}
5. The type of error is runtime error. Errors that occur during the execution of a program are
runtime errors.Eg : infinite loop or wrong value(of different data type) is entered.
II CONVERSIONS
a. 1221758
b. 1101011110.010111002
c. 315.9062510
d. 5b2f16
e. 347.7510
III
ANSWER THE FOLLOWING
1.
2. setw ()
3. a abc
b bc
d dNotabcd
h Notabcd
OUTPUTS
b. one
c.
d. random
e.
f.
*#*%*#*%
g.
18@36@72@144@288@
A. CONDITIONAL OPERATOR
void main()
{char ch;
cin>>ch;
isalpha(ch)? cout<< (char)toupper(ch) : isdigit(ch) ? cout<<"Digit" : cout<<"Symbol";
}
B.
C.PIVOT INDEX
void main()
{int a[]={1,2,3,4,0,6} ,sumj=0,sumk=0;
for(int i=0;i<6;i++)
{sumj=0;sumk=0 ;
for(int j=0;j<i;j++)
sumj += a[j];
for(int k=i+1;k<6;k++)
sumk+=a[k];
if(sumj==sumk)
{cout<<i; break;}
}
if(i==6)
cout<<"No pivot";}
D. ANAGRAM
void main()
{char a[20],b[20];
gets(a); gets(b);
int i=0,j=0,x=0,y=0,flag=0;
while(a[i] !='\0')
{ char d = a[i]; x=y=0;
for(j=0;j<strlen(a);j++)
{ if(a[j]==d)
x++;
if (b[j]==d)
y++;
}
if(x!=y)
{flag=1;break;}
i++;
}
if(flag==1)
cout<<"No";
else
cout<<"yes";
}
E.TOEPLIZ MATRIX CHECK
void main()
{int a[4][5]={{6,7,8,9,2},{4,6,7,8,9},{1,4,6,7,8},{0,1,4,6,7}} ;
int r=4,c=5,flag=0;
for(int i=0;i<r-1;i++)
{ for(int j=0;j<c-1;j++)
{ if(a[i][j] != a[i+1][j+1])
{ flag = -1; }
}
}
if(flag==0)
cout<<"Toepliz";
else
cout<<"No";
}