Académique Documents
Professionnel Documents
Culture Documents
[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 :
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);
};
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
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>
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
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.
Examination Paper 13