You are on page 1of 6

B-1

Half Yearly Examination


Computer Science
Class - 12
th
(2011-12)
SET-B

Time : 3 hrs. M. Marks : 70

Q.1.
(a) Differentiate between parameterized constructor and copy constructor,
giving suitable examples of each (2+1)
(b) What is this pointer.Explain with an example. (3)
(c) Name the header files that shall be needed for successful compilation of the
following C++ code (1)

void main()
{
char string[20];
gets(string);
strcat(string, GOOD MORNING);
puts(string);
}

(d) Rewrite the following program after removing the syntactical error(s), (if
any). Underline each correction. (2)

#include<iostream.h>
#include<stdio.h>
class Employee
{ int EmpID = 901 ;
char EName [20];
public
Employee( ) { }
void Joining( ) { cin >> EmpId ; gets (EName) ; }
void List ( ) {cout << EmpId << : << EName << endl ;}
}
void main( )
{
Employee E ;
Joining.E ( );
E.List ( )
}

(e) Give the output of the following: (3)

#include<iostream.h>
void f(int A, int &B, int *C)
{
A+=B++ + (*C)++;
*C=*C**C;
cout<<A<<B<<*C;
}
void main()
{
int x=15 y=5, z=4;
f(x, y, & z);
}
B-2

(f) Find the output of the following program: (3)

#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--)


{
count << X[I] << * ;
if (I%3 == 0) cout << endl ;

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


(g) Study the following program and select the possible output form the given options

#include<iostream.h> (3)
#include<stdlib.h>
const int MAX=3;
void main()
{
Randomize();
int Number;
Number=50+random(MAX);
for (int P=Number; P>=50; P--)
cout<<P<<#;
cout<<endl;
}
I) 53#52#51#50#
II) 50#51#52#
III) 50#51#
IV) 51#50#


Q. 2.(a) Compare friend function with member function. (2)
(b) Answer questions (i) and (ii) after going through the following class: (3)


class maths
{
char chapter[20];
int marks;
public:
B-3
maths() //Member Function1
{

strcpy(chapter,geometry);
marks=10;
cout<<Chapter Initialized;
}
~maths() //Member Function2
{
cout<<Chapter Over;
}
};

(i) Name the specific features of class shown by Member Function1 and
Member Function2 in the above example.
(ii) Write statements to execute functions 1& 2 respectively.

(c) Define a class RESORT in C++ with the following description : (5)


Private Members :
Rno //Data member to store Room No
Name //Data member t store customer name
Charges //Data member to store per day charges
Days //Data member to store number of days of stay
COMPUTE() //A function to calculate and return Amount as
//Days*Chagres and if the value of Days*Charges is
more than 11000 then as 1.02*Days*Charges

Public Members :
Getinfo() //A function to enter the content Rno, Name, Charges
and Days
Dispinfo() //A function to display Rno, Name, Charges, Days and
Amount (Amount to displayed by calling function
COMPUTE( ))

(d) Answer the questions (i) to (iv) based on the following code : (5)

class regular
{
char SchoolCode[10];
public:
void InRegular( );
void OutRegular( );
};
class Distance
{
Char StudyCentreCode[5];
public:
void InDistance ( );
void OutDistance ( );
};

class Course : public Regular, private Distance
{
char Code[5];
B-4

float Fees;
int Duration;
public:
void InCourse();
void OutCourse();
};

(i) Which type of Inheritance is shown in the above example?
(ii) Write names of all the member functions accessible from OutCourse
function of class Course.
(iii) Write name of all the members accessible through and object of class
Course.
(iv) Is the function InRegular() accessible inside the function InDistance()?
Justify you answer.
Q3.
a). Differentiate between linear & non linear data structures with example. (2)

b) Write a function in C++ which accepts three integer arrays A[ ],B[ ]&C[ ].
Array A[] is sorted in ascending order & array B[] is sorted in descending
order ,both the arrays should be merged to produce array C such that array C is
in descending order. (4)
c) An array P[20][15] is stored in the memory along the column with each of the
element occupying 8 bytes.Find out the Base Address and address of the
element Array[2][3]if the element Array[4][5] is stored at the address 2000.(4)

Q. 4.
(a) Observe the program segment given below carefully, and answer the questions
that follows : (2)

class member
{
int member_no;
char member_name[20];
public:
//function to enter member details
void enterdetails();
//function to display member details
void showdetails();
//function to return member_no
int Rmember_no(){return member_no;}
};
void update(member NEW)
{
fstream file;
file.open(MEMBER.DAT, ios::binary|ios::in|ios::out);
member OM;
int recordsread=0, found=0;
while(!found&&file.read((char*)&OM, sizeof(OM)))
{
recordsread++;
if(NEW.Rmember_no()==OM.Rmember_no())
{
___________________________//missing statememt
file.write((char*)&NEW, sizeof(NEW));
found=1;
B-5

}
else
file.write((char*)OM, sizeof(OM));
}
if(!found)
cout<<Record for modification does n0ot exist;
file.close();
}

if the function update()is supposed to modify a record in file MEMBER.DAT with
the values of member NEW passed to its argument, write the apporopriate
statement for missing statement using seekp() and seekg(), whichever needed, in
the above code that would write the modification record at its proper place

(b) WAP to count the number of lower case characters present in a text file. (4)
(c) Given a binary file TELEPHON.DAT, containing records of the following
class Directory : (4)
class Directory{
char Name[20] ;
char Address[30];
char AreaCode[5];
char Phone_No[15];
public:
void Register();
void Show( ) ;
int CheckCode(char AC [ ])
{
return strcmp{AreaCode,AC);

}
};
Write a function COPYABC() in C++, that would copy only those records having
AreaCode as "456" from TELEPHON.DAT to TELEBACK.DAT.

Q6. (a) State and verify Demorgans SECOND law algebraically. (2)
(b) Write the POS form of a Boolean Function F, which is represented by the ( 1)
following truth table:
A B C F
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 0


(c) Reduce the following Boolean expression using K - Map: (3+1)
F(A, B, C, D) = (O, 1, 2, 3, 4, 5, 10, 11, 15)
Impliment the simplified Expression using NAND gates only.

(d) State the principle of duality & give the dual of (X+Y) (X+Z) (Y+Z) ( 1+1)
B-6



(e) Reduce the following Boolean expression using K - Map: (3+1)
F(x,y,z) = (O, 1, 4, 6 )
Implement the simplified expression using NAND gates only.

(f) Write the equivalent POS expression for : PQR+PQR+PQR (2)
(g) Write the equivalent expression for the logic circuit: (2)

X Y Z

You might also like