XII CBSE Previous Year Question Paper QUESTION NO 1 (D) 2 or 3 Marks.

Slides:



Advertisements
Similar presentations
C’ POINTERS Basic&Examples. Q:what’s the output? int array[] = { 45, 67, 89 }; int *array_ptr = array; printf(" first element: %i\n", *(array_ptr++));
Advertisements

XII CBSE Previous Year Question Paper QUESTION NO 1 (C) 2 Marks.
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Introduction to Programming Lecture 34. In Today’s Lecture Arrays of objects Arrays of objects Interaction of Arrays with Free Store Interaction of Arrays.
Destructors Math 130 Lecture # xx Mo/Da/Yr B Smith: New lecture for 05. Use this for evolving to Java B Smith: New lecture for 05. Use this for evolving.
Informática II Prof. Dr. Gustavo Patiño MJ
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
1 String Library and Stream I/O Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures Series.
#include using namespace std; void main() { int a[3]={10,11,23}; for(int i=0;i
1 Lab Session-VI CSIT-120 Spring 2001 Let us look at C++ syntax rules in brief Exercise VI-A (Demo Required) Lab Assignment#4 Due May 1st, 2001 (No Lab.
Arrays Hanly - Chapter 7 Friedman-Koffman - Chapter 9.
Starting out with C++1 Chapter 9 – Pointers Getting the address of a Variable Why do we have pointers? Indirection – difference between –Will you go out.
Smoking is prohibited 1 CS 101 Second Exam Review Prepared by Dr. Amer Al-Badarneh 
1 Dynamic Memory Allocation Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures Series.
Lecture 4 Sept 4 Goals: chapter 1 (completion) 1-d array examples Selection sorting Insertion sorting Max subsequence sum Algorithm analysis (Chapter 2)
Pointers. COMP104 Pointers / Slide 2 Pointers * A pointer is a variable used for storing the address of a memory cell. * We can use the pointer to reference.
Lecture 2 Pointers Pointers with Arrays Dynamic Memory Allocation.
Review on pointers and dynamic objects. Memory Management  Static Memory Allocation  Memory is allocated at compiling time  Dynamic Memory  Memory.
Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 1 Overview – Chapter Section 4 Arrays and Classes (10.4)
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Simple Arrays Programming COMP104 Lecture 12 / Slide 2 Arrays l An array is a collection of data elements that are of the same type (e.g., a collection.
Programming Pointers. COMP104 Lecture 32 / Slide 2 Pointers l Pointers are objects whose values are the locations of other objects l Pointers are memory.
Operator Overloading CS 308 – Data Structures What is operator overloading? Changing the definition of an operator so it can be applied on the objects.
XII CBSE Previous Year Question Paper QUESTION NO 2 (a) 2 Marks.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 10. Pointers & Dynamic Data Structures.
XII CBSE Previous Year Question Paper QUESTION NO 2 (b) 2 Marks.
1 Arrays Chapter 13 Especially read 13.1 – 13.2 Text introduces vectors, which we will not cover, in 13.3.
 Review structures  Program to demonstrate a structure containing a pointer.
XII CBSE Previous Year Question Paper QUESTION NO 2 (c) 4 Marks.
M. Taimoor Khan #include void main() { //This is my first C++ Program /* This program will display a string message on.
XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks.
This set of notes is adapted from that provided by “Computer Science – A Structured Programming Approach Using C++”, B.A. Forouzan & R.F. Gilberg, Thomson.
224 3/30/98 CSE 143 Recursion [Sections 6.1, ]
XII CBSE Previous Year Question Paper QUESTION NO 1 (E) 2 or 3 Marks.
Chapter: 01 C++ Revision Tour
XII CBSE Previous Year Question Paper QUESTION NO 3 (a) 3 Marks.
Pointers OVERVIEW.
1 CSC241: Object Oriented Programming Lecture No 22.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
CS Midterm Study Guide Fall General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.
C++ Data Types Structured array struct union class Address pointer reference Simple IntegralFloating char short int long enum float double long double.
Object Oriented Programming (OOP) Lecture No. 8. Review ► Class  Concept  Definition ► Data members ► Member Functions ► Access specifier.
CSC241 Object-Oriented Programming (OOP) Lecture No. 4.
Chapter 7 Pointers: Java does not have pointers. Used for dynamic memory allocation.
XII CBSE Previous Year Question Paper QUESTION NO 1 (b) 1 OR 2 Marks.
1 CSE 2341 Object Oriented Programming with C++ Note Set #2.
 140 Total Points ◦ 100 Points Writing Programs ◦ 24 Points Tracing Algorithms and determining results ◦ 16 Points Short Answer  Similar to quizzes.
Lecture 23: Pointers. 2 Lecture Contents: t Pointers and addresses t Pointers and function arguments t Pointers and arrays t Pointer arrays t Demo programs.
1 Data Structure & Algorithm Pointer & Class. 2 Pointer can be used to store the address of other variables with types of int, char, float, and double.
Review for Final Exam. Contents 5 questions (20 points each) + 1 bonus question (20 points) – Basic concepts in Chapters 1-4 – Chapters 5-9 – Bonus: Chapter.
Function prototype A function must be declared before it can be referenced. One way to declare a function is to insert a function prototype before the.
C++ Programming Basics
CS Class 15 Today  More practice with arrays  Introduction to Multi-dimensional arrays Announcements  Programming project #4 due 10/23 by midnight.
XII CBSE Previous Year Question Paper QUESTION NO 1 (F) 2 or 3 Marks.
Cop3530sp12. Parameter passing call by value- appropriate for small objects that should not be altered by the function call by constant reference- appropriate.
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
Welcome to CISC220 Data Structures in C++ sakai.udel.edu Office Hours: Tues 3PM - 4PM / Thurs 1PM - 2PM TA: David.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Pointers  * symbol and & symbol  Pointer operations  Pointer.
Advanced Programming Constants, Declarations, and Definitions Derived Data Types.
Current Assignments Project 3 has been posted, due next Tuesday. Write a contact manager. Homework 6 will be posted this afternoon and will be due Friday.
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout
Learning Objectives Pointers Pointer in function call
Arrays November 8, 2017.
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
CS 101 First Exam Review.
Functions Chapter No. 5.
Presentation transcript:

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