Monday, 2 December 2019

Important Output Finding Questions Based On Randomize And Pointer Concept Class-12




Important Output Finding Questions Based On Randomize And Pointer Concept
Class-12
1. Find the output of the following program :
#include<iostream.h>
#include<ctype.h>
void Secret(char Msg[ ], int N);
void main( )
{ char SMS[ ]=”rEPorTmE”;
Secret(SMS,2);
cout<<SMS<<endl;
}
void Secret(char Msg[ ], int N)
{ for(int C=0;Msg[C]!=’\0’;C++)
if(C%2= =0)
Msg[C]=Msg[C]+N;
else if(isupper(Msg[C]))
Msg[C]=tolower(Msg[C]);
else
Msg[C]=Msg[C]-N;
}
Ans: teRmttoe
2. Study the following program and select the possible output from it:
#include<iostream.h>
#include<stdlib.h>
const int MAX=3;
void main( )
{ randomize( );
int Number;
Number=50+random(MAX);
for(int P=Number;P>=50;P--)
cout<<P<<”#”;
cout<<endl;
}
(i) 53#52#51#50# (ii) 50#51#52#
(iii) 50#51# (iv) 51#50#
Ans: (iv) 51#50#
Solution: MAX value is 3 That’s why random(MAX) can produce 0 or 1 or 2. (random(N) will produce no. between 1 to n-1) The Number value may be 50 or 51 or 52. The P value starts from Number, upto 50, each time decreases by 1. So Possible outputs are as follows:
52#51#50#
51#50#
50#
As the output 51#50# is available in given answers, so 51#50# is the answer.)
3.  Find the output of the following program;
#include<iostream.h>
#include<ctype.h>
void main( )
{ char Text[ ] = “Mind@work!”;
for(int I=0; Text[I]!=’\0’;I++)
{ if(!isalpha(Text[I]))
Text[I]=’*’;
else if(isupper(Text[I]))
Text[I]=Text[I]+1;
else
Text[I] = Text[I+1];
}
cout<<Text;
}
Ans): Output: Nnd@*Xrk!*
4. In the following program, find the correct possible output(s) from the options:
#include<stdlib.h>
#include<iostream.h>
void main( )
{ randomize( );
char City[][10]= {“DEL”,”CHN”,”KOL”,”BOM”,”BNG”};
int Fly;
for(int I=0; I<3;I++)
{ Fly=random(2) + 1;
cout<<City[Fly]<<”:”;}
}
Outputs:
(i) DEL : CHN : KOL:
(ii) CHN: KOL : CHN:
(iii) KOL : BOM : BNG:
(iv) KOL : CHN : KOL:
Ans): Since random(2) gives either 0 or 1, Fly value will be either 1 or 2.(random(n) gives you any number between 0 to n-1)City[1] is “CHN”. City[2] is “KOL”.Since I value from 0 to 2 (ie<3), 3 iterationswill takes place.So the possible output consists 3 strings separated by :, each of them may be either “CHN” or “KOL”.
So the possible output will be
(ii) CHN : KOL : CHN:
(iv) KOL :CHN : KOL:

5. Find the output of the following program:
#include<iostream.h>
#include<ctype.h>
void main( )
{ char Mystring[ ] = "what@OUTPUT!";
for(int I=0; Mystring[I]!='\0';I++)
{ if(!isalpha(Mystring[I]))
Mystring[I]='*';
else if(isupper(Mystring[I]))
Mystring[I]=Mystring[I]+1;
else
Mystring[I] =Mystring[I+1];
}
cout<<Mystring;}
Ans: Output:
hat@*PVUQVU*

6. In the following program, find the correct possible output(s) from the options:
#include<stdlib.h>
#include<iostream.h>
void main( )
{ randomize( );
char Area[ ][10]={“NORTH”,”SOUTH”,”EAST”,”WEST”};
int ToGo;
for(int I=0; I<3;I++)
{ ToGo=random(2) + 1;
cout<<Area[ToGo]<<”:”;
}}
2
Ans: Outputs:
(i) SOUTH : EAST : SOUTH :
(ii) NORTH : SOUTH : EAST :
(iii) SOUTH : EAST : WEST :
(iv) SOUTH : EAST : EAST :
Ans) Since random(2) gives either 0 or 1, ToGo value will be either 1 or 2.(random(n) gives you any number between 0 to n-1) Area[1] is “SOUTH”. Area[2] is “EAST”.Since I value from 0 to 2 (ie<3), 3 iterations will takes place. So the possible output consists 3 strings separated by :, each of them may be either “SOUTH” or “EAST”.
So the possible output will be
(i) SOUTH : EAST : SOUTH :
(iv) SOUTH : EAST : EAST :



7. Find the output of the following program.
#include<iostream.h>
#include<string.h>
#include<ctype.h>
void Convert(char Str[ ],int Len)
{ for(int Count=0;Count<Len;Count++)
{ if(isupper(Str[Count]))
Str[Count]=tolower(Str[Count]);
else if (islower(Str[Count]))
Str[Count]=toupper(Str[Count]);
else if(isdigit(Str[Count]))
Str[Count]=Str[Count]+1;
else Str[Count]=’*’;
}
}
void main( )
{ char Text[ ]=”CBSE Exam 2005”;
int Size = strlen(Text);
Convert(Text,Size);
cout<<Text<<endl;
for(int C=0,R=Size – 1;C<=Size/2;C++,R--)
{ char Temp=Text[C];
Text[C]=Text[R];
Text[R]=Temp;
}
cout<<Text<<endl;
}
Ans:Output: cbse*eXAM*3116
8. Find and write the output of the following C++ program code:
Note: Assume all required header files are already being included in
the program.
void main( )
{
int Ar[ ] = { 6 , 3 , 8 , 10 , 4 , 6 , 7} ;
int *Ptr = Ar , I ;
cout<<++*Ptr++ << '@' ;
I = Ar[3] - Ar[2] ;
cout<<++*(Ptr+I)<<'@'<<"\n" ;
cout<<++I + *Ptr++ << '@' ;
cout<<*Ptr++ <<'@'<< '\n' ;
for( ; I >=0 ; I -=2)
cout<<Ar[I] << '@' ;
}
Ans 7@11@
6@8@
11@3@
9. Find and write the output of the following C++ program code:
typedef char STRING[80];
void MIXNOW(STRING S)
{
 int Size=strlen(S);
 for(int I=0;I<Size;I+=2)
 {
 char WS=S[I];
S[I]=S[I+1];
 S[I+1]=WS;
}
for (I=1;I<Size;I+=2)
 if (S[I]>=’M’ && S[I]<=’U’)
 S[I]=’@’;
}
void main()
{
 STRING Word=”CBSEEXAM2019”;
MIXNOW(Word);
cout<<Word<<endl;
}
Ans. BCE@XEMA0291



LIST OF PROGRAMS ON PYTHON STRINGS CLASS-11




Programs on Python Strings
Class-11
Q1. Write Python script to input a string and a character and count the number of occurrences of the character in the string.
Q2. Write Python script to input a string and display it in reverse order.
Q3. Write Python script to input a string and check whether it is a palindrome or not.
Q4. Write Python script to input a string and count the number of words in it.
Q5. Write Python script to input a string and count the number of words beginning with ‘A; or ‘a’.
Q6. Write Python script to input a string and replace the first letter of every word to uppercase and then display it.
Q7. Write Python script to input a string and replace all occurrences of the word ‘the’ with ‘that’.
Q8. Write Python script to input a string and count and display the number of capital alphabets, small alphabets and numbers.
Q9. Write a program to read a line of strings and count total no. of uppercase and lowercase characters.
Q10. Write  program to input the line of strings and replace each uppercase alphabet with '*' symbol and each lowercase character with '@'


Sunday, 1 December 2019

LIST OF PYTHON PROGRAMS ON LIST CLASS-11




Programs On Python Lists
Class-11

1.   Write a Python program to get the largest number from a list
2.   Write a Python program to get the smallest number from a list
3.   Write a program to input 10 numbers from the user and then display this list of numbers in reverse order.
4.   Write a program to input 10 numbers from the user and find their sum and average.
5.   Write a program to create a list of 10 random integers in the range 10 to 99, and display this list. Then display all the odd elements of the list.
6.   Write a Python program to remove duplicates from a list.
7.   Write a Python program to check a list is empty or not.
8.   Write a Python program to print a specified list after removing the 0th, 4th and 5th elements.
9.   Write a Python program to find all the values in a list are greater than a specified number.
10. Write a program to create a list names1 to store the names of n1 students of a class. Also create a list names2 to store the names of n2 students of another class. n1, n2, and the names are to be input from the user. Then combine these two lists into a new list and display this new list in the ascending order of names.
11. Write a menu driven program which creates an empty list and gives the following options to the user to perform various operations on a list:
(i)   Append an element to the list
(ii)  Input an element from the user and remove it from the list
(iii) Remove all elements from the list
(iv) Count the number of occurrences of an element in the list
(v)  Sort the list
(vi) Reverse the list 
(vii)         Display the list
The program should terminate when the user chooses the option to exit.