CBSE Solved Papers For Class 12 Computer Science (C++) Paper 5

SECTION ‘A’

Question 1:
(a) Differentiate between a Logical Error and Syntax Error. Also , give a suitable example of each in C++. [2]
(b) Observe the following program very carefully and write names of those header files, which are essentially needed to compile and execute the following program successfully: [1]
void main ( )
{
float number;
cout«”number”;
cin>>number,
cout<<sqrt(Number)<<endl;
}
(c) Rewrite the following program after removing the syntactical error(s), if any. Underline each correction. [2]
#include<iostream.h>
const int Max 10;
void main ()
{
int Numbers [Max];
Numbers ={20,50,10,30,40};
for (Loc =Max -1; Loc = > 0; Loc –)
cout >>Number [Loc];
(d) Write the output of the following C++ program code :
Note :
Assume all required header files are already being included in the program : [3]
void Draw (int &N, char mark=’#’)
{
for (int 1=1; I<=N; I++) cout<<mark«endl ;
N++;
}
void main()
{
int count=3; char sign=’*’;
Draw(cout);
Draw(count, sign);
Draw(count, ‘&’);
}
(e) Write the output of the following C++ program code : [2]
Note :
Assume all required header files are already being included in the program,
class Item
{
int Ino;
char Iname [20];
float price; public :
Item( )
{
Ino=100;
strcpy (Iname, “None”); price = 100;
}
void Assign (int I, char Name [],float P)
{
Ino+=I;
strcpy (Iname, Name); price=P;
} ,
void Raise (float P)
{
Price +=P;
}
void Reduce (float P)
{
Price -=P;
}
void DispO
{
cout«Ino«”: “«IName«”: “«Price«endl ;
}
} ;
void main()
{
Item One, Two;
One.Disp() ;
One.Assign (1,”Pen”,95);
Two.Assign (2,”Pencil”,55);
One.Raise(10);
Two.Reduce(5) ;
Two.Disp();
One.Disp();
}
(f) Oberve the following program Score.CPP carefully, if the value of Num entered by the user is 5. Choose the correct possible output(s) from the option from (i) to (iv) and justify your option. [2]
// Program : Score. CPP #include<stdlib.h>
#include<iostream.h>
void main()
{
randomize ();
int Num, Rndnum;
cin>>Num;
Rndnum =random (NUM)+5;
for (int N=l; N<=Rndnum;N++)
cout «N« “”;
}
Output option:
(i) 1 2 3 4
(ii) 1 2
(iii) 123456789
(iv) 1 2 3
Solution:
(a) The differences between logical errors and syntax errors are as follows:
(b)

  1. iostream.h
  2. math.h

(c) #include<iostream.h>
const int Max=10;
void main ()
{
int Numbers [Max];
Numbers []={20,50,10,30,40};
for (int Loc=Max-1; Loc>=0; Loc – -)
cout « Numbers [Loc];} [2]
(d) Output:
#
#
#
*
*
*
*
&
&
&
(e)
One
Two
One Ass
Two Ass
One Reduce
Two Reduce

100 None 100
100 None 100
101 Pen 95
102 Pencil 55
101 Pen 105
102 Pencil 50

Output:
100 : None : 100
102 : Pencil: 50
101: Pen : 105
(f) (iii) 123456789,
The minimum value Rndnum will take is 5.

Question 2:
(a) Differentiate between public and private visibility modes in context of object oriented programming using a suitable example illustrating each. [2]
(b) Explain copy constructor with an example. [2]
(c) Define a class named ADMISSION in C++ with the following descriptions: [4]
Private Members:
AD_No integer (Ranges 10-2000)
NAME Array of characters (String) (store 20 characters)
CLASS Character (store 10 characters)
FEES Float Public Members:

  • Function Read_Data () to read an object of ADMISSION type Function Display () to display the details of an object.
  • Function Draw_Nos () to choose 2 students randomly, and display the details. Use Random function to generate admission numbers to match with AD_No.

(d) Answer the questions (i) to (iv) based on the following code:
class Shape
{
int length;
protected: int width, height;
public: void getDimension (int, int, int);
void dispDimension();
} ;
class sideShape: protected Shape
{
int sideLength, sideWidth;
protected: void getSide (int, int);
public: void dispSide ();
} ;
class SubShape : public sideShape
{
int SubLength;
void display (void) ;
public: void enter ();
} ;

  1. Name the base class and derived class of the class SideShape. [1]
  2. Name the data member(s) that can be accessed from function dispSide(). [1]
  3. Name the private member function(s) of class SubShape. [1]
  4. Is the member function dispSide () accessible by the object of SubShape? [1]

Solution:
(a) Public and Private visibility modes in Object Oriented Programming:
(i) A key feature of object oriented programming is data hiding, i.e., the data is concealed within a class. So that it carmot be accessed mistakenly by functions outside the class.
Private visibility modes in Object Oriented Programming:
(i) The primary mechanism for hiding data is to put it in a class and make it private.
Private data or functions can only be accessed from within the class.
Public Visibility Modes in Object Oriented Programming:
(i) Public data or functions, are accessible from outside the class, by using object of the respective class.
cbse-solved-papers-for-class-12-computer-science-c-paper-5-3
Example:
class small_obj
{
private: int somedata; public:
void setdata (intd);
{ somedata = d;
}
void showdata ()
{
cout« “Data is” «somedata;
}
} ;
Data: Data member some data cannot be acessed outside the class because it is declared as private but functions setdata () and showdata () can be accessed outside the class because they are declared as public.
(b) A copy constructor is used to copy the values of one object into another.
Syntax : classname (classname &obj)
Example: class Student {
int a; public:
Student ()
{
a=10;
}
Student (student &x)//copy constructor
{
a=x.a;
}
} ;
void main()
{
Student S;
Student Sl=S;//call to copy contructor }
(c) class ADMISSION {
int AD_No;
char NAME [20];
char CLASS [10];
float FEES; public:
void Read_Data ();
void Display ();
void Draw_Nos () ;
} ;
void ADMISSION :: Read_Data ()
{ cout<<“\n Enter admission No”;
cin»AD_No;
cout«”\n Enter Name”;
gets(NAME);
cout«”\n Enter class”;
gets(CLASS);
cout«”\n Enter Fees”;
cin»FEES;
}
void ADMISSION : Display ()
{
cout «”\n Admission No :” « AD_No;
cout <<“\n Name :”;
puts(NAME);
cout <<“\n Class ;
puts(CLASS);
cout «”\n Fees :” « FEES;
}
void ADMISSION :: Draw_Nos ()
{ int adno;
adno=random (AD_No); if (AD No= = adno)
Display ();
}
(d)

  1. Base class is Shape and derived class is Subshape. [1]
  2. width, height, sidelength, sidewidth. [1]
  3. display (), [1]
  4. Yes, because it is publically derived from sideshape. [1]

SECTION ‘B’

Question 3:
(a) An Array A [10] [20] is stored in the memory with each element requiring 2 bytes of storage. If the base address of array in the memory is 800, determine the location of A[9] [11] when the array is stored as .

  1. Row major
  2. Column major [3]

(b) Write a C++ function to sort an array of integer using insertion sort. The function should have two parameters; name of the array and number of elements in the array. [3]
(c) Give the necessary declarations for a queue containing float type numbers. Write a user- defined function in C++ to insert a float type number in the queue and you should use linked representation of queue. [4]
(d) Write a function in C++ to print the product of each column of a two-dimesional integer array passed as the argument of the function. [2]
(e) Evaluate the following postfix notation of expression: 15 3 2 + / 7 + 2 * [2]
Solution:
(a) Array: A [10] [20]
Base Address, B=800.
Size of element, W : 2 bytes A [I] [J]=A [9] [11] & 1=9, J=ll Total Rows, R=10 Total Column, C=20 Lowest Row in C++, lr=0 Lowest Column in C + +, Ic=0
Row Major: [1]
A [I] [] = B+W [c(I-Ic) + (J-Ic)]
= 800+2[20(9-0) + (11-0)]
= 800+2[20×9+ll]
= 800+2(180+11)
= 800+2(191)
= 800+382 = 1182
Column Major: [1]
= B+W [(I—Ir)+R (J-lc)]
= 800+2[(9-0)+10 (11-0)]
= 800+2(9+10×11)
= 800+2(9+110)
= 800+2×119 = 800+238
= 1038 [3]
(b) void insertsort (int a[],int n)
{
int p, ptr;
//Assuming a[0]=int_min i.e. smallest integer for (p=j; p < n; P++)
{
temp=a[p] ptr=p-l;
while (temp < a[Ptr])
{
a[ptr+l] = a[ptr];//move element forward .
}
a[ptr+1]=temp://inserting element at proper place
}
int x;
for (x = 0; x <n; x++)
{
cout « a [x] ;
}
cout «”\n”;
}
(c) struct node
{
float data; node * link;
};
node* Insert Q (node*rear, float val)
{
node*temp=new node;
temp—>data=val;
temp—»1ink=NULL;
if (rear==NULL)
rear=temp;
else
{
rear—>link=temp;
rear=temp;
}
return (rear);
}
(d) void product (int arr [] [], int m, int n)
{
int product;
for (int i = 0; i<n; i++)
{
product = 1;
for (j = 0; j<m; j++)
{
product = product * arr [j][i];
}
cout«”product of column” «i + l «”=” « product;
}
}
(e) Postfix expression:

Step Input Operation Stack Status
1 15 PUSH 15 15
2 3 PUSH 3 15 3
3 2 PUSH 2 15 3 2
4 + POP 2
POP 3
Calculate
3+2=5
PUSH 5 15 5
5 / POP 5
POP 15
Calculate
15/5=3
PUSH 3 3
6 7 PUSH 7 37
7 + POP 7
POP 3

 

Step Input Operation Stack Status
Calculate
3+7=10
PUSH 10 10
8 2 PUSH 2 10 2
9 * POP 2
POP 10
Calculate
10 x 2=20
PUSH 20 20

1532 + /7 + 2*
Ans:
20.

Question 4:
(a) Find the output of the following C++ code considering that the binary file GAME.DAT exists on the hard disk with information of around 200 games. [1]
class GAME
{
int Gno;
char GName [20];
public : void GetlnO;
void showName () ;
} ;
void main ()
{
fstream GF;
GF.open(“GAME.DAT”, ios::binary:ios::in);
GAME G;
GF.seekg(sizeof(G)*5) ;
GF.read((char*)&G,sizeof (G);
GF.read((char*)&G,sizeof(G));
int RECORDNO=GF.tellg()/sizeof(G); cout«”RECORDNO: “«RECORDNO«endl ;
GF.close() ;
}
(b) Write a function in C++ to count the number of lines starting with a digit in a text file “Diary.txt” [2]
(c) Given is a binary file PHONE.DAT, containing records of the following structure type: [3]
class Phonelist
{
char Name [20];
char Address [30];
char AreaCode [5] ;
char PhoneNo. [15];
public:
void Register ();
void Show ();
int CheckCode (char AC [])
{
return strcmp (AreaCode, AC) ;
}
};
Write a function TRANSFER () in C++, that would copy all those records which are having Area Code as “DEL” from PHONE. DAT to PHONE BACK. DAT
Solution:
(a) RECORDNO : 7
(b) int countNum() .
{
ifstream fin (“Diary. txt”) ;
char ch[80];
int count=0;
while (!fin. eof () )
{
fin. get line (ch, 80) ;
if(isdigit(ch[0]))
count++;
}
fin. close () ; return count;
}
(c) void Transfer()
{
Phonelist P; ifstream fin; ofstream fout;
fin.open(“PHONE.DAT”,IOS::binary);//IOS & ios both are same
fout.open(“PHCNEBACK.DAT”, ios::binary);
while (fin. read ( (char*) &P, sizeof (P) )
{
if(P.Checkcode(“DEL”)==0)
fout.write((char*)&P, sizeof(P));
}
fin . close () ;
font.close (c);
}

SECTION ‘C’

Question 5:
(a) Observe the following table carefully and find the degree and cordinality of the table : [2]

Fno Flight Detail Price
101 DEL-KOL 2300

 

104 KOL-DEL 2400
205 DEL-MUM 3500
109 MUM-AMD 2200
103 CHE-KOL 4100

(b) Give the following table for a database LIBRARY:
Table: Books

Book_Id Book_Name Author_Name Publishers Price ’ Type Quantity
C0001 Fast Cook Lata Kapoor EPB 355 Cookery 5
F 0001 The Tears William Hopkins Arst Publ. 650 Fiction 20
T 0001 My First C++ Brian & Brooke EPB 350 Text 10
T 0002 C++ Brain works A.W. Rossaine TDH 350 Text 15
F0002 Thunder bolts Anna Roberts First Publ. 750 Fiction 50

Table: Issued

BOOK_Id Quantity-Issued
T 0001 4
C0001 5
F0001 2

Write SQL queries for (a) to (d):

  1. To show Book name, Author name and Price of Books of First Publ. [1]
  2. To list the names from books of Text type. [1]

(c) To display the names and price from books in ascending order of their price. [1]
(d) To increase the price of all books of EPB publishers by 50. [1]
(e) Give the output of the following queries based on the above data:

  1. SELECT COUNT (*) FROM BOOKS; VA]
  2. SELECT MAX (Price) FROM BOOKS WHERE Quantity >=15;
  3. SELECT Book Name, Author_Name FROM BOOKS WHERE Publishers = “EPB”;
  4. SELECT COUNT (DISTINCT Publishers) FROM BOOKS WHERE Price>400;

Solution:
(a) Degree = no. of columns = 3
Cardinality = no. of rows = 5
(b)

  1. SELECT Book Name, Author_name, Price FROM BOOKS
    WHERE Publishers = “First Publ.”;
  2. SELECT * FROM BOOKS
    WHERE Type = “Text”;

(c) SELECT Book Name, Price
FROM Books
ORDER BY price ASC;
(d) UPDATE BOOKS SET Price – Price+50.
WHERE Publishers = “EPB”;
(e)

  1. 5.
  2. 750
  3. Fast cook Lata Kapoor
    My first C++ Brain & Brooke
  4. 2

Question 6:
(a) State and verify Associative law. [2]
(b) Write the equivalent expression for the following logical circuit: [2]
cbse-solved-papers-for-class-12-computer-science-c-paper-5-1
(c) Write the SOP form of a Boolean function F, which is represented by the following truth table:

A
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1

(d) Reduce the following Boolean Expression using K-map:
F (P,Q,R,S) = Σ(0,3,5,6,7,11,12,15) [3]
Solution:
(a) Associative : This law states that:
(A+B)+C= A+(B+C) Or (A.B).C=A.(B.C)
Proof:

A B B A+B (A+B)+C B+C A+(B+C)
0 0 0 0 0 0 0
0 0 1 0 1 1 1
0 1 0 1 1 1 1
0 1 1 1 1 1 1
1 0 0 1 1 0 1
1 0 1 1 1 1 1
1 1 0 1 1 1 1
1 1 1 1 1 1 1

From the above table, (A+B) +C = A+ (B+C) Similarly, we can prove A.(B.C) = (A.B).C

A B C B.C A.(B.C) A.B (A.B).C
0 0 l) 0 0 0 0
0 0 1 0 0 0 0
0 1 0 0 0 0 0
0 1 1 1 0 0 0
1 0 0 0 0 0 0
1 0 1 0 0 0 0
1 1 0 0 0 1 0
1 1 1 1 1 1 1

(b) Exp is= A.C + B.A + B.C
(c) (A’B’C) + (A’BC) + (ABC’) + (ABC)
(d) F(P, Q, R, S) = Σ(0, 3, 5, 6, 7,11,12,15)
cbse-solved-papers-for-class-12-computer-science-c-paper-5-4
Minimized Expression:
= RS+P.Q.S.+ P.Q.R. + P.Q.R.S.+ P.Q.R. S.

Question 7:
(a) What is spam mail? [1]
(b) What is the significance of Cyber Law? [1]
(c) Differentiate FTP and HTTP. [1]
(d) What is the URL in networking? [1]
(e) “Hindustan Connecting World Association” is planning to start their offices in four major cities in India to provide regional IT Infrastructure support in the field of Educations Culture. The company has planned to set up their head office in New Delhi in three locations and have named their New Delhi offices as “Sales office”, “Head office” and “Teach office”. The company’s regional offices are located at: “Coimbatore”, “Kolkata” and “Ahmedabad”.
A rough layout of the same is as follows:
cbse-solved-papers-for-class-12-computer-science-c-paper-5-2
Approximate distances between these offices as per network survey team is as following:

Place From Place To Distance
Head office Sales office 10 km
Head office Teach office 70 m
Head office Kolkata office 1291km
Head office Ahmedabad office 790 km
Head office Coimbatore office 1952 km

In continuation of the above, the company experts have planned to install the following number of computers in each of their offices:

Head office 100
Sales office 20
Teach office 50
Kolkata office 50
Ahmedabad office 50
Coimbatore office 50
  1. Suggest network type (out of LAN, MAN, WAN) for connecting each of the following set of their offices: [1]
    • Head office and Teach office
    • Head office and Coimbatore office
  2. Which device will you suggest to be procured by the company for connecting all the
    computers within each of their offices out of the following device? [1]
    • Modem
    • Telephone
    • Switch/ Hub
  3. Which of the following Communication Media, will you suggest to be procured by the
    company for connecting their local offices in New Delhi for very effective and fast communication? [1]
    • Ethernet Cable
    • Optical Fibre
    • Telephone Cable
  4. Suggest a cable/wiring layout for connecting the company’s local offices located in New Delhi. Also, suggest an effective method/technology for connecting the company’s regional offices at “Kolkata”, “Combatore” and “Ahmedabad”.

(f) What is RJ-45 connector?
(g) What is video conferencing?
Solution:
(a) Spam mail is an unwanted mail. It is mostly commercial advertising. Sometimes it contains virus. [1]
(b) Significance of Cyber Law: [1]
In Internet, the communication technology uses the means of transferring textual messages, pic¬tures and many more.
Each time, there may be threats on either from the senders or receivers side which creates a bridge between networking communication.
(c) To shortcut these problems, the Internet Security Council made number of precautions i.e rules. These predefined rules are called Cyber Law or Law of Internet.

FTP HTTP
(i) File Transfer Protocol. Hypertext Transfer Protocol.
(ii) It is used to transfer files from       one

system         to

another on the internet.

It is used for transferring hypertext files on the world wide web.

(d) Importance of URL in Networking :

  1. URL stands for UNIFORM RESOURCE LOCATOR.
  2. Each page that is created for web browsing is assigned a URL that effectively serves as the pages worldwide name or address.
  3. URL has three parts: the protocol, the DNS name of the machine on which the page is located and a local name uniquely indicating the specific page (generally the filename), for e.g. http://www.cluestch. con [1]

(e)

  1. LAN is used for connecting Head office and Teach office. WAN is used for connecting Head office and Coimbatore office.
  2. Switch/ Hub to be procured by the company for connecting all the computers within each of their offices. [1]
  3. Optical cable to be procured by the company for connecting their local offices in New Delhi for very effective and fast communication. [1]
  4. A cable/wiring layout for connecting the company’s local offices located in New Delhi is Optical Fibre Cable.
    An effctive method/technology for connecting the company’s regional offices at “Kolkata”, “Coimbatore” and “Ahmedabad” is as follows: [1]

cbse-solved-papers-for-class-12-computer-science-c-paper-5-5
(f) RJ-45 connector: RJ-45 is abbreviation for Registered Jack-45. It is an eight wire connector used to connect computers on LAN’s, especially Ethernets. [1]
(g) Video Conferencing: When two or more participants are able to converse in real time through video-phones, it is called Video Conferencing.