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

CS Practice String Output

The document contains 10 programming questions with outputs. The questions involve string manipulation functions like strlen(), tolower(), toupper(), isupper(), islower() etc. to modify strings. Example operations include reversing strings, encrypting/decrypting characters, replacing characters etc.

Uploaded by

Nita Arora
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)
82 views

CS Practice String Output

The document contains 10 programming questions with outputs. The questions involve string manipulation functions like strlen(), tolower(), toupper(), isupper(), islower() etc. to modify strings. Example operations include reversing strings, encrypting/decrypting characters, replacing characters etc.

Uploaded by

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

Computer Science Practice Assignment

S.NO. Q1. Sub Question Part (a) What will be the output of the following program: #include <iostream.h> void Secret(char Str[ ]) { for (int L=0;Str[L]!='\0';L++); for (int C=0;C<L/2;C++) if (Str[C]=='A' || Str[C]=='E') Str[C]=Str[L-C-1]; else { char Temp=Str[C]; Str[C]=Str[L-C-1]; Str[L-C-1]=Temp; } } void main() { char Message[ ]="PreboardExam"; Secret(Message); cout<<Message<<endl; } Ans.: maxEdraoberP (b) void funnystr(char *s, int n = 2) { int i = n; while(i < strlen(s)) { s[i] = '-'; i = i + n; } i = 0; while(s[i] != '\0') { if(s[i] > 'A' && s[i] < 'P') s[i] = tolower(s[i]); else if(s[i] > 'a' && s[i] < 'p') { if(i % 3 == 0) s[i] = tolower(s[i-1]); else s[i] = tolower(s[i]); } i++; } } void main() { char str[] = "MiCroSoFT"; funnystr(str,3); 1 Marks (3)

(3)

cout<<str; } (c) Ans.: mic-oS-fT Give the output of the following program: #include void ReCode ( char Text[ ], int Num ); void main ( ) { char Note [ ] = "Butterfly"; Recode (Note, 2); cout << Note <<endl; } void ReCode (char Text [ ], int Num) { for ( int K = 0 ; Text [K] !='\0' ; K++) if ( K % 2 == 0) Text [K] = Text [K]- Num; else if ( islower (Text[K] )) Text [K] = toupper ( Text [K] ) else Text[K] = Text[K] + Num; } (d) Ans.: @UrTcRdLw What will be the output of the following program: #include<iostream.h> #include<string.h> void main( ) { char Mes1[ ]=HuB, Mes2[ ]=ThaT, Mes3[ ]=BeSt; int L1=strlen(Mes1), L2=strlen(Mes2), L3=strlen(Mes3); int N=L1+L2+L3; for(int c=0; c<N; c++) { if(c%4==0) { cout<<Mes2[L2-1]; L2--; } else if(c%3==0) { cout<<Mes1[L1-1]; L1--; } else { cout<<Mes3[L3-1]; L3--; } } } Ans.: TtSBaeuBhH 2 3 3

(e)

Find the output of the following program (Assuming that all required header files are included) void main( ) { char NAME[ ] = admiNStrAtiOn; for( int x=0;x<strlen(NAME);x++) { if(islower(NAME[x])) NAME[x] = toupper(NAME[x]); else if(isupper (NAME[x])) if(x%2==0) NAME[x] = NAME[x -1]; else NAME[x]--; cout<<NAME <<endl; } } Ans.: ADMIIRTRRTINN 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

(f)

(g)

Find the output of the following program: (Assuming all header files are included) void Mycode(char Msg[],char C) { for(int i=0;Msg[i]!=\0;i++) { if(Msg[i]>=B && Msg[i]<=H) Msg[i]=tolower(Msg[i]); else if(Msg[i]==A || Msg[i]==a) Msg[i]=C; else 3

if(i%2==0) Msg[i]=toupper(Msg[i]); else Msg[i]=Msg[i-1]; } } void main() { char text[]=ApaCHeSeRvEr; Mycode(Text,#); cout<< New Line = <<text; } (h) Ans.: ###chhSSRRee 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 2012; 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.: CbSe *xAm*2113 3112*mxA* eSbC Find the output of the following program: #include <iostream.h> void Secret(char Str[ ]) { for (int L=0;Str[L]!='\0';L++); for (int C=0;C<L/2;C++) if (Str[C]=='A' || Str[C]=='E') Str[C]='#'; 4 3

(i)

else { char Temp=Str[C]; Str[C]=Str[L-C-1]; Str[L-C-1]=Temp; } } void main( ) { char Message[ ]="SteveJobs"; Secret(Message); cout<<Message<<endl; } Ans.: sboJevetS (j) Find the output of the following program; #include<iostream.h> #include<ctype.h> void main( ) { char TEXT1[ ] = Cbse@Board!; for(int I=0; TEXT1 [I]!=\0;I++) { if(!isalpha(TEXT1[I])) TEXT1[I]=*; else if(isupper(TEXT1 [I])) TEXT1[I]=TEXT1[I]+1; else TEXT1[I] = TEXT1[I+1]; } cout<<TEXT1; } Ans. : Dse@*Card!* 2

You might also like