Vous êtes sur la page 1sur 13

Examination Papers, 2004

[Comptt.]
Maximum Marks : 70 Duration : 3 Hours
Note. All the questions are compulsory.
Programming Language : C++

1. (a) What is polymorphism ? Give an example in C++ to show its implementation in C++. 2
(b) Write the name of header files to which the following belong : 1
(i) sqrt() (ii) strcpy() (iii) isalpha() (iv) open()
(c) Rewrite the corrected code for the following program, underline each correction (if any) : 2
#include<iostream.h>
void main()
{
int a,b;
cin>>a>>b;
int s = sum(a,b);
cout<<s;
}
void sum(int a,int b)
{
cout<<(a+b);
}
(d) Find the output of the following program, assuming that all required header files have been included:
3
void change(int x[4], int i) {
x[I] = x[I] * i;
}
void main() {
int x[] = {11, 21, 31, 41};
for(int i =0;i<4;i++) {
change(x, i);
cout<<x[i]<<”\n”;
}
}
(e) Find the output of the program assuming all the required header files have been included : 3
void main() {
int x[] = {10, 20, 30, 40,50};
int *p, **q;
int *t;
p = x;
t = x + 1;
q = &t;
cout<<*p<<","<<**q<<","<<*t++;
}
(f) Write definition for a function SumSeries() in C++ with two arguments/ parameters – double x and int
n. The function should return a value of type double and it should perform sum of the following
series: 4
x2 x 3 x4 x5
x - + - + - ..... upto N terms
3! 5! 7! 9!

Examination Paper 1
Ans. (a) The polymorphism contains three words as : poly means many or multiple; morph means to change
from one thing to another; and ism means the process of something. Function overloading implements
polymorphism.
// Program using function overloading to calculate the area of rectangle, area of triangle
// using Hero’s formula and area of circle.
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <math.h>
float area(float a, float b , float c);
float area(float l, float w);
float area(float r);
void main() {
char ch;
float len, wid, n1, n2, n3, ar, radius;
int choice1;
clrscr();
cout << "\n1. For area of triangle ";
cout << "\n2. For area of rectangle ";
cout << "\n3. For area of circle";
cout << "\n Enter choice : ";
cin >> choice1;
if (choice1 == 1) {
cout << "\nEnter the three sides of triangle : ";
cin >> n1 >> n2 >> n3;
ar = area(n1, n2, n3);
cout << "\nArea of triangle is : " < < ar;
}
if (choice1 == 2) {
cout << "\nEnter the length : ";
cin >> len;
cout << "\nEnter the width : ";
cin >> wid;
cout<< "\nArea of rectangle is : " << area(len, wid);
}
if (choice1 == 3) {
cout << "\nEnter the radius : ";
cin >> radius;
cout << "\n Area of circle : " << area(radius);
}
}
float area(float a, float b , float c) {
float s, a1;
s = (a + b + c) / 2;
a1 = sqrt(s * (s–a) * (s–b) * (s–c));
return(a1);
}
float area(float l, float w) {
return(l*w);
}
float area( float radius) {
return(3.14 * radius * radius);
}
(b) (i) math.h (ii) string.h (iii) ctype.h (iv) fstream.h
(c) The errors are :

2 Together with ® Computer Science (C++) – XII


Error 1: Function ‘sum’ should have a prototype
Error 2: Value of type void is not allowed ( As the return type of the function is void)
The correct code is :
#include<iostream.h>
void sum(int a, int b);
void main()
{
int a,b, s;
cin>>a>>b;
sum(a,b); //Error 1 and Error 2
cout<<s;
}
void sum(int a, int b)
{
cout<<(a+b);
}
(d) The output is as :
0
21
62
123
(e) The output is :
10,30,20
(f) The function is :
double SumSeries(double x, int N) {
float s = x, xpower, factVal, fact;
int i, j;
for(i=2; i<N; i++) {
xpower = 1;
for (j=1; j<=i; j++)
xpower = xpower * x;
factVal = i + 1;
fact = 1;
for (j=1; j<=factVal; j++)
fact = fact * j;
if ((i % 2) == 0)
s = s – (xpower/fact);
else
s = s + (xpower/fact);
}
return(s);
}
2. (a) What is the difference between nesting and inheritance ? Explain with the help of an example. 2
(b) Define a class with complete function definitions COMPETITION in C++ with following specifications:
4
private members
event_no integer
description char(30)
score integer
qualified char
public members
input() To take input for event_no, description and score

Examination Paper 3
Award ( ) To award qualified as ‘y’ if score is more than the cut off score passed as int to the
function else award ‘N’
show() To display all details
(c) Consider the following class definitions and answer the questions following it : 4
class Base {
int A1;
void BF1( );
protected :
int B1;
void BF2( );
public:
int C1;
void BF3;
} ob1;
class Middle : private Base {
int A2;
protected :
int B2;
void MF1( );
public:
int C2;
void MF3;
} ob2;
class Derived : protected Middle {
void DF1;
int A3;
public:
int B3;
void DF2( );
} ob3;
(i) Name the member functions accessible to the objects of Derived.
(ii) Name the data members that are accessible in function DF1().
(iii) What would be the size of class derived objects ?
(iv) Name the data members that are accessible in function F1( ).
Ans. (a) When one class is declared in another class. These type of classes are called nested classes. The
nesting of classes is also known as containership.
#include <iostream.h>
#include <conio.h>
class address {
int hno;
char city[15], state[2];
public:
void read_add();
void show_add();
};
class employee {
char emp_name[25];
address add;
double esalary;
public:
void emp_input(void);
void emp_print(void);
};

4 Together with ® Computer Science (C++) – XII


Inheritance is a capability to define custom data types using classes, enables you to reuse the code
you develop. Inheritance enables you to more readily reuse an object, making slight adjustments,
wherever necessary. For Example,
class Student {
private :
char name[20];
int check (int e);
public :
void getdata( );
void putdata( );
protected :
int total;
void calc( );
};
class School : private Student {
protected :
char class_stu[10];
public :
void getdata( );
void putdata( );
};
In the above example Student is the base class and School is the derived class.
(b) The class is as :
class COMPETITION {
private :
int event_no;
char description[30];
int score;
char qualified;
public :
void input() {
cout << "Enter event no. : ";
cin>>event_no;
cout << "Enter description : ";
gets(description);
cout << "Enter score : ";
cin>>score;
cout << "Enter qualified : ";
cin>>qualified;
}
void Award(int cut_off) {
if (score > cut_off)
qualified = ‘y’;
else
qualified = ‘N’;
}
void show() {
cout << event_no << description << score << qualified;
}
};
(c) (i) void DF2();
(ii) A3, B3,A2, B2
(iii) 16
(iv) There is no function F1 in the class.

Examination Paper 5
3. (a) (i) Give the number of elements in a circular queue. 1
(ii) With 12 memory locations if Front = 10 and Rear = 3. If 4 elements are deleted from above queue,
what will be the value of Front and Rear ? 1
(b) Evaluate the following postfix expression using a stack and show the contents of the stack after
execution of each operation. 2
5, 10, *, 20, 2, /, +
(c) 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
(i) Row Major, (ii) Column Major. 3
(d) Write a function bubble_sort to sort the passed array of 10 integers in descending order using
bubble sort. 2
(e) Consider the following declaration of linked stack, used by operating system in store instruction and
its address. Define the function pop( ) for it. 3
struct Inst_stk {
long mem_add;
char instruction[40];
Inst_stk *next;
} *top, *temp;
(f) Write a function check( ) to check if the passed array of 10 integers is sorted or not. The function
should return 1 if arranged in ascending order, -1 if arranged in descending order, 0 if it is not sorted.
4
Ans. (a) (i) There are two possibilities in a circular queue.
- When Rear is higher than Front :
Therefore, the number of elements is a simple difference of two positions
Number of elements = rear – front
- The position of front is higher than rear
Now, the total number of elements present in queue is the number of elements beyond
front and number of elements from first element to rear.
Number of elements = (rear – 1) + 1 + (MAX – front)
(ii) The value of Front is 2 and Rear is 3.
(b) The stack operation is :
Scanned Elements Operation Stack
5 PUSH 5 5
10 PUSH 10 5, 10
* POP 10
POP 5
Calculate 5 * 10 = 50
PUSH 50 50
20 PUSH 20 50, 20
2 PUSH 2 50, 20, 2
/ POP 2
POP 20
Calculate 20 / 2 = 10
PUSH 10 50, 10
+ POP 50
POP 10

6 Together with ® Computer Science (C++) – XII


Calculate 50 + 10 = 60
PUSH 60 60 (Result of stack)

(c) Given, B = 800, w = 2


(i) Row major order
n = 20
A[9][11] = 800 + 2(20(9 – 0) + (11 – 0))
= 800 + 2( 20 (9) + 11)
= 800 + 2(180 + 11)
= 800 + 2 (191)
= 800 + 382
= 1182
(ii) Column major order
m = 10
A[9][11] = 800 + 2((9 – 0) + 10(11 – 0))
= 800 + 2 (9 + 110)
= 800 + 2(119)
= 800 + 238
= 1038
(d) // The bubble sort function for descending order is :
void bubble_sort(int a[], int N) {
int i, j, temp;
for (i = 0; i < N; i++)
for (j = 0 ; j < N–1; j++)
if (a[j] < a[j+1]) {
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
(e) // Function body for delete stack elements
Inst_stk *pop(Inst_stk *top) {
Inst_stk *temp;
int madd,
clrscr();
char tins[40];
if (top == NULL ) {
cout<<"Stack Empty ";
} else {
temp = top;
top = top–>next;
madd = temp–>mem_add;
strcpy(tins, temp->Instruction);
temp–>next = NULL;
cout<<"\n\tPopped member add is : "<<madd
cout<<"\n\tPopped Instruction is : "<<tins;
delete temp;
}
return (top);
}

Examination Paper 7
(f) //Program to check whether an array is sorted or not.
#include<iostream.h>
#include<conio.h>
#include<process.h>
//FUNCTION FOR BUBBLE SORT
int check(int a[10]) {
int flag=0;
for(int j=0;j<9;j++) {
if(a[j] < a[j+1]) {
flag = 1;
} else {
flag = 0;
break;
}
}
if ( flag == 1)
return flag;
for( j=0;j<9;j++) {
if(a[j] > a[j+1]) {
flag = –1;
} else {
flag = 0;
break;
}
}
return flag;
}
main() {
int a[10];
int i,s;
clrscr();
cout<<"\n\tEnter the array \n";
for(i=0;i<10;i++) {
cout<<"\t";
cin>>a[i];
}
s = check(a);
if ( s == 1)
cout<<"Arranged in ascending order";
if ( s == –1)
cout <<"Arranged in descending order";
if ( s==0)
cout<<"Not arranged";
}
4. (a) How are binary files different from text files in C++ ? 1
(b) A text file named “Report.txt” exists on a disk. Write a program to create its copy named “Finerep.txt”,
which should be in small letters but the first letter of the file and first alphabetic character following
a full stop should be in uppercase. 4
Ans. (a) The data in the text file stored in the form of readable characters while the data in the binary file in the
binary format i.e., in the form of 0 and 1.
(b) The program is :
#include<fstream.h>
#include<conio.h>
#include<process.h>

8 Together with ® Computer Science (C++) – XII


#include<ctype.h>
void main() {
char in_char; // Input character
fstream in_obj, out_obj1;
in_obj.open("Report.TXT", ios::in); // Opens file for read mode
out_obj1.open("Finerep.txt", ios::out); // Opens file for write mode
if (!in_obj) {
cerr << "\n\n*** That file does not exist ***\n";
exit(0); // Exit program
}
cout << "\nCopying ... \n";
in_obj.get(in_char);
in_char = toupper(in_char);
out_obj1.put(in_char);
while (in_obj.get(in_char)) {
if (in_char == ‘.’) {
out_obj1.put(in_char);
in_obj.get(in_char);
in_char = toupper(in_char);
out_obj1.put(in_char);
} else
out_obj1.put(in_char);
}
in_obj.close();
out_obj1.close();
}
5. (a) What is the need of normalization ? Define the first normal form. 1
(b) Consider the following table :
Table : SchoolBus
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
RtNo area_covered capacity noofstudents distance Transporter Charges
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1 Vasant Kunj 100 120 10 Shivam Travels 100000
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
2 Hauz Khas 80 80 10 Anand Travels 85000
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
3 Pitampura 60 55 30 Anand Travels 60000
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
4 Rohini 100 90 35 Anand Travels 100000
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
5 Yamuna Vihar 50 60 20 Bhalla Co. 55000
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
6 Krishna Nagar 70 80 30 Yadav Co. 80000
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
7 Vasundhara 100 110 20 Yadav Co. 100000
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
8 Paschim Vihar 40 40 20 Speed Travels 55000
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
9 Saket 120 120 10 Speed Travels 100000
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
10 Janak Puri 100 100 20 Kisan Tours 95000
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
Write the SQL commands for the following :
(i) To show all records students more than the capacity in order of RtNo. 1
(ii) To show area_covered for buses covering more than 20 km, but charges less than 80000. 1
(iii) To show Transporter wise total no. of students travelling. 1
(iv) To show RtNo, area_covered and average cost per student for all routes. 1
(v) Add a new column drivername in the SchoolBus relation. 1

Examination Paper 9
(vi) Add a new record with following data: 1
(11, “Moti Bagh”, 35, 32, 10, “Kisan Tours”, 35000)
(vii) Give the output considering the original relation as given : 2
(1) Select sum(distance) from SchoolBus where Transporter = “Yadav Travels”;
(2) Select min(noofstudents) from SchoolBus;
(3) Select avg(charges) from SchoolBus where Transporter = “Anand Travels”;
(4) Select distinct transporter from SchoolBus;
Ans. (a) Normalization is a process of data analysis used for grouping data elements in a record. While
dealing with database there may be unnecessary repetition of data, which can cause problems in
storing, and retrieving of data. The unnecessary repetition of data is called redundancy. Normalization
is the process of analyzing data. So, the redundancy gets reduced.
First Normal Form :A table is said to be in first normal form if no two rows are identical and each entry
is single valued.
(b) (i) SELECT * FROM SCHOOLBUS WHERE noofstudents > capacity ORDER BY Rtno;
(ii) SELECT area_covered FROM SCHOOLBUS WHERE distance > 20AND Charges < 80000;
(iii) SELECT SUM(noofstudents) FROM SCHOOLBUS GROUP BY Transporter;
(iv) SELECT RtNo, area_covered, Charges/noofstudents FROM SCHOOLBUS;
(v) ALTER TABLE SCHOOLBUS
ADD (drivername CHAR(20));
(vi) INSERT INTO SCHOOLBUS
VALUES (11, “Moti Bagh”, 35, 32, 10, “Kisan Tours”, 35000);
(vii) (1) 50 (2) 40 (3) 81666.6 (4) 6
6. (a) State the principle of duality. Give the dual of ( A + BC + AB). 1
(b) Verify the following De Morgan’s law by algebraic means: 1
(X.Y)’ = X’ + Y’
(c) Draw the logic circuit diagram using NAND gate only for the following expression : 2
AB + A’B + A’B’
(d) Prove algebraically x + x’y = x + y 1
(e) Draw a logic diagram for full adder. Give the truth table for full adder. 2
(f) Obtain the simplified form of a Boolean expression using Karnaugh Map. 2
F(A, B, C) = π (0, 1, 2, 3, 4)
(g) Given the following truth table, write the sum of products form of the function F(X, Y, Z) 1
Inputs Output
X Y Z F
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1

10 Together with ® Computer Science (C++) – XII


Ans. (a) Duality Principle. Amy algebraic equality derived from the axioms of Boolean Algebra remains true
when the operators OR and AND are interchanged and the identity elements 0 and 1 are interchanged.
This property is called duality principle. For example,
x+1=1
x * 0 = 0 (dual)
Because of the duality principle, for any given theorem we get it’s dual for free. The dual of (A+BC+AB)
is : A.(B+C).(A+B)
(b) DeMorgan’s first theorem states that (X + Y)' = X'.Y'
We know that , X + X' = 1 and X.X' = 0
So , if (X + Y )' = X'.Y' then (X + Y ) + X'.Y' = 1
and (X + Y) .X'.Y' = 0
Let us prove first part ,
(X + Y ) + X'.Y' = 1
(X + Y)+X'Y' = ((X +Y ) + X').((X +Y ) + Y') [(X + Y) (X + Z) = X +Y.Z]
= (X + X' + Y).(X + Y + Y') = ( 1 + Y ) ( X + 1) [X + X' = 1 inverse law]
= 1.1 = 1 [1 + X =1 identity law]
(c) The NAND gate is :
A
B y

AB +AB +AB

(d) L.H.S. = x + xy
= (x + x) (x + y) [Distributive law x + x = 1]
= 1. (x + y)
= x + y = R.H.S
(e) Logic diagram of full-adder is :
x
z sum = x + y + z
y

carry = x . y + y . z + x . z

Examination Paper 11
The truth table for Full-adder is :
x y z sum carry
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
(f) The Karnugh Map is :
WZ
UV 00 01 11 10

0 0 0 0 0

1 0

F = A. + BC
(g) F = X’Y’Z + X’YZ’ + XY’Z’ + XYZ
7. (a) What is Firewall ? 1
(b) Explain packet switching technique. 1
(c) Expand URL. 1
(d) Explain the STAR topology with the help of diagram. State one advantage and one limitation of the
same. 2
Ans. (a) A firewall is a computer system or group of computer systems that reinforce information security
between two networks. These networks are referred to as an internal network and an outside network.
(b) A packet switching network divides the data traffic into blocks called packets that have maximum
length.
Each packet of user data travels in a data envelope, which gives the destination address of the packet
and a variety of control information. Each switching node in a minicomputer reads the packet into its
memory, examines the address, selects the next node to which it shall transmit the packet, and sends
it on its way. The packets eventually reach their destination, where their envelopes are stripped off.
Then, they may have to be reassembled to form the original user messages. It is rather like a postal
service in which letters in envelopes are passed from one post office to another until they reach their
destination.
(c) URL. Uniform Resource Locator, an address on the World Wide Web. A URL looks like this :
http://www.vsnl.net.in/index.html.
(d) A star topology in which all stations are connected to a central switch. A physical star topology is
one in which all branches of the network are connected through a hub. A logical star topology is one
in which the hub contains all of the intelligence of the network and directs all network transmissions.

12 Together with ® Computer Science (C++) – XII


Advantages of STAR topology
1. One Device per connection
2. Easy to access.
Disadvantages of STAR topology
1. Long cable length
2. Central node dependency

Examination Paper 13

Vous aimerez peut-être aussi