Documente Academic
Documente Profesional
Documente Cultură
[All India]
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 names of the header files to which the following boelog :
(i) gets()
(ii) strcmp()
(iii) abs()
(iv) isalnum()
(c) Rewrite the corrected code for the following program. Underline each correction (if any) :
2
2
3
#include <iostream.h>
structure Supergym
{
int member number;
char membername[20];
char membertype[] = "HIG";
};
void main()
{
Supergym person1, person2;
cin << "Member Number :";
cin >> person1.membernumber;
cout << "Member Name :";
cin >> person1.membername;
person1.member type = "MIG";
person2 = person1;
cin << "Member Number :" << person2.membernumber;
cin << "Member Name :" << person2.membername;
cin << "Member Number :" << person2.membertype;
}
#include <iostream.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>
void ChangeString(char Text[], int &Counter)
{
char *Ptr = Text;
int Length = strlen(Text);
for ( ; Counter<Length 2; Counter+=2, Ptr++)
{
*(Ptr + Counter) = toupper((*Ptr + Counter));
}
}
void main()
{
clrscr();
int Position = 0;
char Message[] = "Pointers Fun";
ChangeString(Message, Position);
Examination Paper
#include <iostream.h>
void main()
{
int var1 = 5, var2 = 10;
for (int i = 1; i <= 2; I++)
{
cout << var1++ << '\t' << var2 << endl;
cout << var2 << '\t' << ++var1 << endl;
}
}
(f ) Write definition for a function SumSequence() 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
1 / x 3! / x2 + 5! / x3 7! / x4 + 9! / x5 . . . upto n terms
(Note : The symbol ! represents Factorial of a number i.e.,
5! = 5 x 4 x 3 x 2 x 1)
Ans. (a) Polymorphism. 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;
float radius;
int choice1;
clrscr();
cout << "\n1. For area of triangle ";
cout << "\n2. For area of rectangle ";
cout << "\n3. For area of circle ";
cout << "\nEnter 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 : ";
}
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;
float 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);
}
(iv) ctype.h
#include <iostream.h>
#include <string.h>
struct Supergym
{
int membernumber;
char membername[20];
char membertype[];
};
void main()
{
Supergym person1, peson2;
cout << "Member Number :";
cin >> person1.membernumber;
cout << "Member Name :";
cin >> person1.membername;
strcpy(person1.membertype, "MIG");
person2 = person1;
cout << "Member Number :" << person2.membernumber;
cout << "Member Name :" << person2.membername;
cout << "Member Number :" << person2.membertype;
}
Examination Paper
2. (a) Given the following C++ code, answer the questions (i) & (ii).
class TestMeOut
{
public :
~TestMeOut()
// Function 1
{ cout << "Leaving the examination hall " << endl; }
TestMeOut()
// Function 2
{ cout << "Appearing for examination " << endl;
void MyWork()
// Function 3
{ cout << "Attempting Questions " << endl; }
};
(i) In Object Oriented Programming, what is Function 1 referred as and when does it get invoked
/ called ?
(ii) In Object Oriented Programming, what is Function 2 referred as and when does it get invoked
/ called ?
(b) Declare a class myfolder with the following specification :
4
Private members of the class
Filenames
long
( to represent total number of bytes available in myfolder)
Usedspace
long
( to represent total number of bytes used in myfolder)
(i) Name the members, which can be accessed from the member functions of class human.
(ii) Name the members, which can be accessed by an object of class ape.
(iii) Name the members, which can be accessed by an object of class human.
(iv) What will be the size of an object (in bytes) of class human ?
Ans. (a) (i) Destructor, it is invoked as soon as the scope of the object gets over.
(ii) Constructor, it is invoked as soon as the object of the class is created.
(b) The class is as :
#include <iostream.h>
#include <conio.h>
class myfolder
{
char Filenames[10][25];
long Availspace;
long Usedspace;
public:
void Newfileentry();
long Retavailspace();
void Showfiles();
};
void myfolder::Newfileentry()
{
Examination Paper
}
long myfolder::Retavailspace()
{
return (Availspace/1024);
}
void myfolder::Showfiles()
{
for(int i=0;i<10;i++)
cout << Filenames[i] << endl;
}
void main()
{
myfolder mf;
mf.Newfileentry();
int x = mf.Retavailspace();
cout << "Total available space is = "<<x;
mf.Showfiles();
}
(c)
3. (a)
(b)
(c)
(d)
(e)
(i) The data members are : race and habitation and iq_level.
The member functions are : readape() and showape().
(ii) The member functions are : readape() and showape().
(iii) The member functions are : : readape(), showape(), readhuman() and showhuman().
(iv) The size of an object of human is 78 bytes.
Define a function SwapArray(int [], int) that would accept a one dimensional integer array NUMBERS
and its size N. The function should rearrange the array in such a way that the values of alternate
locations of the array are exchanged ( Assume the size of the array to be even)
Example :
If the array initially contains
{2, 5, 9, 14, 17, 8, 19, 16},
then after rearrangement the array should contain
{5, 2, 14, 9, 8, 17, 16, 19}
3
An array ARR[5][5] is stored in the memory with each element occupying 2 bytes of space. Assuming
the base address of ARR to be 1500, computer the address of ARR[2][4], when the array is stored :
(i) Row Wise (ii) Column Wise
4
Write a function in C++ to find the sum of diagonal elements from a 2 dimensional array of type float.
Use the array and its size as parameters with float as its return type.
2
Obtain the postfix notation for the following infix notation of expression showing the contents of the
stack and postfix expression formed after each step of conversion :
2
A * B + ( C D/F)
Define member functions queins() to insert and quedel() to delete nodes of the linked list implemented
class queue, where each node has the following structure:
4
struct node
{
char name[20];
int age;
node * Link;
};
class queue
{
node *rear, *front;
public :
queue() { rear = NULL; front = NULL};
void queins();
void quedel();
};
(b) Given,
Let us assume that the Base index number is [0][0].
The Base address B = 1500,
No. of Rows R = 5,
No. of Columns C = 5,
Size of each element W = 2
And let the location of ARR[2][4] = L
(i) The given array ARR is stored as Row Major
Using the formula
L = B + W * [2 * C + 4]
= 1500 + 2 * [2 * 5 + 4]
= 1500 + 2 * [10 + 4]
= 1500 + 2 * 14
= 1500 + 28
= 1528
(ii) When the given array ARR is stored as Column Major
Using the formula
L = B + W * [2 + 4 * R]
= 1500 + 2 * [2 + 4 * 5]
= 1500 + 2 * [2 + 20]
= 1500 + 2 * 22
= 1500 + 44
= 1544
Examination Paper
Stack
Output
(
(
A
*
B
)
+
(
C
(
D
/
F
(
((
((
((*
((*
(
(+
(+(
(+(
(+(
(+((
(+((
(+((/
(+((/
A
A
AB
AB*
AB*
AB*
AB*C
AB*C
AB*C
AB*CD
AB*CD
AB*CDF
)
)
)
(+(
(+
Empty
AB*CDF/
AB*CDF/
AB*CDF/+
4. (a) Assuming that a text file named First.TXT contains some text written into it, write a function named
vowelwords, that reads the file FIRST.TXT and creates a new file named SECOND.TXT, to contain
only those words from the file FIRST.TXT which start with a lowercase vowel (i.e., with a, e, i,
o, u). For example if the file FIRST.TXT contains
Carry umbrella and overcoat when it rains
Then the file SECOND.TXT shall contain
Umbrella and overcoat it
3
(b) Assuming the class Computer as follows:
2
class Computer
{
char chiptype[10];
int speed;
Examination Paper
public:
void getdetails() {
gets(chiptype);
cin>>speed;
}
void showdetails() {
cout<<"Chip"<<chiptype<<"Speed = "<<speed;
}
};
Write a function readfile() to read all the records present in an already existing binary file SHIP.DAT
and display them on the screen, also count the number of records present in the file.
Ans. (a) The function is :
void vowelwords()
{
fstream afile,bfile;
char ch,ch1;
afile.open("FIRST.TXT",ios::in);
bfile.open("SECOND.TXT",ios::out);
ch1 = ' ';
clrscr();
while(afile)
{
ch1 = ' ';
afile.get(ch);
if (( ch =='a') || (ch =='e') || (ch=='i')||(ch=='o')||(ch=='u')&&(ch1==' '))
{
ch1=ch;
while(ch!=' ')
{
bfile.put(ch);
afile.get(ch);
ch1 = ch;
if(ch==' ')
break;
}
bfile.put(' ');
} else
{
ch1 = ch;
while(ch!=' ')
{
if (!afile)
break;
afile.get(ch);
}
}
}
afile.close();
bfile.close();
}
void readfile()
{
computer COMP;
int reccount = 0;
fstream Cfile;
Cfile.open("SHIP.DAT", ios::in|ios::binary);
while (Cfile)
{
Cfile.read((char *)&COMP, sizeof(COMP));
reccount++;
COMP.showdetails();
}
cout << "Total number of records are : " << reccount;
Cfile.close();
}
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
Book_Id
Book_Name
Author_Name
Publishers Price Type
Quantity
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
F0001
The Tears
William Hopkins First Publ
750
Fiction
10
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
F0002
Thunderbolts
Anna Roberts
First Publ. 700
Fictioin
5
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
T0001
My First C++
Brain & Brooke
EPB
250
Text
10
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
T0002
C++ Brainworks
A.W. Rossaine
TDH
325
Text
5
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
C0001
Fast Cook
Lata Kapoor
EPB
350
Cookery 8
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567
Table : Issued
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
Book_Id
Quantity_Issued
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
F0001
3
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
T0001
1
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
C0001
5
12345678901234567890123456789012123
Write SQL queries for (b) to (g) and output of (h):
To show Book name, Author name and Price of books of EPB. Publishers.
1
To list the names from books of Fiction type.
1
To display the names and price of the books in descending order of their price.
1
To increase the price of all books of First Publ. Publishers by 50.
1
To display the Book_Id, Book_Name and Quantity_Issued for all books which have been issued.
(The query will require contents from both the tables.)
1
(g) To insert a new row in the table Issued having the following data :
1
F0002, 4
(h) Give the output of the following queries based on the above tables :
2
(i) SELECT COUNT(DISTINCT Publishers) FROM Books;
(ii) SELECT SUM(Price) FROM Books WHERE Quantity > 5;
(iii) SELECT Book_Name, Author_Name FROM BooksWHERE Price < 500;
(iv) SELECT COUNT (*) FROM Books;
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 the data. The unnecessary repetition of data is called redundancy. Normalization
is the process of analyzing data. So, the redundancy gets reduced.
1NF. A table is said to be in 1NF if no two rows are identical and each table entry is single valued.
(b)
(c)
(d)
(e)
(f )
Examination Paper
11
(b)
(c)
(d)
(e)
(f )
(g)
(h)
6. (a)
(b)
F(A,B,C)
(c) Obtain a simplified form for the following Boolean Expression using Karnaughs Map :
F(a, b, c, d) = (0, 1, 2, 4, 5, 7, 8, 9, 10, 11, 14)
(d) Draw the logic circuit for a Half Adder using NAND gates only.
(e) Interpret the following Logic Circuit as Boolean Expression :
W
X
F
Y
Z
Ans. (a) The Absorption laws are :
(i) X + X.Y = X
(ii) X(X+Y) = X
Hence,
(i) X + X.Y = X ( 1 + Y )
= X.1
[Identity Law]
=X
3
2
1
a'b'
c'd'
1
a'b
ab
ab'
(d)
(e)
7. (a)
(b)
(c)
(d)
Ans. (a)
(b)
(c)
(d)
c'd
1
1
cd
4
6
12
cd'
1
13
8
9
15
11
14
10
Examination Paper
13