Sunteți pe pagina 1din 13

Examination Papers, 2004

[All India]
Maximum Marks : 70
Note.

Duration : 3 Hours

All the questions are compulsory.


Programming Language : C++

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;
}

(d) What will be the output of the following program :

#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

cout << Message << " @ " << Position;


}

(e) What will be the output of the following program :

#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 : ";

2 Together with Computer Science (C++) XII

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;
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);
}

(b) (i) stdio.h


(ii) string.h
(iii) math.h
(c) The correct program with underline correction is :

(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;
}

(d) The output is :


PoiNterRs Fun @ 10

Examination Paper

(e) The output is :


5 9
9 7
7 7
7 9
(f ) The function is
#include <iostream.h>
#include <math.h>
#include <conio.h>
double SumSeries(double x, int N)
{
double s = 1/x;
float xpower, factVal, fact;
int i, j;
for(i=1; i<N; i++)
{
xpower = 1;
for (j=2; 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 (fact/xpower);
else
s = s + (fact/xpower);
}
return(s);
}

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

an array of strings of size[10][25]


( to represent all the names of files inside myfolder)
Availspace

long
( to represent total number of bytes available in myfolder)
Usedspace
long
( to represent total number of bytes used in myfolder)

4 Together with Computer Science (C++) XII

public members of the class


Newfileentry()

A function to accept values of Filenames, Availspace and Usedspace from


user
Retavailspace()
A Fucntion that returns the value of total Kilobytes available
( 1 Kilobytes = 1024 bytes)
Showfiles()

a function that displays the names of all the files in myfolder


(c) Given the following class definitions answer that follow:
4
class livingbeing
{
char specification[20];
int averageager;
public:
void read();
void show();
};
class ape : private livingbeing
{
int no_of_organs, no_of_bones;
protected :
int iq_level();
public:
void readape();
void showape();
};
class human : public ape
{
char race[20];
char habitation[30];
public:
void readhuman();
void showhuman();
};

(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

cout << "Enter the names of the files ";


for(int i=0;i<10;i++)
cin >> Filenames[i];
cout << "Enter the available spaces ";
cin >> Availspace;
cout << "Enter the used space ";
cin >> Usedspace;

}
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];

6 Together with Computer Science (C++) XII

int age;
node * Link;

};
class queue
{
node *rear, *front;
public :
queue() { rear = NULL; front = NULL};
void queins();
void quedel();
};

Ans. (a) The function is :


void SwapArray(int NUMBER[8], int N)
{
int temp;
int j;
for (int i=0; i<N; i++)
{
j = i + 1;
temp = NUMBER[i];
NUMBER[i] = NUMBER[j];
NUMBER[j] = temp;
j;
i++;
}
for (i=0; i<N; i++)
cout << NUMBER[i] << endl;
}

(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

(c) The function is :


void sum_diagonal(float MATRIX[6][6], int M, int N)
{
int i, j, s1 = 0, s2 = 0;
cout << "Input steps";
cout << "\n\yEnter the element in the array\n";
for(i=0;i<M;i++)
for(j=0;j<N;j++)
cin >> MATRIX[i][j];
// Display the array elements
for(i=0;i<M;i++)
{
for(j=0;j<N; j++)
cout << MATRIX[i][j] << "\t";
cout << \n;
}
// Finding the diagonal sum in s1 from left index to right
for(i=0; i<M; i++)
for(j=0; j<N; j++)
{
s1 = s1 + MATRIX[i][j];
i++;
}
// Finding the diagonal sum s2 from right index to left
for (i=0; i<=M; i++)
for(j=N1;j>=0; j)
{
s2 = s2 + MATRIX[i][j];
i++;
}
// The resulted sum of diagonals
cout << s2 << " " << s1;
getch();
}

(d) The postfix notation of A * B + (C D/F) is :


((A*B)+(C(D/F)))
Input

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

8 Together with Computer Science (C++) XII

)
)
)

(+(
(+
Empty

AB*CDF/
AB*CDF/
AB*CDF/+

Hence, the postfix notation of A * B + (C - D/F) is : AB*CDF/-+.


(e) The queins() function is :
void queue::queins()
{
node *temp = new node;
cout<< "Enter the name : ";
gets(temp>name);
cout<< "Enter age : ";
cin>>temp>age;
temp>Link = NULL;
if (rear == NULL) {
rear = temp;
front = rear;
}
else
{
rear >Link=temp;
rear = temp;
}
}
// Function body for delete queue elements.
void queue::quedel()
{
node *temp;
int val;
if (front == NULL)
{
cout << "Queue Empty";
val=1;
}
else
{
temp = front;
front = front->Link;
temp->Link = NULL;
delete temp;
}
}

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();
}

(b) The function is :

void readfile()
{
computer COMP;
int reccount = 0;

10 Together with Computer Science (C++) XII

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();
}

5. (a) What do you understand by normalization ? what is First Normal Form ?


2
Given the following tables for a database LIBRARY
Table : Books
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234567

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)

SELECT book_name, author_name, price FROM books where publishers = 'EPB';


SELECT book_name FROM books where type = 'Fiction';
SELECT book_name, price FROM books order by price desc;
UPDATE books
SET price = price + 50
WHERE publishers = 'First Publ.';
SELECT a.book_id, a.book_name, b.quantity_issued FROM books a, issued b
WHERE a.book_id = b.book_id;
INSERT INTO issued VALUES('F0002', 4);
(i) 3
(ii) 1350
(iii) My First C++
Brain & Brooke
C++ Brainworks A.W. Rossaine
Fast Cook
Lata Kapoor
(iv) 5
State and prove the absorption law algebraically.
2
Given the following truth table, derive a sum of product(SOP) and Product of Sum(POS) form of
Boolean expression from it :
2
A

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

12 Together with Computer Science (C++) XII

3
2
1

(ii) X( X + Y ) = X.X + X.Y


= X + X.Y[Idemponent Law]
= X( 1 + Y)[Identity Law]
= X.1
=X
(b) SOP = A'B'C'+A'B'C+A'BC+AB'C+ABC'
POS = (A+B'+C)(A'B+C)(A'+B'+C')
(c) The K-Map is :

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

Hence, F = a'c' + bc'd + ab'c + cd' + b'd'.


Note. The concept deleted from revised syllabus 2005 onward examination.
F = (W.X')(Y'.Z).
Write two advantages and two disadvantages for STAR topology.
1
Write one difference between coaxial and optical cable.
1
Explain the following terms in short :
2
(i) FTP
(ii) URL
Define Packet Switching.
1
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
Coaxial cable. It consists of a solid wire core surrounded by one or more foil or braided wire shields,
each separated from the other by some kind of plastic insulator. It is mostly used in the cable wires.
Optical fibre cable. It consists of thin strands of glass or glass-line material which are so connected
that they carry light from source at one end to destination at the other end. The main advantage of
this cable is their complete immunity to noise. But this cable is very expensive as compared to the
coaxial cable.
(i) FTP. File Transfer Protocol (FTP) is the name of a special set of protocols used by computers
connected over the Internet to transfer files.
(ii) URL. Uniform Resource Locator, an address on the World Wide Web. A URL looks like this :
http://www.vsnl.net.in/index.html.
A Packet Switching network divides the data traffic into blocks called packets that have a 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 destinations, 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 destinations.

Examination Paper

13

S-ar putea să vă placă și