Computer Science - XII
Computer Science - XII
Public Members
• A function FEEDINFO() to allow user to enter values for Flight Number, Destination,
Distance & call function CALFUEL() to calculate the quantity of Fuel
• A function SHOWINFO() to allow user to view the content of all the data members
Note : Two options with the following pattern are generally asked in the Board Exam. Various
optional questions are given below.
Q7. Answer the following questions after going through the following class:
class Seminar
{
int Time;
public:
Seminar(); //Function 1
void Lecture() //Function 2
{cout<<”Lectures in the seminar on”<<end1;}
Seminar(int); //Function 3
Seminar(Seminar &abc); //Function 4
~Seminar() //Function 5
{ cout<<”Vote of thanks”<<end1;}
};
(i) In Object Oriented Programming, what is Function 5 referred as and when does it get
invoked/called?
(ii) In Object Oriented Programming, which concept is illustrated by Function 1, Function 3
and Function 4 all together?
(iii) Which category of constructor - Function 1 belongs to? Write an example illustrating the
calls for Function 1.
(iv) Which category of constructor - Function 3 belongs to? Write an example illustrating the
calls for Function 3.
(v) Which category of constructor - Function 4 belongs to? Write an example illustrating the
calls for Function 4.
(vi) Write an example illustrating the calls for Function 3 explicitly.
(vii) Write an example illustrating the calls for Function 4 explicitly.
(viii) Write the complete definition for Function 1 to initialize Time as 30.
(ix) Write the complete definition for Function 3 to initialize Time with Mytime as
parameter to the Function 3.
(x) Write the complete definition for Function 4.
Q8. Answer the following questions after going through the following class:
class Complex
{
int x;
int y;
public:
Complex(); //Function 1
void disp() //Function 2
{cout<<”The Complex number is : “<<x<<” + “<<y<<”i”<<end1;}
Complex(int, int); //Function 3
Complex(Complex &abc); //Function 4
};
(i) Which category of constructor - Function 1 belongs to? Write an example illustrating the
calls for Function 1.
(ii) Which category of constructor - Function 3 belongs to? Write an example illustrating the
calls for Function 3.
(iii) Which category of constructor - Function 4 belongs to? Write an example illustrating the
calls for Function 4.
(iv) Write an example illustrating the calls for Function 3 explicitly.
(v) Write an example illustrating the calls for Function 4 explicitly.
(vi) Write the complete definition for Function 1 to initialize x as 10 and y as 20.
(vii) Write the complete definition for Function 3 to initialize the data members with p and
q as parameters to the Function 3.
(viii) Write the complete definition for Function 4.
Inheritance
(i) Write the members which can be accessed from the member functions of class human.
(ii) Write the members, which can be accessed by an object of class human.
(iii) What is the size of an object (in bytes) of class human?
(iv) Write the class(es) which objects can access read() declared in livingbeing class.
class parent class father : protected parent class mother : public father
{ { {
(i) In case of the class father, what is the base class of father and what is the derived class of
father?
(ii) Write the data member(s) that can be accessed from function dispdata().
(iii) Write the member function(s), which can be accessed by an object of mother class.
(iv) Is the member function outputdata() accessible to the objects of father class?
Q4. Answer the questions (i) to (iv) based on the following:
class person class client : private person class doctor : public person
{ { {
int x;
(i) What type of inheritance is depicted by the above example?
(ii) Write the member functions, which can be called by the object of class client.
(iii) What is the size in bytes of the object of class doctor and client respectively?
(iv) Write the data members, which can be used by the member functions of the class doctor.
(i) Write the names of data members, which are accessible from objects belonging to class
AUTHOR.
(ii) Write the names of all the members which are accessible from member functions of class
AUTHOR.
(iii) How many bytes are required by an object belonging to class AUTHOR?
(v) Write the sequence of the constructors’ invocation when the object of author is created.
{ { {
float Salary;
(i) Write the names of data members which are accessible from objects belonging to class
CUSTOMER.
(ii) Write the member functions that are accessible from objects belonging to class SALESMAN.
(iii) Write the names of all the members which are accessible from member functions of class
SHOP.
(iv) How many bytes will be required by an object belonging to class SHOP?
Address Calculation
Short Answer Questions ( 3 marks)
Formulae of Row Major & Column Major are used in the given questions. Kindly go through it.
Q1. An array x[30][10] is stored in the memory with each element requiring 4 bytes of storage. If the
base address of x is 4500, find out memory locations of x[12][8] and x[2][4], if the content is
stored along the row.
Q2. An array P[20][30] is stored in the memory along the column with each of the element
occupying 4 bytes, find out the Base Address of the array, if an element P[2][20] is stored at
the memory location 5000.
Q3. An array ARR[5][25] is stored in the memory with each element occupying 4 bytes of space.
Assuming the base address of ARR to be 1000, compute the address of ARR[5][7], when the
array is stored as : (i) Row wise (ii) Column wise.
Q4. An array S[40][30] is stored in the memory along the row with each of the element occupying 2
bytes, find out the memory location for the element S[20][10], if an element S[15][5] is stored
at the memory location 5500.
Q5. An array P[20][30] is stored in the memory along the column with each of the element
occupying 4 bytes, find out the memory location for the element P[5][15], if an element P[2]
[20] is stored at the memory location 5000.
Note : Practice the way to write the function definition where array and its size are passed as
arguments. Practice with the concepts of accessing the elements of the one / two dimensional
array. Apply the suitable logic to solve the given problem and write the coding of it.
Q1. Write a function in C++ to find sum of rows from a two dimensional array.
Q2. Write a function in C++ to find the sum of both left and right diagonal elements from a two
dimensional array (matrix).
Q3. Write a function in C++ which accepts an integer array and its size as arguments and replaces
elements having even values with its half and elements having odd values with twice its value.
eg:
if the array contains : 3, 4, 5, 16, 9
then the function should be rearranged as 6, 2,10,8, 18
Q4. Write a user defined function in C++ which intakes one dimensional array and size of array as
argument and display the elements which are prime.
If 1D array is 10 , 2 , 3 , 4 , 5 , 16 , 17 , 23
Then prime numbers in above array are: 2 , 3 , 5, 17, 23
Q5. Write a function in C++ which accepts an integer array and its size as arguments/parameters and
exchanges the values at alternate locations.
example : if the array is 8,10,1,3,17,90,13,60 then rearrange the array as 10,8,3,1,90,17,60,13
Short Answer Questions ( 3 marks)
Q1. Write a function in C++ to merge the contents of two sorted arrays A & B into third array C.
Assuming array A is sorted in ascending order, B is sorted in descending order, the resultant
array is required to be in ascending order.
Q2. Given two arrays of integers x and y of sizes m and n respectively. Third array of integers z has
m+n size. These are passed as the arguments to the function EXCHANGE(). Write a function
named EXCHANGE() which will produce the elements to the third array named z, such that the
following sequence is followed:
(i) All odds numbers of x from left to right are copied into z from left to right.
(ii) All even number of x from left to right are copied into z from right to left.
(iii) All odd numbers of y from left to right are copied into z from left to right.
(iv) All even number of y from left to right are copied into z from right to left.
e.g.: x is {3,2,1,7,6,3}
and y is {9,3,5,6,2,8,10}
then z = {3,1,7,3,9,3,5,10,8,2,6,6,2}
Q3. Write function SORTPOINTS() in c++ to sort an array of structure Game in descending order of
points using Bubble Sort
Note: Assume the following definition of structure Game
struct Game
{
long PNo; // Player Number
char PName[20];
long points;
};
Q4. Write a function in C++ which accepts an integer array and its size as arguments and assign the
elements into a two dimensional array of integers in the following format
If the array is 1,2,3,4,5,6 if the array is 1,2,3
The resultant 2D array is The resultant 2D array is
123456 123
012345 012
001234 001
000123
000012
000001
Q5. Write a function in C++ which accepts an integer array of double dimensional with its size as
arguments and displays the total numbers of odd, even and prime numbers in the array.
Example : if the following integer array will be passed to the function, i.e.
6 4 13 19 5
7 3 8 11 51
9 12 23 4 6
21 29 18 9 10
28 5 12 2 6
Then the output should be : The total odd numbers are : 13
The total odd numbers are : 12
The total odd numbers are : 10
Note : Insertion at the beginning of Linked List (Push operation in Stack), Insertion at the end of
Linked List (Insertion in a Queue), Deletion from the beginning of Linked List (Pop operation
in Stack as well as Deletion of node in a Queue) are in the syllabus. So, only the logic of
these three functions should be practiced. The logic and the way to solve these functions are
given below. Practice them.
Q1. Write a function in C++ to delete a node containing customer’s information, from a dynamically
allocated Queue of Customers implemented with the help of the following structure:
struct Customer
{
int CNo;
char CName[20];
Customer *Link;
};
Q2. Write a function in C++ to delete a node containing Book’s information, from a dynamically
allocated Stack of Books implemented with the help of the following structure.
struct Book
{
int BNo;
char BName[20];
Book *Next;
};
Q3. Write a function in C++ to perform a PUSH operation in a dynamically allocated stack considering
the following:
struct node
{ int x,y;
node *Link;
};
Q4. Write a function in C++ to perform Insert operation in a dynamically allocated Queue containing
names of students.
struct stud
{
char Name[20];
stud *Link;
};
Q5. Write a function in C++ to perform Push operation on a dynamically allocated Stack containing
real numbers. struct NODE
{
float Data; NODE *Link;
};
(Infix to Postfix)
Q4. Convert A + ( B * C – ( D / E )) * F into postfix form showing stack status after every step.
Q1. Observe the program segment given below carefully and fill the blanks marked as Statement 1
and Statement 2 using seekg()/seekp() functions for performing the required task.
#include <fstream.h>
class Item
{
int Ino;char Item[20];
public:
//Function to search and display the content of a particular record
void Search(int );
//Function to modify the content of a particular record number
void Modify(int);
};
void Item::Search(int RecNo)
{
fstream File;
File.open(“STOCK.DAT”,ios::binary|ios::in);
______________________ //Statement 1
File.read((char*)this,sizeof(Item));
cout<<Ino<<”==>”<<Item<<endl;
File.close();
}
void Item::Modify(int RecNo)
{
fstream File;
File.open(“STOCK.DAT”,ios::binary|ios::in|ios::out);
cout>>Ino;cin.getline(Item,20);
______________________ //Statement 2
File.write((char*)this,sizeof(Item));
File.close();
}
Q2. Observe the program segment given below carefully and fill the blanks marked as
Statement 1 and Statement 2 using seekg() and tellg() functions for performing the required
task.
#include <fstream.h>
class Employee
{
int Eno;char Ename[20];
public:
//Function to count the total number of records
int Countrec();
};
int Item::Countrec()
{
fstream File;
File.open(“EMP.DAT”,ios::binary|ios::in);
______________________ //Statement 1
Q3. Observe the program segment given below carefully and answer the following:-
#include <fstream.h>
class stud
{
int rno; char name[20];
public:
void enroll();
void disp();
long rrno()
{return rno;}
};
void update(long i)
{
fstream File;
File.open(“STOCK.DAT”,ios::binary|ios::in);
Stud s1;
int record=0,found=0;
while(File.read((char*)&s1,sizeof(stud)))
{ if(i == s1.rrno())
{ cout<<”enter new score”;
S1.enroll();
______________________ //Statement 1
______________________ //Statement 2
Found=1;
}
Record++;
}
If(found==1)
Cout<<”record update”;
File.close();
}
Write the statement 1 to position the file pointer at the beginning of the record & statement
2 to write the record.
Q4. A file named as “STUDENT.DAT” contains the student records, i.e. objects of class student.
Assuming that the file is just opened through the object FILE of fstream class, in the required
file mode, write the command to position the put pointer to point to the beginning of the
second record from the last record.
Q5. A file named as “EMPLOYEE.DAT” contains the student records, i.e. objects of class employee.
Assuming that the file is just opened through the object FILE of fstream class, in the required
File mode, write the command to position the get pointer to point to eighth record from the
beginning.
Q1. What is a database system? What are the advantages provided by a database system?
Q2. What are the various levels of database abstraction in a database system?
Q3. What is Data Independence? What are the levels of Data Independence?
Q9. What is Data Definition Language? Give examples of some DDL commands.
Q10. What is Data Manipulation Language? Give examples of some DML commands.
Q1. Consider the following tables ACTIVITY and COACH. Write SQL commands for the statements
(i) to (iv) and give outputs for SQL queries (v) to (viii).
Table: ACTIVITY
ACode ActivityName ParticipantsNum PrizeMoney ScheduleDate
Table: COACH
PCode Name ACode
1 Ahmad Hussain 1001
2 Ravinder 1008
3 Janila 1001
4 Naaz 1003
(i) To display the name of all activities with their Acodes in descending order.
(ii) To display sum of PrizeMoney for each of the Number of participants groupings (as
shown in column ParticipantsNum 10,12,16).
(iii) To display the coach’s name and ACodes in ascending order of ACode from the table
COACH.
(iv) To display the content of the GAMES table whose ScheduleDate earlier than 01/01/2004
in ascending order of ParticipantNum.
(v) SELECT COUNT(DISTINCT ParticipantsNum) FROM ACTIVITY;
(vi) SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM ACTIVITY;
(vii) SELECT SUM(PrizeMoney) FROM ACTIVITY;
(viii) SELECT DISTINCT ParticipantNum FROM COACH;
Q2. Consider the following tables GAMES and PLAYER. Write SQL commands for the statements (i) to
(iv) and give outputs for SQL queries (v) to (viii).
Table: GAMES
Q3. Consider the following tables HOSPITAL. Give outputs for SQL queries (i) to (iv) and write SQL
commands for the statements (v) to (viii).
No Name Age Department Dateofadmin Charge Sex
1 Arpit 62 Surgery 21/01/06 300 M
2 Zayana 18 ENT 12/12/05 250 F
3 Kareem 68 Orthopedic 19/02/06 450 M
4 Abhilash 26 Surgery 24/11/06 300 M
5 Dhanya 24 ENT 20/10/06 350 F
6 Siju 23 Cardiology 10/10/06 800 M
7 Ankita 16 ENT 13/04/06 100 F
8 Divya 20 Cardiology 10/11/06 500 F
9 Nidhin 25 Orthopedic 12/05/06 700 M
10 Hari 28 Surgery 19/03/06 450 M
Q4. Consider the following tables BOOKS. Write SQL commands for the statements (i) to (iv) and give
outputs for SQL queries (v) to (viii).
Table : BOOKS
Q5. Consider the tables ITEMS & COMPANY. Write SQL commands for the statements (i) to (iv)
and give the outputs for SQL queries (v) to (viii).
Table : ITEMS
ID PNAME PRICE MDATE QTY
T001 Soap 12.00 11/03/2007 200
T002 Paste 39.50 23/12/2006 55
T003 Deodorant 125.00 12/06/2007 46
T004 Hair Oil 28.75 25/09/2007 325
T005 Cold Cream 66.00 09/10/2007 144
T006 Tooth Brush 25.00 17/02/2006 455
Table : COMPANY
ID COMP City
T001 HLL Mumbai
T008 Colgate Delhi
T003 HLL Mumbai
T004 Paras Haryana
T009 Ponds Noida
T006 Wipro Ahmedabad
i). To display PNAME, PRICE * QTY only for the city Mumbai.
ii). To display product name, company name & price for those items which IDs are equal to the
IDs of company.
iii). To delete the items produced before 2007.
iv). To increase the quantity by 20 for soap and paste.
v). SELECT COUNT(*) FROM ITEMS WHERE ITEMS.ID=COMPANY.ID;
vi). SELECT PNAME FROM ITEMS WHERE PRICE=SELECT MIN(PRICE) FROM ITEMS;
vii). SELECT COUNT(*) FROM COMPANY WHERE COMP LIKE “P_ _ _ _”;
viii). SELECT PNAME FROM ITEMS WHERE QTY<100;
Q6. In a database there are two tables ‘GARDEN’ and ‘CUSTOMER’ shown below-
TABLE :GARDEN
TABLE : CUSTOMER
Q8. Consider the table TEACHER given below. Write the commands in SQL for (i) to (iv) and
output for (v) to (viii) Table: TEACHER
BOOLEAN ALGEBRA
Short Answer Questions ( 2 marks)
Q1. Write the POS form of a Boolean function F, which is represented in a truth table as follows:
U V W F
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
Q2. Write the SOP form of a Boolean function G, which is represented in a truth table as follows:
X Y Z G
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 0
Q5. Convert the following function to its equivalent SOP shorthand notation.
F( A , B, C, D ) = ( 0, 3, 7, 9, 10, 14)
Q6. Convert the following function to its equivalent POS shorthand notation.
F( A , B, C, D ) = ( 1, 4, 6, 8, 11, 13)
Karnaugh Map
F( A, B, C, D ) = ( 0, 3, 5, 6, 7, 8, 11, 15 )
Q1. Write the equivalent Boolean Expression for the following Logic Circuit.
Q2. Write the equivalent Boolean Expression for the following Logic Circuit.
U
V
Q3. Draw the Logic Circuit Diagram for the following Boolean Expression :
F = ( A . C ) + ( A . B ) + ( B . C )
Block
A
D
Block
B
Centre to centre distances between various blocks Number of Computers
Q2. Ravya Industries has set up its new center at Kaka Nagar for its office and web based activities.
The company compound has 4 buildings as shown in the diagram below:
Fazz
RajBuildi
ng Building
Jazz
Harsh
Buildi Building
ng
Q3. Nootan Vidya Mandir in OOTY is setting up the network between its different wings. There are
4 wings named as SENIOR(S), MIDDLE(M), JUNIOR(J) and OFFICE(O).
Distance between the various wings are given below: Number of Computers
(i) Suggest a suitable Topology for networking the computer of all wings.
(ii) Name the wing where the server to be installed. Justify your answer.
(iii) Suggest the placement of Hub/Switch in the network.
(iv) Mention an economic technology to provide internet accessibility to all wings.
Q4. East and West Public Ltd. has decided to network all its offices spread in five buildings.
C
A
B
A to B 50 Mts
B to C 30 Mts
C to D 30 Mts
E
D
D to E 35 Mts
E to C 40 Mts
D to A 120 Mts
D to B 45 Mts
No of computers
E to B 65 Mts
(a) Suggest a
A 55
possible cable
layout for connecting the buildings. B 180
(b) Suggest the most suitable place to install the server of this C 60
organization.
D 55
(c) Suggest the placement of the following devices with
justification. E 70
(i.) Hub/Switch
(ii.) Repeater
(d) The company wants to link its head office in ‘A’ building to its Office in Sydney
(i) Which type of transmission medium is appropriate for such a link?
(ii) What type of network this connection result into?