Вы находитесь на странице: 1из 12

Examination Papers, 2004

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

1. (a) What is Inheritance ? Give an example in C++ to show its implementation in C++. 2
(b) Write the names of the header files to which the following belong : 2
(i) sqrt() (ii) isalpha() (iii) puts() (iv) strcpy()
(c) Rewrite the corrected code for the following program. Underline each correction (if any) : 3
#include <iostream.h>
structure Swimmingclub
{
int mem number;
char memname[20];
char memtype[] = "LIG";
};
void main()
{
Swimminglcub per1, per2;
cin << "Member Number:";
cout >> memnumber.per1;
cout << "Member Name :";
cin >> peer1.membername;
per1.memtype = "HIG";
per2 = per1;
cin << "Member Number :" << per2.memnumber;
cin << "Member Name :" << per2.memname;
cin << "Member Number :" << per2.memtype;
}
(d) What will be the output of the following program : 2
#include <iostream.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>
void Newtext(char String[], int &Position) {
char *Pointer = String;
int Length = strlen(String);
for ( ; Position<Length – 2; Position+=2, Pointer++)
{
*(Pointer+Position) = toupper(*(Pointer + Position));
}
}
void main()
{
clrscr();
int Location = 0;
char Message[] = "Dynamic Act";
Newtext(Message, Location);
cout << Message << “ # ” << Location;
}

Examination Paper 1
(e) What will be the output of the following program : 2
#include <iostream.h>
void main()
{
int v1 = 5, v2 = 10;
for (int x = 1; x <= 2; x++)
{
cout << ++v1 << '\t' << v2– – << endl;
cout << – –v2 << '\t' << v1++ << endl;
}
}
(f ) Write definition for a function SumSeries() in C++ with two arguments/parameters – double x and int
n. The function should return a value o type double and it should perform sum of the following
series: 4
x – x2 / 3! + x3 / 5! – x4 / 7! + x5 / 9! – . . . 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) 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) (i) math.h (ii) ctype.h (iii) stdio.h (iv) string.h
(c) The correct program with underline correction is :
#include <iostream.h>
#include <string.h>
struct Swimmingclub
{
int memnumber;
char memname[20];
char memtype[] = "LIG";
};
void main()
{

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


Swimminglcub per1, per2;
cout << "Member Number:";
cin >> per1.memnumber;
cout << "Member Name :";
cin >> per1.memname;
strcpy(per1.memtype, "HIG");
per2 = per1;
cout << “Member Number :" << per2.memnumber;
cout << "Member Name :" << per2.menname;
cout << "Member Number :" << pe2.memtype;
}
(d) The output is :
DynAmiC ACt # 10
(e) The output is :
6 10
8 6
8 8
6 8
(f ) The function is : x – x2 / 3! + x3 / 5! – x4 / 7! + x5 / 9! – . . . upto n terms
double SumSeries(double x, int N)
{
float s = x;
float 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) Given the following C++ code, answer the questions (i) & (ii) 2
class Readbook
{
public:
Readbook() //Function 1
{cout << "Open the Book" << endl;}
void Readchapter() //Function 2
{cout << "Reading Chapter One" << endl;)
~Readbook() //Function 3
{cout << "Close the Book" << endl;}
};
(i) In Object Oriented Programming, what is Function1 referred as and when does it get invoked /
called ?

Examination Paper 3
(ii) In Object Oriented Programming, what is Function 3 referred as and when does it get invoked
/ called ?
(b) Declare a class Directory with the following specifications : 4
private members of the class
Docunames – an array of strings of size [10][25]
(to represent all the names of Documents inside Directory)
Freespace – long
(to represent total number of bytes available in Directory)
Occupied – long
(to represent total number of bytes used in Directory)
public members of the class
Newdocuentry() – A function to accept values of Docunames, Freespace and Occupied from
user
RetFreespace() – A function that returns the value of total Kilobytes available
(1 Kilobyte = 1024 bytes)
Showfiles() – A function that displays the names of all the Documents in Directory.
(c) Given the following class definitions answer the questions that follows : 4
class Book
{
char Title[20];
char Author[20];
int No_of_pages;
public:
void read();
void show();
};
class Textbook : private Book
{
int no_of_chapters, no_of_assignments;
protected:
int standard;
public:
void readtextbook();
void showtextbook();
};
class Physicsbook : public Textbook
{
char Topic[20];
public:
void readphysicsbook();
void showphysicsbook();
};
(i) Name the members, which can be accessed from the member functions of class Physics book.
(ii) Name the members, which can be accessed by an object of class Textbook.
(iii) Name the members, which can be accessed by an object of class Physicsbook.
(iv) What will be the size of an object (in bytes) of class Physicsbook ?
Ans. (a) (i) Constructor, it is invoked as soon as the object of the class active.
(ii) Destructor, it is invoked as soon as the scope of the object gets over.
(b) The class is :
#include <iostream.h>
#include <conio.h>

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


class Directory
{
char docunames[10][25];
long Freespace;
long Occupied;
public:
void Newdocuentry();
long Retfreespace();
void Showfiles();
};
void Directory::Newdocuentry()
{
cout << " Enter the names of the documents ";
for(int i=0;i<10;i++)
cin >> docunames[i];
cout << "Enter the freespace available ";
cin >> Freespace;
cout << "Enter the space occupied ";
cin >> Occupied;
}
long Directory::Retfreespace()
{
return (Freespace/1024);
}
void Directory :: Showfiles()
{
for(int i=0;i<10;i++)
cout << docunames[i] << endl;
}
void main()
{
Directory D;
D.Newdocuentry();
int x = D.Retfreespace();
cout << "Total Free Scpace is = "<<x;
D.Showfiles();
}
(c) (i) The data members are : Topic and standard.
The member functions are : readtextbook() and showtextbook().
(ii) The member functions are : readtextbook() and showtextbook().
(iii) The member functions are : readtextbook(), showtextbook(), readphysicsbook() and
showphysicsbook().
(iv) The size of an object of Physicsbook is 68 bytes.
3. (a) Define a function Reversearray(int [], int) that would accept a one dimensional integer array NUMBERS
and its size N. The function should reverse the contexts of the array without using any second array.
Note. Use the concept of swapping elements.
(Example : If the array initially contains
{2, 15, 3, 14, 7, 9, 19, 6, 1, 10},
then after reversal the array should contains
{10, 1, 6, 19, 9, 7, 14, 3, 15, 2}) 4
(b) An array ARR[5][5] is stored in the memory with each element occupying 4 bytes of space. Assuming
the base address of ARR to be 1000, compute the address of ARR[2][4], when the array is stored :
(i) Row Wise (ii) Column Wise 4

Examination Paper 5
(c) Write a function in C++ to find and display the sum of each row and each column of a 2 dimensional
array of type float. Use the array and its size as parameters with float as its return type. 2
(d) Evaluate the following Postfix notation of expression, show status of stack for each operations : 2
500, 20, 30, +, 10, *, +
(e) Define functions stackpush() to insert nodes and stackpop() to delete nodes, for a linked list
implemented stack having the following structure for each node : 3
struct node {
char name[20];
int age;
node *Link;
};
class stack {
node *top;
public:
stack() { top = NULL;};
void stackpush();
void stackpop();
};
Ans. (a) The function is :
void Reversearray(int NUMBER[10], int N) {
int temp;
int j = N–1;
for (int i=0; i<N/2; i++)
{
temp = NUMBER[i];
NUMBER[i] = NUMBER[j];
NUMBER[j] = temp;
j––;
}
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 of T = B = 1000,
No. of Rows = R = 5,
No. of Columns = C = 5,
Size of each element = W = 4,
And let the location of ARR[5][5] = L
(i) The given array ARR is stored as Row Major
Using the formula
L = B + W * [2 * C + 4]
= 1000 + 4 * [2 * 5 + 4]
= 1000 + 4 * [10 + 4]
= 1000 + 4 * 14
= 1000 + 56
= 1056
(ii) When the given array ARR is stored as Column Major
Using the formula
L = B + W * [2 + 4 * R]
= 1000 + 4 * [2 + 4 * 5]

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


= 1000 + 4 * [2 + 20]
= 1000 + 4 * 22
= 1000 + 88
= 1088
(c) The function is :
//Row and column sum
void row_col(float ARR[10][10], int r, int c)
{
int i, j, rsum = 0, csum = 0;
for (i = 0; i < r; i++)
{
rsum = 0;
for (j = 0; j < c; j++)
{
rsum = rsum + ARR[i][j];
}
cout << "\n\t sum of " <<(i+1)<< "row is " << rsum;
}
for (i = 0; i < c; i++)
{
csum = 0;
for (j = 0; j < r; j++)
{
csum = csum + ARR[j][i];
}
cout << "\n\t sum of " << (i+1) << "column is " << csum;
}
}
(d) The stack operation is :
Scanned Elements Operation Stack
500 PUSH 500 500
20 PUSH 20 500, 20
30 PUSH 30 500, 20, 30
+ POP 30
POP 20
Calculate 30 + 20 = 50
PUSH 50 500, 50
10 PUSH 10 500, 50, 10
* POP 10
POP 50
Calculate 50 * 10 = 500
PUSH 500 500, 500
+ POP 500
POP 500
Calculate 500 + 500 = 1000
PUSH 1000 1000 (Result of stack)
(e) // Function body for add stack elements
void stack::stackpush()
{
node *temp;

Examination Paper 7
temp = new node;
gets(temp->name);
cin >> temp->age;
temp->link = NULL;
if(top ==NULL)
top = temp;
else
{
temp->link = top;
top = temp;
}
}
// Function body for delete stack elements
void stack::stackpop()
{
node *temp;
clrscr();
if (top == NULL )
{
cout<<"Stack Empty ";
val = –1;
}
else
{
temp = top;
top = top->link;
temp->link = NULL;
delete temp;
}
}
4. (a) Assume that a text file named TEXT1.TXT already contains some text written into it, write a function
named vowelwords(), that reads the file TEXT1.TXT and create a new file named TEXT2.TXT, which
shall contain only those words from the file TEXT1.TXT which don’t start with an uppercase vowel
(i.e., with ‘A’, ‘E’, ‘I’, ‘O’, ‘U’). For example if the file TEXT1.TXT contains
Carry Umbrella and Overcoat When it Rains
then the file TEXT2.TXT shall contain
Carry When it Rains 3
(b) Assuming the class Vehicle as follows :
class vehicle
{
char vehicletype[10];
int no_of_wheels;
public:
void getdetails()
{
gets(vehicletype);
cin >> no_of_wheels;
}
void showdetails()
{
cout << "Vehicle Type" << vehicletype;
cout << "Number of wheels = " << no_of_wheels;
}
};

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


Write a function showfile() to read all the records present in an already existing binary file SPEED.DAT
and display them on the screen, also count the number of records present in the file. 2
Ans. (a) The function is :
void vowelwords() {
fstream afile,bfile;
char ch,ch1;
afile.open("TEXT1.TXT",ios::in);
bfile.open("TEXT2.TXT",ios::out);
ch1 = ' ';
clrscr();
while(afile) {
afile.get(ch);
cout << "\nOutside "<<ch;
if (( ch =='A') || (ch =='E') || (ch=='I')||(ch=='O')||(ch=='U')&&(ch1==' '‘)) {
while(ch!=' ') {
afile.get(ch);
ch1=ch;
if(ch==’ ‘)
break;
}
}
else
bfile.put(ch);
}
afile.close();
bfile.close();
}
(b) The function is :
void showfile() {
vehicle VH;
int reccount = 0;
fstream vfile;
vfile.open("SPEED.DAT", ios::in|ios::binary);
while (vfile)
{
vfile.read((char *)&VH, sizeof(VH));
reccount++;
VH.showdetails();
}
cout << "Total number of records are : " << reccount;
vfile.close();
}
5. (a) What do you understand by normalization ? What is Second Normal Form ? 2
Given the following tables for a database LIBRARY :
Table : Books
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
Book_Id Book_Bame Author_Name Publishers Price Type Quantity
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
C0001 Fast Cook Lata Kapoor EPB 355 Cookery 5
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
F0001 The Tears William Hopkins First Publ. 650 Fiction 20
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
T0001 My First C++ Brain & Brooke EPB 350 Text 10
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
T0002 C++ Brainworks A.W. Rossaine TDH 350 Text 15
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456
F0002 Thunderbolts Anna Roberts First Publ. 750 Fictioin 50
123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123456

Examination Paper 9
Table : Issued
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
Book_Id Quantity_Issued
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
T0001 4
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
C0001 5
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
12345678901234567890123456789012123
F0001 2
12345678901234567890123456789012123
Write SQL queries for (b) to (g) :
(b) To show Book name, Auther name and Price of books of First Publ. Publishers 1
(c) To list the names from books of Text type 1
(d) To display the names and price from books in ascending order of their price 1
(e) To increase the price of all books of EPB Publishers by 50 1
(f ) 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
“F0003”, 1
(h) Give the output of the following queries based on the above tables : 2
(i) SELECT COUNT(*) FROM Books
(ii) SELECT MAX(Price) FROM Books WHERE Quantity >= 15
(iii) SELECT Book_Name, Author_Name FROM Books WHERE Publishers = "EPB"
(iv) SELECT COUNT (DISTINCT Publishers) FROM Books WHERE Price >= 400
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 pose 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.
Second normal form : A table is said to be in 2NF if it is in first normal form and each non–key
attribute depends on the entire key.
(b) select book_name, author_name, price from books where publishers = 'First Publ.';
(c) select book_name from books where type = 'Text';
(d) select book_name, price from books order by price;
(e) update books
set price = price + 50
where publishers = 'EPB'’;
(f ) select a.book_id, a.book_name, b.quantity_issued from books a, issued b
where a.book_id = b.book_id;
(g) insert into issued values('F0003', 1)
(h) (i) 5
(ii) 750
(iii) First CookLata Kapoor
My First C++Brain & Brooke
(iv) 2
6. (a) State and prove the De Morgan’s Theorem (Any One) algebraically. 2
(b) Given the following truth table, derive a Sum of Product (SOP) and Product of Sum (POS) form of
Boolean expression from it. 2

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


X Y Z G(X,Y,Z)
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 0
1 0 1 1
1 1 0 0
1 1 1 1
(c) Obtain a simplified form for the following Boolean Expression using Karnaugh’s Map : 3
F(u, v, w, z) = Σ(0, 3, 4, 5, 7, 11, 13, 15)
(d) Draw the logic circuit for a Half Adder using NOR gates only. 2
(e) Interpret the following Logic Circuit as Boolean Expression : 1
W

X
F
Y
Z
Ans. (a) 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 + X =1 identity law]
= 1.
(b) SOP = X'Y'Z + X'YZ' + XY'Z + XYZ
POS = (X+Y+Z)(X+Y'+Z')(X'+Y+Z)(X'+Y'+Z)
(c) The K-Map is :
w'z' w'z wz wz'
u'v' 1 0 4 1 12 8

u'v 1 1
1 5
1 13
1 9

uv 3
1 7
1 15
1 11

uv' 2
1 6
1 14
1 10
Hence, F = u'w'z' + vw'z + wz.

Examination Paper 11
(d) Note. The concept deleted from revised syllabus 2005 onward examination.
(e) F = wx' + y'z
7. (a) Write two advantages and two disadvantages for STAR topology. 1
(b) Write one difference between Telnet and FTP. 1
(c) Explain the following terms in short : 2
(i) DHTML
(ii) ISP
(d) Define Packet Switching. 1
Ans. (a) 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
(b) Telnet. A terminal emulation protocol that allows user to log-on to a host computer from remote
computers using a Telnet program.
FTP. File Transfer Protocol (FTP) is the name of a special set of protocols used by computers
connected over the Internet to transfer files.
(c) (i) DHTML. “Dynamic HTML” is typically used to describe the combination of HTML, style
sheets and scripts that allows documents to be animated.
(ii) ISP. An ISP or Internet Access Provider is a company that provides the Internet access.
(d) 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.

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

Вам также может понравиться