XII CBSE Previous Year Question Paper QUESTION NO 1 (D) 2 or 3 Marks
1. (d) Find the output of the following program : Delhi #include class state { char *state_name; int size; public: state( ); { size=0; state_name=new char[size+1]; } state(char *s) Contd…
{ size = strlen(s) ; state_name = new char[size+1]; strcpy(state_name,s); } 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+l]; strcpy(state_name, a.state_name); strcat(state_name, b.state_name); } }; contd…
void main( ) { char * temp = “Delhi”; state state1 (temp), state2(“Mumbai”), state3(“Nagpur”), S1, S2; S1.Replace(state1, state2); S2. Replace(S1, state3); S1.display( ); S2.display( ); }
Answer: (d) DelhiMumbai DelhiMumbaiNagpur (3 full marks for identifying error in definition of the constructor state() in Line 7) OR (3 marks for the correct lines of output) OR (2 marks for any one correct line of output) OR (1 Mark for showing the output starting with Delhi)
2 (d) Find the output of the following program : OD #include class student { char *name; int l; public: student() { l=0; name=new char[1+1]; } student(char *s) { l=strlen(s); name=new char[1+1]; strcpy (name,s); } contd…
void display() { cout<<name<<endl;} void manipulate(student & a, student & b) { l=a.l + b.l; delete name; name=new char[l+l]; strcpy(name, a.name); strcat(name, b.name); } };
void main() { char * temp =''Jack''; student name1(temp), name2('' Jill''), name3('' John'' ),S1,S2; S1.manipulate(name1,name2); S2.manipulate(S1,name3); S1.display(); S2.display(); }
Answer : (d) JackJill JackJillJohn (2 marks for any one correct line) (Full 3 marks for both lines correct) (½ mark to be deducted from full 3 marks, if endl is not considered)
3 (d) Find the output of the following program : Delhi #include void main() { int Numbers[] = {2,4,8,10}; int *ptr = Numbers; for (int C = 0; C<3; C++) { cout<< *ptr << ptr++; }
3 (d) Find the output of the following program : Delhi cout<<endl; for(C = 0; C<4; C++) { (*ptr)*=2; --ptr; } for(C = 0; C<4; C++) cout<< Numbers [C]<< “#”; cout<<endl; }
(d) 4 # 8 # 16 # 20 # (1 Mark for each correct line of output) Note: · ½ Mark to be deducted for missing symbols in each line of output · ½ Mark to be deducted if endl is not considered in the output · As Borland C++ Compiler declares for loop variable locally,the program will result in syntax errors. So, any studentspecifying Variable C not declared OR mentioning that the program will not RUN
4 (d) Find the output of the following program : OD # include void main () { intArray[] = {4,6,10,12}; int *pointer = Array ; for (int I=1 ; I<=3 ; I++) { cout<<*pointer<<#”; pointer ++; }
4 (d) Find the output of the following program : OD cout<<endl; for (I=1 ; I<=4 ; I++) { (*pointer)*=3 ; -- pointer; } for(I=l; I<5; I + + ) cout << Array [I-1] << cout << endl; }
(d) 4 # 6 # 10 # (1 Mark for each correct line of output) Note: · ½ Mark to be deducted for missing symbols in the output · ½ Mark to be deducted if endl is not considered in the output · As Borland C++ Compiler declares for loop variable locally,the program will result in syntax errors. So, any student specifying Variable I not declared OR mentioning that the program will not RUN due to incorrect syntax should be awarded full 2 Marks
5 (d) Find the output of the following program: Delhi #include void main ( ) { char Text [ ] = for (int I = 0; Text (I)! = ‘\0’; 1++) { if (!isalpha (Text[I])) Text [I] = ‘*’; else if (isupper (Text[I])) Text [I] = Text [I] + 1 ;
5 (d) Find the output of the following program: Delhi Text [I] = Text [I] + 1 ; else Text (I) = Text [I+ 1]; } cout<<Text; }
Ans: (½ Mark for N in the 1st position) (½ Mark for nd in the 2nd and 3rd position) (½ Mark in the 4th position) (½ Mark for * in the 5th position) (½ Mark for Xrk!) (½ Mark for * at the end) 332 OR (Fu1l 3 Marks If error is mentioned in the code for Text (I) after last else)
6. (d) Find the output of the following program : OD #include void main ( ) { char Mystring[ ] ; for(int I = 0; Mystring [I] ! =’ \0'; I++) { if (!isalpha (Mystring[I])) Mystring [I] = ‘*’; else if (isupper (Mystring[I]))
6. (d) Find the output of the following program : OD Mystring [I] = Mystring[I] +1; else Mystring [I] = Mystring [I+1]; } cout<<Mystring; }
Ans: (½ Mark for X in the first position) (½ Mark for at in the 2nd & 3rd positions) (½ Mark in the 4th position) (½ Mark for * in the 5th position) (½ Mark for PVUQvu) (½ Mark for * at the end)
7 (d) Find the output of the following program : Delhi #include void main ( ) { int X[ ] = {10, 25, 30, 55, 100}; int *p = X ; while ( *p < 110) { if (*p%3 ! = 0) *p = *p + 1 ; else *p = *p + 2 ;
7 (d) Find the output of the following program : Delhi p++; } for(int I = 4 ; 1>= 1 ; I - -) { cout << X[I] << “*” ; if ( I%3 = = 0) cout<<endl ; } cout<<X[0]*3<<endl ; }
Ans 1110*56* 32*26*33 (½ Mark for each correct value) (½ Mark for all correct endl and *)
8 (d) Find the output of the following program: OD #include void main ( ) { int A[ ] = {10, 15, 20, 25, 30} int *p = A; while (*p < 30) { if (*p%3 ! = 0) *p = *p + 2 ; else *p = *p + 1;
8 (d) Find the output of the following program: OD p++; } for (int J = 0; J<=4; J++) { cout << A[J] << “*” ; if ( J%3 = = 0) cout<<end1;
Ans 12* 16*22*27* 30*90 (1 Mark for each line with correct values) Note: Deduct ½ Mark if any/all ‘*’ missing Deduct ½ Mark if endl is not considered at the right positions
9 (d) Find the output of the following program : Delhi #inc1ude struct POINT {int X, Y, Z;}; void StepIn(POINT & P, int Step=1) { P.X+=Step; P.Y -=Step; P.Z+=Step; }
9 (d) Find the output of the following program : Delhi void StepOut(POINT & P, int Step=1) { P.X-=Step; P.Y+=Step; P.Z–=Step; }
9 (d) Find the output of the following program : Delhi void main ( ) { POINT P1={15, 25, 5}, P2={10, 30, 20}; StepIn(P1); StepOut(P2,4); cout<<P1.X<<“,”<<P1.Y<<“,”<<P1.Z<<endl; cout<<P2.X<<“,”<<P2.Y<<“,”<<P2.Z<<endl; StepIn(P2,12); cout<<P2.X<<“,”<<P2.Y<<“,”<<P2.Z<<endl; }
Ans. 16, 24, 6 6, 34, 16 18, 22, 28 (1 Mark for each line with -correct values) OR (½ Mark for any two correct values in each line) Note: Deduct (½ Mark if any/all ‘,’ missing Deduct (½ Mark if endl is not considered at the right positions
10 (d) Find the output of the following program: OD #include struct THREE_D {int X,Y,Z;}; void MoveIn(THREE_D &T, int Step=l) } T.X+=Step; T.Y-=Step; T.Z+=Step }
10 (d) Find the output of the following program: OD void MoveOut(THREE_D &T, int Step=l) { T.X-=Step; T.Y+=Step; T.Z-=Step; }
10 (d) Find the output of the following program: OD void main () { THREE_D Tl={lO,20,5},T2={30,lO,40}; MoveIn(T1); MoveOut(T2,5); cout<<Tl.X<<“,”<<Tl.Y<<“,”<<T1.Z<<endl; cout<<T2.X<<“,”<<T2.Y<<“,”<<T2.Z<<endl; MoveIn(T2,l0); cout<<T2.X<<“,”<<T2.y<<“,”<<T2.Z<<endl; }
Ans. 11, 19, 6 25, 15, 35 35, 5, 45 (1 Mark for each line with correct values) OR (½ Mark for any two correct values in each line) Note: Deduct ½ Mark if any/all ',' missing Deduct ½ Mark if endl is not considered at the right positions
11 (d) Find the output of the following program: Delhi #inc1ude void ChangeArray(int Number, int ARR[ ], int Size) { for (int L =0; L<Size; L++) if (L<Number) ARR [L] +=L; e1se ARR [L] *=L; }
11 (d) Find the output of the following program: Delhi void Show (int ARR [ ], int Size) { for (int L=0; L<Size; L++) (L%2!=0) ?cout<<ARR[L] <<"#": cout<<ARR[L]<<end1 ; } void main ( ) { int Array [ ] = {30, 20, 40, 10, 60, 50}; ChangeArray (3, Array, 6) ; Show (Array, 6) ; }
Ans 30 21#42 30# # (½ Mark for each correct value) Note: Deduct ½ Mark for not writing # at proper places Deduct ½ Mark for not considering endl at proper places
12 (d) Find the output of the following program: OD #include 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; }
12 (d) Find the output of the following program: OD void Display (int A [ ], int N) { for (int K=0 ; K<N ; K++) (K%2==0)? cout<<A[K]<<"%":cout<<A(K]<<end1; } void main ( ) { int H[ ]= {30,40,50,20,10,5}; SwitchOver (H, 6, 3); Display (H, 6); }
Ans 30%41 52%60 40%25 (1 Mark for each line with correct values) Note: Deduct ½ Mark if any/all '% t missing Deduct ½ Mark if endl is not considered at the right positions
13 (d) Find the output of the following program: SP 2010 SET I 3 #include struct GAME { int Score, Bonus;}; void Play(GAME &g, int N=10) { g.Score++;g.Bonus+=N; }
13 (d) Find the output of the following program: SAMPLE PAPER 2010 SET I 3 void main() { GAME G={110,50}; Play(G,10); cout<<G.Score<<":"<<G.Bonus<<endl; Play(G); cout<<G.Score<<":"<<G.Bonus<<endl; Play(G,15); cout<<G.Score<<":"<<G.Bonus<<endl; }
Ans: (d) 3 111:60 112:70 113:85 (1 Mark for each correct line of output)
14 (d) Find the output of the following program: SAMPLE PAPER 2010 SET II 3 #include void Changethecontent(int Arr[ ], int Count) { for (int C=1;C<Count;C++) Arr[C-1]+=Arr[C]; } void main() { int A[]={3,4,5},B[]={10,20,30,40},C[]={900,1200}; Changethecontent(A,3);
14 (d) Find the output of the following program: SAMPLE PAPER 2010 SET II 3 Changethecontent(B,4); Changethecontent(C,2); for (int L=0;L<3;L++) cout<<A[L]<<'#'; cout<<endl; for (L=0;L<4;L++) cout<<B[L] <<'#'; cout<<endl; for (L=0;L<2;L++) cout<<C[L] <<'#'; }
d) 7#9#5# 30#50#70#40# 2100#1200# (1 Mark for each line of output)
15 SAMPLE PAPER 2012 SET I
16 SAMPLE PAPER 2012 SET II
17 (d)Find the output of the following program: SAMPLE PAPER 2009 SET I 3 #include struct PLAY { int Score, Bonus;}; void Calculate(PLAY &P, int N=10) { P.Score++;P.Bonus+=N; } void main() { PLAY PL={10,15}; Calculate(PL,5);
17 (d)Find the output of the following program: SAMPLE PAPER 2009 SET I 3 cout<<PL.Score<<”:”<<PL.Bonus<<endl; Calculate(PL); cout<<PL.Score<<”:”<<PL.Bonus<<endl; Calculate(PL,15); cout<<PL.Score<<”:”<<PL.Bonus<<endl; }
17 SAMPLE PAPER 2009 SET I Answer: 11:20 12:30 13:45 (1 Mark for each correct line of output) Note: Deduct ½ Mark for not showing : in the output Deduct ½ Mark for not considering endl
18 (d)Find the output of the following program: SAMPLE PAPER 2009 SET II3 #include void Changethecontent(int Arr[], int Count) { for (int C=1;C<Count;C++) Arr[C-1]+=Arr[C]; }
18 (d)Find the output of the following program: SAMPLE PAPER void main() { int A[]={3,4,5},B[]={10,20,30,40},C[]={900,1200}; Changethecontent(A,3); Changethecontent(B,4); Changethecontent(C,2); for (int L=0;L<3;L++)
18 (d)Find the output of the following program: SAMPLE PAPER 2009 SET II 3 cout<<A[L]<<’#’; cout<<endl; for (L=0;L<4;L++) cout<<B[L] <<’#’; cout<<endl; for (L=0;L<2;L++) cout<<C[L] <<’#’; }
18 SAMPLE PAPER 2009 SET II Answer: 7#9#5# 30#50#70#40# 2100#1200# (1 Mark for each correct line of output) Note: Deduct ½ Mark for not showing : in the output Deduct ½ Mark for not considering endl
THANK YOU