Documente Academic
Documente Profesional
Documente Cultură
[Comptt.]
Maximum Marks : 70
Note.
Duration : 3 Hours
1. (a) What is polymorphism ? Give an example in C++ to show its implementation in C++.
(b) Write the name of header files to which the following belong :
(i) sqrt()
(ii) strcpy()
(iii) isalpha()
(iv) open()
(c) Rewrite the corrected code for the following program, underline each correction (if any) :
2
1
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 :
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
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 Heros 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 * (sa) * (sb) * (sc));
return(a1);
}
float area(float l, float w) {
return(l*w);
}
float area( float radius) {
return(3.14 * radius * radius);
}
(ii) string.h
(iii) ctype.h
(iv) fstream.h
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
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;
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)
(ii)
(iii)
(iv)
void DF2();
A3, B3,A2, B2
16
There is no function F1 in the class.
Examination Paper
3. (a)
(b)
(c)
(d)
(e)
(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
10
*
PUSH 5
PUSH 10
POP 10
POP 5
Calculate 5 * 10 = 50
PUSH 50
PUSH 20
PUSH 2
POP 2
POP 20
Calculate 20 / 2 = 10
PUSH 10
POP 50
POP 10
5
5, 10
20
2
/
50
50, 20
50, 20, 2
50, 10
Calculate 50 + 10 = 60
PUSH 60
60 (Result of stack)
Examination Paper
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>
#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.
(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
2
Hauz Khas
80
80
10
Anand Travels
85000
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
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
8
Paschim Vihar
40
40
20
Speed Travels
55000
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
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
1
1
1
1
1
Examination Paper
Output
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 its dual for free. The dual of (A+BC+AB)
is : A.(B+C).(A+B)
(b) DeMorgans 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
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
y
sum = x + y + z
carry = x . y + y . z + x . z
Examination Paper
11
sum
carry
01
11
10
F = A. + BC
(g) F = XYZ + XYZ + XYZ + 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.
Examination Paper
13