Monday, 30 May 2016

COMPUTER SCIENCE[CBSE 2015]
Time allowed : 3 hours ] [ Maximum marks : 70
General Instructions :
(i) All questions are compulsory.
(ii) Programming Language : Section A refers to C++
(iii) Programming Language : Section B refers to Python.
(iv) Attempt either Section A or Section B.
(v) Section C is compulsory for all.
(vi) It is compulsory to mention ‘Section A’ or ‘Section B’ before attempting the
question paper.
Section – A
(Only for C++ Candidates)
1. (a) Find the correct identifiers out of the following, which can be used for naming
variable, constants or functions in a C++ program : 2
While, for, Float, new, 2ndName, A%B, Amount2, _Counter

(b) Observe the following program very carefully and write the names of those header
file(s), which are essentially needed to compile and execute the following program
successfully : 1
typedef char TEXT[80];
void main()
{
TEXT Str[] = “Peace is supreme”;
int Index=0;
while (Str[Index]!=’\0’)
if (isupper(Str[Index]))
Str[Index++]=’#’;
else
Str[Index++]=’*’;
puts(Str);
}
(c) Observe the following C++ code very carefully and rewrite it after removing
any/all syntactical errors with each correction underlined. 2
Note : Assume all required header files are already being included in the program.
#Define float Max=70.0;
Void main()
{
int Speed
char Stop=’N’;
cin>>Speed;
if Speed>Max
Stop=’Y’;
cout<<Stop<<end;
}
(d) Write the output of the following C++ program code : 2
Note : Assume all required header files are already being included in the program.
void Position(int &C1,int C2=3)
{
C1+=2;
C2+=Y;
}
void main()
{
int P1=20, P2=4;
Position(P1);
cout<<P1<<”,”<<P2<<end1;
Position(P2,P1);
cout<<P1<<”,”<<P2<<end1;
}

(e) Write the output of the following C++ program code : 3
Note : Assume all required header files are already being included in the program.
class Calc
{
char Grade;
int Bonus;
public:
Calc() {Grade=’E’;Bonus=0;}
void Down(int G)
{
Grade–=G;
}
Void Up(int G)
{
Grade+=G;
Bonus++;
}
void Show()
{
cout<<Grade<<”#”<<Bonus<<end1;
}
};
void main()
{
Calc c;
C.Down(2);
C.Show();
C.Up(7);
C.Show();
C.Down(2);
C.Show();
}
(f) Study the following program and select the possible output(s) from the options (i)
to (iv) following it. Also, write the maximum and the minimum values that can be
assigned to the variable NUM. 2
Note :
– Assume all required header files are already being included in the program.
– random(n) function generates an integer between 0 and n – 1.
void main()
{
randomize();
int NUM;
NUM=random(3)+2;
char TEXT[]=”ABCDEFGHIJK”;
for (int I=1;I<=NUM; I++)
{
for(int J=NUM; J<=7;J++)
cout<<TEXT[J];
cout<<end1;
}
}
(i) FGHI (ii) BCDEFGH (iii) EFGH (iv) CDEFGH
FGHI BCDEFGH EFGH CDEFGH
FGHI EFGH
FGHI EFGH
2. (a) What is a copy constructor ? Give a suitable example in C++ to illustrate with its
definition within a class and a declaration of an object with the help of it. 2
(b) Observe the following C++ code and answer the questions (i) and (ii) :
class Traveller
{
long PNR;
char TName[20];
public :
Traveller() //Function 1
{cout<<”Ready”<<end1;}
void Book(long P,char N[]) //Function 2
{PNR = P; strcpy(TName, N);}
void Print() //Function 3
{cout<<PNR << TName <<end1;}
~Traveller() //Function 4
{cout<<”Booking cancelled!”<<end1;}
};
(i) Fill in the blank statements in Line 1 and Line 2 to execute Function 2 and
Function 3 respectively in the following code : 1
void main()
{
Traveller T;
_________ //Line 1
_________ //Line 2
}//Stops here
(ii) Which function will be executed at }//Stops here ? What is this function
referred as ? 1
(c) Write the definition of a class PIC in C++ with following description : 4
Private Members
Pno //Data member for Picture Number (an integer)
 Category //Data member for Picture Category (a string)
 Location //Data member for Exhibition Location
(a string)
 FixLocation //A member function to assign


Category Location //Exhibition Location as per category
Classic Amina //as shown in the following table
Modern Jim Plaq
Antique Ustad Khan
Public Members
– Enter() //A function to allow user to enter values
//Pno, category and call FixLocation() function
– SeeAll() //A function to display all the data members
(d) Answer the questions (i) to (iv) based on the following : 4
class Exterior
{
int OrderId;
char Address[20];
protected:
float Advance;
91/1 6
public:
Exterior();
void Book(); void View();
};
class Paint:public Exterior
{
int WallArea,ColorCode;
protected:
char Type;
public:
Paint();
void PBook();
void PView();
};
class Bill : public Paint
{
float Charges;
void Calculate();
public :
Bill();
void Billing();
void Print();
};
(i) Which type of Inheritance out of the following is illustrated in the above
example ?
– Single Level Inheritance
– Multi Level Inheritance
– Multiple Inheritance
(ii) Write the names of all the data members, which are directly accessible from
the member functions of class Paint.
(iii) Write the names of all the member functions, which are directly accessible
from an object of class Bill.
(iv) What will be the order of execution of the constructors, when an object of
class Bill is declared ?
91/1 7 [P.T.O.
3. (a) Write the definition of a function Alter(int A[], int N) in C++, which should
change all the multiples of 5 in the array to 5 and rest of the elements as 0. For
example, if an array of 10 integers is as follows : 2
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9]
55 43 20 16 39 90 83 40 48 25
After executing the function, the array content should be changed as follows :
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9]
5 0 5 0 0 5 0 5 0 5
(b) A two dimensional array P[20] [50] is stored in the memory along the row with
each of its element occupying 4 bytes, find the address of the element P[10] [30],
if the element P[5] [5] is stored at the memory location 15000. 3
(c) Write the definition of a member function Pop( ) in C++, to delete a book from a
dynamic stack of TEXTBOOKS considering the following code is already
included in the program. 4
struct TEXTBOOKS
{
char ISBN[20]; char TITLE[80];
TEXTBOOKS *Link;
};
class STACK
{
TEXTBOOKS *Top;
public:
STACK(){Top=NULL;}
void Push();
void Pop();
~STACK();
};
(d) Write a function REVCOL (int P[] [5], int N, int M) in C++ to display the content
of a two dimensional array, with each column content in reverse order. 3
Note : Array may contain any number of rows.
For example, if the content of array is as follows :
15 12 56 45 51
13 91 92 87 63
11 23 61 46 81
The function should display output as :
11 23 61 46 81
13 91 92 87 63
15 12 56 45 51
91/1 8
(e) Convert the following infix expression to its equivalent Postfix expression,
showing the stack contents for each step of conversion. 2
X / Y + U* (V–W)
4. (a) Write function definition for SUCCESS( ) in C++ to read the content of a text file
STORY.TXT, count the presence of word STORY and display the number of
occurrence of this word. 2
Note :
– The word STORY should be an independent word
– Ignore type cases (i.e. lower/upper case)
Example :
If the content of the file STORY.TXT is as follows :
Success shows others that we can do it. It is possible to
achieve success with hard work. Lot of money does not mean
SUCCESS.
The function SUCCESS( ) should display the following :
3
(b) Write a definition for function Economic ( ) in C++ to read each record of a binary
file ITEMS.DAT, find and display those items, which costs less than 2500.
Assume that the file ITEMS.DAT is created with the help of objects of class
ITEMS, which is defined below : 3
class ITEMS
{
int ID;char GIFT[20]; float Cost;
public :
void Get()
{
cin>>CODE;gets(GIFT);cin>>Cost;
}
void See()
{
cout<<ID<<”:”<<GIFT<<”:”<<Cost<<end1;
}
float GetCost(){return Cost;}.
};
(c) Find the output of the following C++ code considering that the binary file
CLIENTS.DAT exists on the hard disk with records of 100 members. 1
class CLIENTS
{
int Cno;char Name[20];
public :
void In(); void Out();
};
void main()
{
fstream CF;
CF.open(“CLIENTS.DAT”,ios::binary|ios::in);
CLIENTS C;
CF.read((char*) &C, sizeof(C));
CF.read((char*) &C, sizeof(C));
CF.read((char*) &C, sizeof(C));
int POS=CF.tellg()/sizeof(C);
cout<<”PRESENT RECORD:”<<POS<<end1;
CF.close();
}
5. (a) Observe the following table carefully and write the names of the most appropriate
columns, which can be considered as (i) candidate keys and (ii) primary key. 2

(b) Consider the following DEPT and WORKER tables. Write SQL queries for (i) to
(iv) and find outputs for SQL queries (v) to (viii) : 6


Note : DOJ refers to date of joining and DOB refers to date of Birth of workers.
(i) To display Wno, Name, Gender from the table WORKER in descending
order of Wno.
(ii) To display the Name of all the FEMALE workers from the table WORKER.
(iii) To display the Wno and Name of those workers from the table WORKER
who are born between ‘1987-01-01’ and ‘1991-12-01’.
(iv) To count and display MALE workers who have joined after ‘1986-01-01’.
(v) SELECT COUNT(*), DCODE FROM WORKER
GROUP BY DCODE HAVING COUNT(*)>1;
(vi) SELECT DISTINCT DEPARTMENT FROM DEPT;
(vii) SELECT NAME, DEPARTMENT, CITY FROM WORKER W,DEPT D WHERE
W.DCODE=D.DCODE AND WNO<1003;
(viii) SELECT MAX(DOJ), MIN(DOB) FROM WORKER;
6. (a) Verify the following using Boolean Laws. 2
X + Y' = X.Y+X.Y'+X'.Y'
(b) Draw the Logic Circuit for the following Boolean Expression : 2
(U + V').W' + Z
(c) Derive a Canonical SOP expression for a Boolean function F, represented by the
following truth table : 1

(d) Reduce the following Boolean Expression to its simplest form using K-Map : 3
F(X,Y,Z,W) = S(0,1,6,8,9,10,11,12,15)
7. (a) Illustrate the layout for connecting 5 computers in a Bus and a Star topology of
Networks. 1
(b) What is a spam mail ? 1
(c) Differentiate between ftp and http. 1
(d) Out of the following, which is the fastest (i) wired and (ii) wireless medium of
communication ?
Infrared, Coaxial Cable, Ethernet Cable, Microwave, Optical Fiber 1
(e) What is Worm ? How is it removed ? 1
(f) Out of the following, which all comes under cyber crime ? 1
(i) Stealing away a brand new computer from a showroom.
(ii) Getting in someone’s social networking account without his consent and
posting pictures on his behalf to harass him.
(iii) Secretly copying files from server of a call center and selling it to the other
organization.
(iv) Viewing sites on a internet browser.
(g) Perfect Edu Services Ltd. is an educational organization. It is planning to setup its
India campus at Chennai with its head office at Delhi. The Chennai campus has 4
main buildings – ADMIN, ENGINEERING, BUSINESS and MEDIA.
You as a network expert have to suggest the best network related solutions for
their problems raised in (i) to (iv), keeping in mind the distances between the
buildings and other given parameters.


(i) Suggest the most appropriate location of the server inside the CHENNAI
campus (out of the 4 buildings), to get the best connectivity for maximum
no. of computers. Justify your answer. 1
(ii) Suggest and draw the cable layout to efficiently connect various buildings
within the CHENNAI campus for connecting the computers. 1
(iii) Which hardware device will you suggest to be procured by the company to
be installed to protect and control the internet uses within the campus ? 1
(iv) Which of the following will you suggest to establish the online face-to-face
communication between the people in the Admin Office of CHENNAI
campus and DELHI Head Office ? 1
(a) Cable TV
(b) Email
(c) Video Conferencing
(d) Text Chat
___________

Thursday, 28 April 2016

practice questions for class & Object

1.     Define a class Travel in C++ with the description given below:
Private members:
plancode of type long place of type characters array
 number_of_travellers of type integer
 number_of_buses of type integer
Public members:
 A constructor to assign initial values of plancode as 1001, place as “Kolkata”, number_of_travellers as 5 and number_of_buses as 1
A function newplan( ) which allows user to enter plancode , place and number_of_travellers and also assign the number_of_buses as per the following conditions:
number_of_travellers        number_of_buses
less than 20                                         2
equal to and more than 20
 and less than 40                                3
equal to and more than 40               4
 A function show( ) to display the contents of all the data members on the screen
2. Answer the questions (i) to (iv) based on the following code :
class Goods {
int id; protected :
char name[20]; long qty;
void Incr(int n);
public :
Goods(); ~Goods();
void get();
};
class Food_products : public Goods {
char exp_dt[10];
protected : int id; int qty;
public :
void getd();
void showd();
};
class Cosmetics : private Goods {
 int qty; char exp_date[10];
protected : int id;
 public :                                                 
~Cosmetics();
Cosmetics();
 void show();
};




(i)                How many bytes will be required by an object of class Food_products.
(ii)               (ii) Name the member functions accessible through the object of class Food_products.
(iii)             From the following, Identify the member function(s) that cannot be called directly from the object of class Cosmetics show(), getd(), get()
(iv)             (iv) If the class cosmetics inherits the properties of food_products class also, then name the type of inheritance
33 .     Describe friend function with example.
44 .     what is static data member and static function
55 .     Explain nested class with suitable  program.
66 .     Write four  features of constructor and destructor
77 .       Write the following law of Boolean algebra and prove with truth table
a)     Absorption law  b) distributive law    c) complementary law   d) involution law
e)  Idempotent  law  f) associative law
8) Write D Morgan’s theorem and prove it algebraically
9) Define the following terms
a) keyword   b)literals   c) identifier d) default parameter e) function prototype   f) type casting   g) explicit data type conversion   h) random()   i) randomize()  j) header files   k


Sunday, 17 April 2016

CONSTRUCTOR AND DESTRUCTOR


CONSTRUCTOR AND DESTRUCTOR
We initialize the built in data type during declaration like int a=5
We also initialize array during declaration int a[ ]={1,2,3,4};
Char name[ ]=”Sachin”;
We also initialize structure like given below
#include<iostream.h>
#include<conio.h>
struct player
{
int id,age;
char name[20];
};
void main()
{
player p={7,32,"Dhoni"};
cout<<p.id<<"-"<<p.name<<"-"<<p.age<<endl;
getch();
}
Here is the question how we can initialize the class?

Solution is constructor
Before learning how to define constructor we should know more about Feature of constructer
Features of constructor
1.       It has no return data type
2.       It is also like a member function
3.       Name of class and constructor is always same
4.       It is implicitly called
5.       It can be overloaded
6.       It can’t be inherited but derived class can call base class constructor
7.       It follows the access rule
8.       When object is declared constructor function will be invoke according to matching parameter

Defining constructor
class student
{
int age;
public:
student()      // constructor
{
}
void get();
void show();
};
Here we have defined one constructor we can see that it is defined like function, name of constructor and class is same, no return type even void
When we declare object student s constructor will be invoked. Here we can see that no value is passed in constructor so no value will be passed in object
We can also define more than one constructor in a class. As we know that it can be overloaded. When more than one constructor is defined constructor will be called according to matching of arguments.
Ex.
class student
{
int age;
public:
student()      // constructor  1
{
}
Student(int a) // constructor 2
{
age=a;
}
void get();
void show();
};
If we declare object student s constructor 1 will be invoked as its argument is matching, similarly when we declare object like
student s(5);
Constructor 2 will be invoked

Destructor:- as we have discussed constructor is used to initialize the object. If we declare so many objects in a program then each object will occupy memory. If some constructor is not in use memory occupied by it must be released.  C++ compiler has one interesting features which release the memory occupied by an object when its life time is over

Destructor is a member function which destroy the object/release the memory occupied by object when its life time is over
It can be define like
~student()
{
}
We use ~(Tild) sign to define destructor

Features of destructor is almost same like constructor. Main difference between constructor and destructor is that constructor is used to initialize the object while destructor is used to destroy the object. only one destructor can be defined for class but destructor can't be overloaded.
Features of destructor
1.       It has no return data type
2.       It is also like a member function
3.       Name of class and destructor is always same
4.       It is implicitly called when life time of object is over.
5.       It can’t be inherited but derived class can call base class constructor
6.       It follows the access rule
7.       When object is declared destructor function will be invoke according to matching parameter

      Types of constructor

1.       Default constructor
2.       Parametrized constructor
3.       Copy constructor

1.       Default constructor
Student()
{
}
Above define constructor is called default constructor  which does not have any arguments
When we declare object
student s;
default constructor will be invoked
student ()
{
Age =15;
}
This is also example of default constructor it also not having argument it will also called when student s ; object will be declared and it will initialize the age of student with 10.
Note:-  student() { } and student() { age =15} can’t be define in same class as it is not
satisfying the overloading rules.

2.       Parametrized constructor:
student(int a)
{
age=a;
}
For calling this constructor we have to declare object with matchin argument like
Student s(5);
3.    Copy constructor :- copy constructor is used to copy one object into another object.
If we talk about built in data type we assign value of one variable into other like
int a =5;
this type of initialization is called explicit assignment
there is another method of assignment int a(5);
we also assign object of structure like student s1,s2;
s1=s2
is there any method to assign one class object into another object of same class. It is possible with the help of copy constructor
copy constructor always takes one argument of class object in call by reference mode
Example student(student &s)
example of copy constructor
#include<iostream.h>
#include<conio.h>
#include<string.h>
class student
{
int roll,marks;
char name[10];
public:
student()
{
cout<<"\n default constructor"  ;
}
student(int r, int m, char n[])
{
cout<<"\n parametrized constructor";
roll=r;
strcpy(name ,n);
marks =m;
}
student(student &s)
{
cout<<"\n copy constructor\n";
roll= s.roll;
strcpy(name,s.name);
marks=s.marks;
}
~student(){
cout<<"\n destructor\n";
}
void get()
{
cout<<"\n enter roll"  ;
cin>>roll;
cout<<"\n enter name";
cin>>name;
cout<<"\n enter marks\n";
cin>>marks;
}
void show()
{
cout<<roll<<"\t"<<name<<"\t"<<marks<<endl     ;
}
};
void main()
{
{
student s(5,10,"Rahul");  // parametrized constructor is called
student m ;              // default constructor is called
m.get();
student n(m); // copy constructor is called
m.show();
s.show();
n.show();
getch();
}
getch();
}

output of the program


Practice Questions





Friday, 8 April 2016

CLASS AND OBJECT
CLASS:-           CLASS IS ABSTRACT USER DEFINED DATA TYPE
                                   CLASS IS WAY OF BINDING DATA AND METHOD TOGETHER
                                   CLASS IS GROUP OF SIMILAR KIND OF OBJECTS
Defining a class in c++
Student
Roll
Name
Age
Marks

Void get() // to accept student details
Void show()// to display student details

If we have to define class in C++ for the above class represented in diagram we can define like this
#include<iostream.h>
#include<conio.h>
class student
{
int roll,age,marks;       // by default data are private, private data are not accessible out side class
char name[20];
public:                     // functions are public means it will be accessible outside the class using object of class
void get()
{
cout<<"\n enter roll";
cin>>roll;
cout<<"\n enter name";
cin>>name;
cout<<"\n enter age";
cin>>age;
cout<<"\n enter roll";
cin>>marks;
}
void show()
{
cout<<"Name:"<<name<<endl;
cout<<"Noll:"<<roll<<endl;
cout<<"Age:"<<age<<endl;
cout<<"Marks:"<<marks<<endl;
}
};
void main()
{
student s;
s.get();
s.show();
getch();
}
Here function is defined inside the class. We can also define function outside the class as give below
#include<iostream.h>
#include<conio.h>
class student
{
int roll,age,marks;                   // by default data are private, private data are not accessible outside class
char name[20];
public:                           // functions are public means it will be accessible outside the class using object of class
void get(); // function prototype
void show();// function prototype
};
void student::get() // function is define using scope resolution operator , student::get() mean get of student class
{
cout<<"\n enter roll";
cin>>roll;
cout<<"\n enter name";
cin>>name;
cout<<"\n enter age";
cin>>age;
cout<<"\n enter roll";
cin>>marks;
}
void student::show()               // function is defined  using scope resolution operator , student::show() mean show                                                    of student class
{
cout<<"Name:"<<name<<endl;
cout<<"Noll:"<<roll<<endl;
cout<<"Age:"<<age<<endl;
cout<<"Marks:"<<marks<<endl;
}
void main()
{
student s;
s.get();
s.show();
getch();
Access modifiers :- (or access specifiers) are keywords in object-oriented languages that set the accessibility of classes, methods, and other members.
1.    Public :- accessible every where
2.    Protected :- accessible inside the class and in derived class
3.    Private:- accessible only by member function of class.

Using class in main Program
Class can be used in main program by declaring object
Since private members are not accessible outside object can access only public member
As shown in given example
void main()
{
student s;          // s is object of class student
s.get();                    // accessing get function(using .dot operator) of student class as it is public
s.show();                // accessing show function(using .dot operator) of student class as it is public
getch();
}
Array of object
Student s can store details of one student. If we have to store details of more than one student we can create array of student object like
Student s[5];
We can call the function student[i].get()
Example
void main()
{
student s[5];          //five  object of class student
for(i=0;i<5;i++)
{
S[i].get();              
}
for(i=0;i<5;i++)
{
S[i].show();          
}
getch();

}

}