+ All Categories
Home > Documents > Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

Date post: 04-Apr-2018
Category:
Upload: vandang
View: 217 times
Download: 4 times
Share this document with a friend
23
www.computerindia.co.in CBSE Question Output Questions CBSE 2018 (a) Find and write the output of the following C++ program code: [3] Note: Assume all required header files are already included in the program. void Revert(int &Num, int Last=2) { Last = (Last%2==0)?Last+1: Last-1; for(int C=1; C<=Last; C++) Num+=C; } void main() { int A=20, B=4; Revert(A,B); cout<<A<<”&”<<B<<endl; B--; Revert(A,B); cout<<A<<”#”<<B<<endl; Revert(B); cout<<A<<”#”<<B<<endl; } (b) Find and write the output of the following C++ program code: Note: Assume all required header files are already included in the program. #define Modify(N) N*3+10 void main() { int LIST[]={10,15,12,17}; int *P=LIST, C; for(C=3; C>=0; C--) LIST[C] = Modify(LIST[I]); for(C=0; C<=3; C++) { cout<<*P<<”:”; P++; } } By Kanhaya Sir Mobile No.: 9868772318 Page 1 of 23
Transcript
Page 1: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

CBSE 2018(a) Find and write the output of the following C++ program code: [3]

Note: Assume all required header files are already included in the program.void Revert(int &Num, int Last=2){

Last = (Last%2==0)?Last+1: Last-1;for(int C=1; C<=Last; C++)

Num+=C;}void main(){

int A=20, B=4;Revert(A,B);cout<<A<<”&”<<B<<endl;B--;Revert(A,B);cout<<A<<”#”<<B<<endl;Revert(B);cout<<A<<”#”<<B<<endl;

}

(b) Find and write the output of the following C++ program code:Note: Assume all required header files are already included in the program.#define Modify(N) N*3+10void main(){

int LIST[]={10,15,12,17};int *P=LIST, C;for(C=3; C>=0; C--)

LIST[C] = Modify(LIST[I]);for(C=0; C<=3; C++){

cout<<*P<<”:”;P++;

}}

(c) Look at the following C++ code and find the possible output(s) from the outputs (i) to (iv) following it. Also, write the highest and lowest values that can be assigned in the array A.Note: Assume all the required header files are already being included in the code. The function random(n) generates an integer between 0 and n-1.void main(){

randomize();int A[4], C;

By Kanhaya Sir Mobile No.: 9868772318Page 1 of 20

Page 2: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

for(C=0; C<4; C++)A[C] = random(C+1)+10;

for(C=3; C>=0; C--)cout<<A[C]<<”@”;

}

(i) (ii)13@10@11@10@ 15$14$12$10$(iii) (iv)12@11@13@10@ 12@11@10@10@

CBSE 2017(a) Find and write the output of the following C++ program code : 2

Note : Assume all required header files are already included in the program.

#define Big(A,B) (A>B)?A+1:B+2void main(){

char W[] = “Exam”;int L=strlen(W);for(int i=0; i<L-1; i++)

W[i] = Big(W[i], W[i+1]);cout<<W<<endl;

}(b) Find and write the output of the following C++ program code : 3 Note : Assume all required header files are already included in the program.

void main(){

int A[] = {10,122,15,17,20,30};for(int i=0; i<6; i++){

if(A[i]%2==0)A[i] /= 2;

else if(A[i]%3==0)A[i] /= 3;

if(A[i]%5==0)A[i] /= 5;

}for(i=0; i<6; i++)

cout<<A[i]<<”#”;}

(c) Look at the following C++ code and find the possible output(s) from the options (I) to (iv) following it. Also, write the maximum values that can be assigned to each of the variables R and C.

Note: 2

By Kanhaya Sir Mobile No.: 9868772318Page 2 of 20

Page 3: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

Assume all required header files are already being included in the code. The function random(n) generates a integer between 0 to n-1.

void main(){

randomize();int R=random(3), C=random(4);int MAT[3][3] = {{10,20,30},{20,30,40},{30,40,50}};for(int I=0; I<R; I++){

for(int J=0; J<C; j++)cout<<MAT[I][J]<<” “;

cout<<endl;}

}(i) (ii)

10 20 3020 30 4030 40 50

10 20 3020 30 40

(iii) (iv)

10 2020 30

10 2020 3030 40

CBSE 2016(a) Find and write the output of the following C++ program code : 2 Note : Assume all required header files are already included in the program. typedef char STRING[80]; void MIXITNOW(STRING S) { int Size=strlen(S);

for(int I=0;I<Size–1;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=”CRACKAJACK”; MIXITNOW(Word); cout<<Word<<endl;

By Kanhaya Sir Mobile No.: 9868772318Page 3 of 20

Page 4: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

} (e) Find and write the output of the following C++ program code : 3 Note : Assume all required header files are already being included in the program. class Stock {

long int ID; float Rate; int Date;

public: Stock(){ID=1001;Rate=200;Date=1;} void RegCode(long int I,float R) {

ID=I; Rate=R; } void Change(int New,int DT) { Rate+=New; Date=DT; } void Show() { cout<<”Date :”<<Date<<endl; cout<<ID<<”#”<<Rate<<endl; } }; void main() {

Stock A,B,C; A.RegCode(1024,150); B.RegCode(2015,300); B.Change(100,29); C.Change(–20,20); A.Show(); B.Show(); C.Show(); }

(c) Look at the following C++ code and find the possible output(s) from the options (i) to (iv) following it. Also, write the maximum and the minimum values that can be assigned to the variable CHANGER. 2

Note : • Assume all the required header files are already being included in the code. • The function random(n) generates an integer between 0 and n – 1 void main() {

By Kanhaya Sir Mobile No.: 9868772318Page 4 of 20

Page 5: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

randomize(); int CHANGER; CHANGER=random(3); char CITY[][25]={“DELHI”,”MUMBAI”,”KOLKATA”,”CHENNAI”}; for(int I=0;I<=CHANGER;I++) { for(int J=0;J<=I;J++) cout<<CITY[J]; cout<<endl; } }

By Kanhaya Sir Mobile No.: 9868772318Page 5 of 20

Page 6: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

(i) (ii)

DELHI DELHIMUMBAI DELHIMUMBAIKOLKATA DELHIMUMBAIKOLKATACHENNAI

DELHIDELHIMUMBAIDELHIMUMBAIKOLKATA

(iii) (iv)

MUMBAI MUMBAIKOLKATA MUMBAIKOLKATACHENNAI

KOLKATAKOLKATACHENNAI

CBSE 2015(a) Write the output of the following C++ program code:Note: Assume all required header files are already being included in the program.void Position(int & C1, int C2=3){C1+=2;C2 +=4;

} void main(){ int P1=20, P2=4;

Position(P1);cout<<P1<<”,”<<P2<<endl;Position(P2,P1);cout<<P1<<”,”<<P2<<endl;

}(b) Write the outout of the following C++ program code:Note: Assume all required header files are already being included in the program.class Calc{

char Grade;int Bonus;

public:Calc() { Grade='E'; Bonus=0; }void Down(int G){

Grade -= G;}void Up(int G){

Grader += G;Bonus++;

}

By Kanhaya Sir Mobile No.: 9868772318Page 6 of 20

Page 7: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

void Show(){

cout<<Grade<<”#”<<Bonus<<endl;}

};void main(){

Calc C;C.Down(2);C.Show();C.Up(7);C.Show();C.Down(2);C.Show();

}(c) Study the following program and select the possible output(s) from the option (I) to (iv) following it. Also, write the maximum and the minimum values that can be assigned to the variable NUM.- Assume all required header files are already being included in the program. random(n) function generates an integer between 0 to n-1.void main(){

randomize);int NUM;NUM = random(3) + 2;char TEXT[]=”ABCDEFGHIJK”;for(int I=1; I<=NUM; I++){

for(int J=NUM; J<=7; J++)cout<<TEXT[J];

cout<<endl;}

}(I) FGHI (ii) BCDEFGH (iii) EFGH (iv) CDEFGH (II) FGHI BCDEFGH EFGH CDEFGH

FGHI EFGH FGHI EFGH

CBSE 20141. (a) Obtain the output from the following C++ program as expected to appear on the

screen after its executionImportant Note:- All the desired header files are already included in the code, which are required to

run the code.void main(){

char *String=”SARGAM”;

By Kanhaya Sir Mobile No.: 9868772318Page 7 of 20

Page 8: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

int *Ptr, A[] = {1, 5, 7, 9};Ptr = A;cout<<*Ptr<<String<<endl;String++;Ptr+=3;cout<<*Ptr<<String<<endl;

}(b) Obtain the output of the following C++ program, which will appear on the screen after its execution.Important Note:- All the desired header files are already included in the code, which are required to

run the code.class Player{

int Score, Level;char Game;

public:Player(char GGame = ‘A’){

Score = 0;Level = 1;Game = GGame;

}void Start(int SC);void Next();void Disp(){

cout<<Game<<”@”<<Level<<endl;cout<<Score<<endl;

}};void main(){

Player P, Q ( ‘B’ );P.Disp();Q.Start(75);Q.Next();P.Start(120);Q.Disp();P.Disp();

}void Player :: Next(){

Game = (Game == ‘A’) ? ‘B’ : ‘A’;}void Player :: Start(int SC){

By Kanhaya Sir Mobile No.: 9868772318Page 8 of 20

Page 9: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

Score += SC;If(Score>=100)

Level = 3;else if(Score>=50)

Level = 2;else

Level = 1;}(b) Read the following C++ code carefully and find out, which out of the given options (i) to (iv) are expected correct output(s) of it. Also, write the maximum and minimum value that can be assigned to the variable Start used in the code:void main(){

int Guess[4] = {200, 150, 20, 250};int Start = random(2) + 2;for(int C=Start; C<4; C++)

cout<<Guess[C]<<”#”;}

(i) 200# 150# (iii) 150#20#250#(ii) 150#20# (iv) 20#250#

CBSE 20132. (a) Observe the following C++ code carefully and obtain the output, which will appear on

the screen after execution of it.Important Note:- All the desired header files are already included in the code, which are required to

run the code.void main(){

char *String = “SHAKTI”;int *Point, Value[ ] = { 10, 15, 70, 19};Point = Value;cout<<*Point<<String<<endl;String++;Point++;cout<<*Point<<String<<endl;

}(b) Observe the following C++ code carefully and obtain the output, which will appear

on the screen after execution of it.#include<iostream.h>class Aroundus{

int Place, Humidity, Temp; public:

Aroundus(int P=2){

Place = P;

By Kanhaya Sir Mobile No.: 9868772318Page 9 of 20

Page 10: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

Humidity = 60;Temp = 20;

}void Hot(int T){

Temp += T;}void Humid(int H){

Humidity += H;}void JustSee(){

cout<<Place<<”:”<<Temp<<”&”<<Humidity<<”%”<<endl;}

};void main(){

Aroundus A, B(5);A.Hot(10);A.JustSee();B.Humid(15);B.Hot(2);B.JustSee();A.Humid(5);A.JustSee();

}(c) Based on the following C++ code, find out the expected correct output(s) from the

options (i) to (iv). Also, find out the minimum and the maximum value that can be assigned to the variable Trick used in the code at the time when value of Count is 3:void main(){

char Status[][10] = { “EXCEL”, “GOOD”, “OK”};int Turn=10, Trick;for (int Count=1; Count<4; Count++){

Trick = random(Count);cout<<Turn-Trick<<Status[Trick]<<”#”;

}}(i) 10EXCEL#10EXCEL#8OK#(ii) 10EXCEL#8OK#9GOOD#(iii) 10EXCEL#9GOOD#10EXCEL#(iv) 10EXCEL#10GOOD#8OK#

By Kanhaya Sir Mobile No.: 9868772318Page 10 of 20

Page 11: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

CBSE 20123. (a) Find the output of the following program:

#include <iostream.h>class TRAIN{

int Tno, TripNo, PersonCount;public:

TRAIN(int Tmno=1){

Tno = Tmno;TripNo = 0;PersonCount=0;

}void Trip(int TC=100){

TripNo++;PersonCount+=TC;

}void Show(){

Cout<<Tno<<”:”<<TripNo<<”:”<<PersonCount<<endl;}

};void main(){

TRAIN T(10), N;N.Trip();T.Show();T.Trip(70);N.Trip(40);N.Show();T.Show();

}(b) Find the output of the following program:

#include <iostream.h>#include <ctype.h>Typedef char Txt80 [80];void main(){

char *PText;Txt80 Txt = “Ur2GReAt”;int N = 6;PText = Txt;while (N>=3){

Txt[N] = (isupper(Txt[N]) ? tolower(Txt[N]) : toupper(Txt[N]));cout<<PText<<endl;

By Kanhaya Sir Mobile No.: 9868772318Page 11 of 20

Page 12: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

N--;PText++;

}}

(c) Observe the following program and find out, which output(s) out of (i) to (iv) will not be expected from the program? What will be the minimum and the maximum value assigned to the variable Chance?#include <iostream.h>#include <stdlib.h>void main(){

randomize();int Game[ ] = {10,16}, P;int Chance = random(2) + 5;for(int T=0; T<2; T++){

P = random(2);cout<<Game[P]+Turn<<”#”;

}}(i) 15#22#(ii) 22#16#(iii) 16#21#(iv) 21#22#

CBSE 20114.(a) Find the output of the following program:

#include<iostream.h>void SwitchOver ( int A[ ], int N, int Split ){

for ( int K=0; K<N; K++ ) if( K < Split )

A[K] += K;else

A[K] *= K;}void Display ( int A[ ], int N ){

for( int K=0; K<N; K++ )(K%2 != 0)? cout<<A[K]<<"%" : cout<<A[K]<<endl;

}void main( ){

int H [ ] = {30, 40, 50, 20, 10, 5 };SwitchOver ( H, 6, 3 );Display ( H, 6 );

}

By Kanhaya Sir Mobile No.: 9868772318Page 12 of 20

Page 13: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

(b) Find the output of the following program : #include <iostream.h>void main(){

int *Queen, Moves [ ] = {11, 22, 33, 44 };Queen = Moves;Moves[2] += 22;cout<<”Queen @”<<*Queen<<endl;*Queen -= 11;Queen += 2;cout<<”Now @”<<*Queen<<endl;Queen++;cout<<”Finally @”<<*Queen<<endl;cout<<”New Origin @”<<Moves[0]<<endl;

}(c) Go through the C++ code shown below, and find out the possible output or outputs

from the suggested Output Options (i) to (iv). Also, write the minimum and maximum values, which can be assigned to the variable MyNum.

2#include <iostream.h>#include <stdlib.h>void main(){

randomize();int MyNum, Max = 5;MyNum = 20 + random(Max);for ( int N=MyNum; N<=25; N++)

cout<<N<<”*”;}(i) 20*21*22*23*24*25(ii) 22*23*24*25*(iii) 23*24*(iv) 21*22*23*24*25*

CBSE 2010a) Find the output of the following program:

#include <iostream.h>struct THREE_D{ int X, Y, Z; };void MoveIn(THREE_D &T, int Step = 1){

T.X += Step;T.Y -= Step;T.Z += Step;

}void MoveOut ( THREE_D &T, int Step = 1){

By Kanhaya Sir Mobile No.: 9868772318Page 13 of 20

Page 14: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

T.X -= Step;T.Y += Step;T.Z -= Step;

}void main(){

THREE_D T1 = {10, 20, 5}, T2 = {30, 10, 40};MoveIn ( T1 );MoveOut ( T2, 5 );cout<<T1.X<<”,”<<T1.Y<<”,”<<T1.Z<<endl;cout<<T2.X<<”,”<<T2.Y<<”,”<<T2.Z<<endl;MoveOut ( T2, 10);cout<<T2.X<<”,”<<T2.Y<<”,”<<T2.Z<<endl;

}b) Find the output of the following program:

#include<iostream.h>#include<ctype.h>void MyCode(char Msg[ ], char CH){

for (int Cnt=0; Msg[Cnt] != ‘\0’; Cnt++){

if (Msg[Cnt] >=’B’ && Msg[Cnt] <= ‘G’)Msg[Cnt] = tolower(Msg[Cnt]);

elseif (Msg[Cnt] ==’A’ || Msg[Cnt]==’a’)

Msg[Cnt] = CH;elseif(Cnt%2==0)

Msg[Cnt] = toupper(Msg[Cnt]);else

Msg[Cnt] = Msg[Cnt-1];}

}void main(){

char MyText[]=”ApEACeDriVE”;MyCode(MyText, ‘@’);Cout<<”NEW TEXT:”<<MyText<<endl;

}(c) The following code is from a game, which generates a set of 4 random numbers. Praful is

playing this game, help him to identify the correct option(s) out of the four choices given below as the possible set of such numbers generated from the program code so that he wins the game. Justify your answer.#include<iostream.h>#include<stdlib.h>const int LOW=25;void main()

By Kanhaya Sir Mobile No.: 9868772318Page 14 of 20

Page 15: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

{randomize();int POINT=5, Number;for( int I=1; I<=4; I++){

Number=LOW + random(POINT);cout<<Number<<”:”;POINT--;

}}(i) 29:26:25:28:(ii) 24:28:25:26:(iii) 29:26:24:28:(iv) 29:26:25:26:

CBSE 20095.(a) Find the output of the following program:

#include <iostream.h>void main(){

int X [ ] = {10, 25, 30, 55, 110 };int *p = X;while ( *p < 110 ){

if( *p % 3 != 0 )*p = *p + 1;

else*p = *p + 2;

p++;}for( int I=4; I>=1; I--){

cout<<X[I]<<”*”;if( I%3==0)

cout<<endl;}cout<<X[0] *3<<endl;

}(b) Find the output of the following program:

#include <iostream.h>#include <ctype.h>void Encode ( char Info[ ], int N);void main(){

char Memo [ ]= “Justnow”;Encode(Memo, 2);

By Kanhaya Sir Mobile No.: 9868772318Page 15 of 20

Page 16: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

cout<<Memo<<endl;}void Encode ( char Info[ ], int N){

for ( int I=0; Info[I] != ‘\0’; I++)if ( I%2 == 0)

Info[I] = Info[I] – N;else if ( islower(Info[I]))

Info[I] = toupper(Info[I]);else

Info[I] = Info[I] + N;}

a) Study the following program and select the possible output from it:#include <iostream.h>#include <stdlib.h>const int LIMIT = 4;void main(){

randomize();int Points;Points = 100 + random ( LIMIT );for ( int P=Points; P>=100; P--)

cout<<P<<”#”;cout<<endl;

}(i) 103#102#101#100#(ii) 100#101#102#103#(iii) 100#101#102#103#104#(iv) 104#103#102#101#100#

CBSE 20087.a) Find the output of the following program:

#include <iostream.h>#include <conio.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;

elseText[I] = Text[I + 1];

}cout<<Text;

By Kanhaya Sir Mobile No.: 9868772318Page 16 of 20

Page 17: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

}

b) Find the output of the following program:#include <iostream.h>void main(){

int U = 10, V = 20;for( int I=1; I<=2; I++){

cout<<”[1]=”<<U++<<”&”<<V-5<<endl;cout<<”[2]=”<<++V<<”&”<<U+2<<endl;

}}

c) 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:

By Kanhaya Sir Mobile No.: 9868772318Page 17 of 20

Page 18: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

CBSE 20078.a) Find the output of the following program:

#include <iostream.h>void main(){

int Array[ ] = { 4, 6 10, 12 };int *pointer = Array;for ( int I=1’ i<=3; i++){

cout<<*pointer<<”#”;pointer++;

}cout<<endl;for (I=1; I<=4; I++){

(*pointer) *= 3;--pointer;

}for (I=1; I<5; I++)

cout<<Array[I-1]<<”@”;cout<<endl;

}b) Find the output of the following program:

#include <iostream.h>void Withdef ( int HisNum = 30){

for (int I=20; I<=HisNum; I+=5)cout<<I<<” “;cout<<endl;

}void Control (int & MuNum){

MyNum+=10;Withdef(MyNum);

}void main(){

int YourNum = 20;Control(YourNum);Withdef();cout<<”Number=”<<YourNum<<endl;

}

By Kanhaya Sir Mobile No.: 9868772318Page 18 of 20

Page 19: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

c) In the following C++ program what is the expected value of MyMarks from Option (i) to (iv) given below. Justify answer.#include <stdlib.h>#include <iostream.h>void main(){

randomize();int Marks [ ] = {99, 92, 94, 96, 93, 95 }, MyMarks;MyMarks = Marks [ 1 + random(2) ];

}(i) 99 (ii) 94 (iii) 96 (iv) None of the above

CBSE 20069.(i) Find the output of the following program:

#include <iostream.h>#include <string.h>class state{

char *state_name;int size;

public:state() { size=0; state_name = new char [ size+1]; }state(char *s){

size = strlen(s);state_name = new char [size+1];

}void display(){

cout<<state_name<<endl;}void Replace ( state & a, state & b){

size = a.size + b.size;delete state_name;state_name = new char [size + 1];strcpy(state_name, a.state_name);strcat(state_name, b.state_name);

}};void main(){

char *temp = “Delhi”;state state1(temp), state2(“Mumbai”), state3(“Nagpur”), S1,S2;S1.Replace(state1, state2);S2.Replace(S1, state3);

By Kanhaya Sir Mobile No.: 9868772318Page 19 of 20

Page 20: Q - Computer Tuitions · Web viewSTRING Word=”CRACKAJACK”; MIXITNOW(Word); cout

www.computerindia.co.in CBSE Question Output Questions

S1.display();S2.display();

}b) Find the output of the following program:

#include <iostream.h>void main(){

long NUM = 1234543;int F=0, S=0;do{

int Rem = NUM%10;if(Rem%2 != 0)

F += Rem;else

S += Rem;NUM /= 10;

}while(NUM > 0);cout<<F-S;

}

By Kanhaya Sir Mobile No.: 9868772318Page 20 of 20


Recommended