CBSE 12th Paper Paper Solved — session 2015-16

Python Methods and Functions

Instructions:
i. All questions are required.
II. Programming language: Section A: C++
III. Programming Language: Section B: Python
Intravenously Answer either Section A or B and Section C is required

Section: A (C++ )

Q1 a. Define a

# define sum (a, b) a + b

Defines a macro mind by taking two arguments a and b. This macro can be called like any function. So after preprocessing:

z = sum (x, y);
is replaced with Z = x + y;

b. What

void main ()

{

int Last = 26.5698742658;

cout & lt; & lt; setw (5) & lt; & lt; setprecision (9) & lt; & lt; Last;

}

Answer: Two header files need to be included:
iostream: iostream stands for standard input / output stream. This header file contains definitions for objects such as cin, cout, etc.
iomanip: iomanip stands for I / O manipulators. The methods declared in these files are used for flow control. This file contains definitions for setw, setprecision, etc.

c. Rewrite the following program after removing any syntax errors. Underline each correction. 2

# include & lt; iostream.h & gt;

void main () int A [10];

A = [3, 2, 5, 4, 7, 9, 10];

for (p = 0; p & lt; = 6; p ++) {

if (A [p]% 2 = 0)

int S = S + A [p];

}
cout & lt; & lt; S;
}

Answer: In the above code, there are no curly braces after main (), array elements are not declared correctly, p is not declared, and S cannot be declared inside a block. So, the following fixes have been made:

 #include & lt; iostream.h & gt;   void main () {    int A [10] = {3, 2, 5, 4, 7, 9, 10};     int S = 0, p  ; for (p = 0; p  if (A [p]% 2 == 0)  S = S + A [p];} cout 

d. Find the output of the following C++ program: 2



# include & lt; iostream.h & gt; void repch ( char s []) { for ( int i = 0; s [i]! = '' ; i ++) { if (((i% 2)! = 0) & amp; & amp; (s [i]! = s [i + 1])) {   s [i] = '@' ; } else if (s [i] == s [i + 1]) { s [i + 1] = '!' ; i ++; } } } void main () { char str [] = "SUCCESS" ; cout & lt; & lt; "Original String" & lt; & lt; str repch (str); cout & lt; & lt; "Changed String" & lt; & lt; str; }


Ans: Output: Replace '@' in place of U, '!' in place of second C and '!' in place of third S

 Original String SUCCESS Changed String S @ C! ES! 

f. Find the output of the following: 3

# include & lt; iostream.h & gt;

 

void switchover ( int A [], int N, int split)

{

 

  for ( int K = 0; K & lt; N; K ++)

if (K & lt; split)

A [K] + = K;

else

  A [K] * = K;

}

 

void display ( int A [], int N)

{

  for ( int K = 0; K & lt; N; K ++)

(K% 2 == 0)? cout & lt; & lt; A [K] & lt; & lt; "%" : cout & lt; & lt; A [K] & lt; & lt; endl;

}

void main ()

{

  int H [] = {30, 40, 50, 20, 10, 5};

switchover (H, 6, 3);

display (H, 6);

}

Answer: In the above program, when the switchover () function is called by passing the array address, array size, and split = 3. In this function, for K = 0, 1, 2, if the condition is met and K is added to the array elements, i.e. 30 + 0 = 30, 40 + 1 = 41, 50 + 2 = 52, and after that the condition is also met and the array elements are multiplied, 20 * 3 = 60, 10 * 4 = 40, 5 * 5 = 25.
Display () prints the value of the changed array and outputs:

 30% 41 52% 60 40% 25 

f. Take a look at the following C++ code and find out which of the specified options i) through iv) is the expected correct output. Also assign the maximum and minimum values ​​that can be assigned to the "Go" variable. 2

void main ()

{

int X [4] = {100, 75, 10, 125};

int Go = random ( 2) + 2;

for ( int i = Go; i & lt; 4; i ++)

  cout & lt; & lt; X [i] & lt; & lt; "$$" ;

}

me. 100 $$ 75 ii. 75 $$ 10 $$ 125 $$ iii. 75 $$ 10 $$ iv.10 $$ 125 $$

Answer : Choice (iv) might be the only correct answer if Go = 2. In this case, 10 $$ 125 $$ will be printed.
Minimum value Go = 2 (with random (2) = 0)
Maximum value Go = 3 (with random (2) = 1)

Q2 a. Distinguish between

class Exam {

  int Rollno;

char Cname [25] ;

float Marks;

 

public :

  Exam () // Function 1

{

Rollno = 0;

Cname = "" ;

Marks = 0.0;

}

Exam ( int Rno, char candname) // Function 2

{

Rollno = Rno;

strcpy (Cname, candname );

}

~ Exam () // Function 3

{

cout & lt; & lt; "Result will be intimated shortly" & lt; & lt; endl;

}

void Display () // Function 4

{

  cout & lt; & lt; "Roll no:" & lt; & lt; Rollno;

cout & lt; & lt; " Name: " & lt; & lt; Cname;

cout & lt; & lt; " Marks: " & lt; & lt; Marks;

}

};

(i ) What OOP concept do Functions 1 and 2. Explain?
Answer: Functions 1 and Function 2 are
Constructors that implement the concept of the default constructor and function 2 is the parameterized constructor.

(ii) What is the name of function 3? When will this be called?
Answer: Function 3 is the destructors-c/> destructor, which is called when the object goes out of scope.

c. Define a Aggregate Marks Grade & gt; = 80 A Less than 80 and & gt; = 65 B Less than 65 and & gt; = 50 C Less than 50 D

Public Members:

Reply :

class Candidate {

long Rno;

char Cname [20] ;

float Agg_marks;

char Grade;

void setGrade ()

{

if (Agg_marks & gt; = 80)

Grade = 'A';

else if (Agg_marks & lt; 80 & amp; & amp; Agg_marks & gt; = 65)

Grade = 'B';

else if (Agg_marks & lt; 65 & amp; & amp; Agg_marks & gt; = 50)

Grade = 'C';

else

  Grade = 'D';

}

 

public :

Candidate ()

{

Rno = 0;

Strcpy (Cname, "NA " );

Agg_marks = 0.0;

}

void Getdata ()

  {

  cout & lt; & lt; "Registration No" ;

cin & gt; & gt; Rno;

cout & lt; & lt; "Name" ;

cin & gt; & gt; Cname;

cout & lt; & lt; Aggregate Marks "; 

  cin & gt; & gt; Agg_marks;

setGrade ();

}

void dispResult ()

{

cout & lt; & lt; "Registration No" & lt; & lt; Rno;

cout & lt; & lt; "Name" & lt; & lt; Cname;

cout & lt; & lt; Aggregate Marks "& lt; & lt; Agg_marks; 

}

d. Give the following class definition, answer the following question: 4

class University {

 

char name [20];

 

protected :

  char vc [20];

 

public :

  void estd ();

void inputdata ();

void outputdata ();

 

class College: protected University { 

 

int regno;

protected

  char principal ()

  

public :

int no_of_students;

void readdata ();

void dispdata ();

};

 

class Department: public College {

  

  char name [twenty];

public :

  void fetchdata ( int );

void displaydata (); };

i) Name the base class and the derived class of the college . 1
Ans:
Base class: University
Derived class: Department

ii) Name the data items which can be accessed from the displaydata () function.
Answer: char name [20], char HOD [20], char Principal (), int no_of_students, char vc [20]

iii) What type of inheritance is depicted in the above class definition?
Answer:

struct NODE {

  int Ticketno;

char PName [20] ;

NODE * NEXT;

};

class Queueofbus {

NODE * Rear, * Front;

 

public :

  Queueofbus ()

{

Rear = NULL;

Front = NULL;

};

void Insert ();

void Delete ();

~ Queueofbus ()

{

cout & lt; & lt; "Object destroyed" ;

}

};

Ans:

void Queueofbus :: Insert ()

{

code class = "string"> "Object destroyed" ;

}

};

Ans:

void Queueofbus :: Insert ()

{

code class = "string"> "Object destroyed" ;

}

};

Ans:

void Queueofbus :: Insert ()

{





Get Solution for free from DataCamp guru