You are on page 1of 219

Classification of Computer Sc. Q.

Paper as per the


Blue Print of CBSE

Unit -1 : Review of C++ Covered in Class XI Total Marks=12

1. Header files for different library functions.


2. Fundamental data type, conditional operator, logical operators, INR/DCR
operators, programs of switch, nested loops, series and arrays etc.
3. Function prototype, scope & life time, call by value & reference, actual &
formal parameters, Global & local variables...etc.
4. Error or Output related questions with the following topics:
a) looping with ++ or –
b) Array with/without function and calculations
c) Structure with/without function
d) Random function or switch
e) Pointer with structure/array

Unit -2 : OOPS Total Marks=12

1. Concepts/ Advantages of OOPS.


2. Creation of class with constructor.
3. Concept of Class/ Constructor/Destructor.
4. Inheritance multilevel/multiple practice the type of questions based on the
concept of inheritance& class.
5. Type of inheritance.

Unit -3 : Data Structure &Pointers Total Marks=14

1. 2-D Array address calculation row wise/column wise.


2. 1-Darray program based on rearrangement/ sorting/ merging/ searching etc.
3. 2-D array program based on row wise sum/ column wise sum/ transpose/
diagonal/ triangle matrices….etc.
4. Infix to postfix or postfix to infix using stack implementation method.
5. Insertion/deletion process of a dynamic Queue or Push/ Pop process of a
Dynamic Stack.
6. Array stack/ array queue insertion / deletion operations.

1
Unit -4 : Data File handling Total Marks=06

1. Fundamental of file handling. 1M


2. Function on text file: create/ search or count letters/words. 2M
3. Function on Binary File: Create/ Append/ Modify/ Search With or 3M
Without Display the record of File.

Unit -5 : Database & SQL Total Marks=8

1. Concept of database: Applications/ levels/ RDBMS/ Keys/ Terms used in 2M


DBMS/ Relational Algebra.
2. SQL Queries based on one or two table: display with order by/ group by/ 4M
aggregate functions/ conditions using and/or/between/like/in operators.
3. SQL data type/ aggregate functions/ output of sql commands/ DDL/DML.2M

Unit -6 : Boolean Algebra Total Marks=8

1. Boolean Laws. 2M
2. SOP and POS Form reduction. 1M
3. K-Map in SOP /POS. 3M
4. Circuit Design and Theory of Gates. 2M

Unit -7: Communication and Networking Total Marks=10

1. Network: Topology/ type of N/w, / advantage/terms/Cables. 2M


2. Internet Terms/ HTTP/FTP/WWW/HTML/DHTML/XML/Protocols. 2 M
3. N/W Security/ Virus. 2M
4. LAN Design. 3M
5. Open Source Terms. 1M

2
CONTENTS

SNo Title Page No.


1 Unit -1 : Review of C++ 1 - 22
2 Answers: Unit-1 23- 32
3 Unit -2 : OOPS 33 - 49
4 Answers: Unit-2 50 - 63
5 Unit -3 : Data Structure & Pointers 64 - 70
6 Answers: Unit-3 71 - 89
7 Unit -4: Data File Handling 90 - 97
8 Answers: Unit-4 98 - 105
9 Unit -5: Database & SQL 106 - 114
10 Answers: Unit-5 115 - 119
11 Unit -6: Boolean Algebra 120 - 124
12 Answers: Unit-6 125 - 130
13 Unit -7: Comm. & N/W 131 - 138
14 Answers: Unit-7 139 - 148
15 CBSE Exam. Papers with Answers 149 – 218

Unit -1: Review of C++ covered in Class XI


Total Marks=12
QNo. Questions
3
A. (Theoretical)

(1) Differentiate between a global variable and a local variable. Give example for the same.
(2) Explain the logical errors, runtime errors and syntax errors in programming? Also give suitable examples of
each in c++.
(3) Differentiate between the function call by value and call by reference methods.
(4) Explain the fundamental data types in c++?
(5) Define the typedef and #define with suitable example.
(6) Define the enumerated data type in c++ with an example?
(7) Differentiate between if and switch statement?
(8) Define the scope and life time of a variable?
(9) Declare a structure EMP having data members empcode, name, job, salary and address. The address must be in
a format of another structure called Addr having data members hno, streetname, city and state.
What is the difference between Actual Parameter and Formal Parameters?Also, give a suitable C++ code to
(10) illustrate both.
What is “this” pointer? Give an example to illustrate the use of it in C++.
(11) Define a macro with a suitable example.
(12) Write definition for a function SUMSequence() in C++ with two arguments – double x and int n. The function
(13) should return the sum (double type)of the following series :
1/x – 3! / x2 + 5! / x3 – 7! / x4 + 9! / x5 - …………………. Up to n terms.
(Note : The symbol ! represents Factorial of a number i.e. 5! = 5*4*3*2*1)
Differentiate between compiler and interpreter?
(14) What do you mean by a Class? Define its various sections.
(15) What is the difference between type casting and automatic type conversion? Explain with suitable example?
(16) If a main() is defined with int type as follows:
int main()
(17) { ………
return 0; }
Explain that the main function returns value 0 to whom?
B. Header File Naming

(1) Write name of the header file for the following function:
exit(), rand(), seekg(), getch(), setw ( ), isdigit ( ), strcpy ( ), gotoxy ( ), abs( ), strlen( ), pow( ), isupper(),
gets(), fabs(), isalnum(), random(), strcmpi(), frexp(), toascii(), rename(), remove(), open()
(2) Name the Header file(s) that shall be needed for successful compilation of the following C++ code?
(a) void main()
{
char st[20];
gets(st);
if(isaplha(st[0])
cout<<”Starts with alphabet”;
else
cout<<strlen(st);
}
(b) void main()
{
int a[10];
for(int i=0;i<10;i++)
{
cin>>a[i];
if(a[i]%2==0)
a[i]=pow(a[i],3);
else
a[i]=sqrt(a[i]);
if(a[i]>32767)
exit(0);
}

4
getch();
}
(c) void main( )
{
char Text[40];
strcpy(Text,”AISSCE”);
puts(Text);
cout<<”\n”;
getch();
}
(d) Name the header file(s) required in the following program.
struct ST
{ int code[10];
};
void main()
{ ST s1;
int rn;
randomize();
rn=random(10);
for(int i=0; i<=rn;i++)
{ s1.code[i]=i;
cout<<s1.code[i]<<” , ”;
}
}
C. Write the possible output for the following program/code: (Ignore the Header file declaration )
(1) Structure Problems:
(a) struct item
{char name[30];
float price; };
void show(item p)
{ cout<<p.name<<";"<<p.price<<endl; }
void main()
{ clrscr();
item t1[3]={"Mouse",450.00,"Printer", 7500.00, "Hard Disk",2175.75};
item t2={"Processor",12000.00};
item t3;
for(int i=0;i<3;i++)
{ if(t1[i].price>t2.price)
t3=t1[i];
else
t3=t2;
}
show(t3);
getch();
}
(b) struct point
{ int x, y; };
void show(point p)
{ cout << p.x << ”;” << p.y << endl; }
void main()
{ point pp={10,20}, v, w;
v=pp;
v.x=v.y++ +10;
v.y=v.x*2;
w=v;
w.x++;
w.y=v.y+10;

5
show(v);
show(w);
}
(c) struct xlist
{ int p, q, r; };
void main()
{ xlist adata={15,20,25};
xlist pdata={2,4,6};
int s=0;
for(int i=pdata.p ;i<=pdata.r ; i++)
{
cout<<adata.p*i<<”\t”;
s+=adata.p*i;
}
cout<<”sum= ”<<s;
}
(d) struct AREA
{ int len, breadth, height; };
void Dimension (AREA m)
{ cout<<m.len<<”x”<<m.breadth<<”x”<<m.height<<endl; }
void main()
{ AREA b1={10,15,5}, b2, b3;
++b1.height;
Dimension(b1);
b2=b1;
b2.len++;
b3=b2;
b3.breadth++;
Dimension(b3);
b2.height+=10;
b2.breadth--;
Dimension(b2);
}
(e) struct play
{ int code;
char playname[25];
int noofplayer;
} p[5] = {1, ”cricket”, 11, 2, ”hockey”, 11, 3, ”football”, 11,
4, ”basketball”, 7, 5, ”boxing”, 1};
void main()
{
cout<<"PLAY CODE\t PLAY NAME \t NO. OF PLAYER\n";
for(int i=1; i<4; i++)
cout<< p[i].code << "\t" << p[i].playname<<"\t"<<p[i].noofplayer<<"\n";
}
(f) struct text
{ char vow[6];
char cons[22];
};
void main()
{ text t1={“aeiou”, “bcdfgh” };
for(int i=0; t1.vow[i]!='\0'; i++)
cout<<char(toupper(t1.vow[i]))<<"\t";
cout<<”\n”;
for(int j=0 ; t1.cons[j] !='\0' ; j++)
cout<<char(tolower(t1.cons[j]))<<"\t";
}

6
(g) struct share
{ long qty, value; };
void increase (share s[], int total, int ns=5)
{
for(int c=0 ; c<total ; c++)
{ s[c].value += ns; }
}
void main()
{ share s[2]={ {50,10},{20,30}};
increase(s,2);
for(int i=0 ; i<2 ; i++)
cout<< "Amount=" << s[i].qty * s[i].value <<” , “;
increase(s, 2, 10);
for(i=0; i<2 ; i++)
cout<<"Amount=" << s[i].qty * s[i].value <<endl;
cout<<"share Values: "<< s[0].value <<" and "<< s[1].value <<endl;
}
(h) struct list
{ int a,b;
};
void main()
{
list s[3]={{12,14},{2,3},{4,5}};
for(int i=0;i<3;i++)
cout<<s[i].a+s[i].b<<"\t";
}
(i) struct student
{ char name[20];
int age;
int roll;
};
void main( )
{ student stud={“Neelam”, 17, 12};
student stud1;
stud1=stud;
stud1.roll=8;
cout<<”\nName:”<<stud1.name;
cout<<”\nRollno:”<<stud1.roll;
cout<<”\nAge:”<<stud1.age;
}
(j) struct Student
{ int rno;
char name[20];
};
void main()
{ student a[2]={{1,”Amit”},{2,”Sumit”}};
for(int i=0 ; i<2 ; i++)
{cout<<”\n Rno :”<<a[i].rno;
cout<<”\n Name : “;
for(int j=0 ; j<strlen(a[i].name) ; j++)
if(islower(a[i].name[j]))
cout<< (char)toupper(a[i].name[j]) << ” “ ;
else
cout<< (char)tolower(a[i].name[j]) << ” “ ;
}
}
(k) struct Game

7
{ char Magic[20];
int Score;
};
void main()
{ Game M={"Tiger", 500};
char *Choice;
Choice = M.Magic;
Choice[4] = 'P';
Choice[2] = 'L';
M.Score += 50;
cout<< M.Magic <<”\t”<< M.Score << endl;
Game N = M;
N.Magic[0] = 'A' ;
N.Magic[3] = 'J';
N.Score - = 120;
cout<<N.Magic<<”\t”<<N.Score<<endl;
}
(l) #include <iostream.h>
void Secret(char Str[ ])
{ for (int L=0 ; Str[L] != '\0' ; L++)
for (int C=0 ; C<L/2 ; C++)
if (Str[C]= ='A' | | Str[C]= ='E')
Str[C] = '#' ;
else
{
char Temp=Str[C];
Str[C]=Str[L-C-1];
Str[L-C-1]=Temp;
}
}
void main()
{ char Message[ ]="ArabSagar";
Secret(Message);
cout<<Message<<endl;
}
(2) Functions, Pointer & Array Problems:
(a) #define M(r) r*r
#define L(p) p*p*p
void main()
{
int a=3, b=0, c=0;
b= a + M(a);
c= a + b + L(a);
cout<< b<< ”\t”<< c<< ”\n”;
}
(b) void Indirect(int Temp=20)
{ for (int I=10; I<=Temp; I+=5)
cout<<I<<” , “ ;
cout<<endl;
}
void Direct (int &Num)
{ Num +=10;
Indirect(Num);
}
void main()
{ int Number =20;
Direct(Number) ;

8
Indirect();
cout<< “ Number=” <<Number<<endl ;
}
(c) int a=10;
void main()
{ void demo(int &, int, int*);
int a=20, b=5;
demo(::a, a, &b);
cout<<::a<<” “ <<a<<” “ <<b<<endl;
}
void demo(int &x, int y, int *z)
{ a += x;
y *= a;
*z = a + y;
cout<<x<<” “ <<y<<” “ <<*z<<endl;
}
(d) void change (int *);
void main()
{ int a[5] = {4, 5, 6, 7, 8};
change (a);
for(int i =4 ; i>=0 ; i--)
cout<<a[i]<<"\t";
cout<<"\n";
}
void change(int *b)
{
for(int i=0 ; i<=4 ; i++)
{ *b = *b+1;
b++;
}
}
(e) void Modify(int &a, int b=10)
{ if( b%10 = = 0)
a +=5;
for(int i=5 ; i<=a ; i++)
cout<<b++<<” : “;
cout<<endl;
}
void Disp(int x)
{ if(x%3 = = 0)
Modify(x);
else
Modify(x, 3);
}
void main()
{
Disp(3);
Disp(4);
Modify(2,20);
}
(f) void main()
{
int Numbers[] = {2, 4, 8, 10};
int *ptr = Numbers;
for (int C = 0; C<=3; C++)
{
cout<< *ptr << “@”;

9
ptr++;
}
cout<<endl;
ptr=Numbers;

for(C = 0; C<4; C++)


{
(*ptr) *= 2;
++ptr;
}
for(C = 0; C<4; C++)
cout<< Numbers [C]<< “#”;
cout<<endl;
}
(g) void main()
{
int *p, a[5]={23, 24, 25, 26, 27};
for(p=a, int i=0 ; i<5 ; i++, p++)
{
if(*p%2 = = 0)
cout<<*p<<”\t”;
}
}
(h) #include <iostream.h>
void Changethecontent(int Arr[ ], int Count)
{
for (int C=1;C<Count;C++)
Arr[C-1] + = Arr[C];
}
void main()
{int A[]={3, 4, 5}, B[] = {10, 20, 30, 40}, C[] = {900, 1200};
Changethecontent(A, 3);
Changethecontent(B, 4);
Changethecontent(C, 2);
for (int L=0; L<3; L++)
cout<<A[L]<<'#';
cout<<endl;
for (L=0 ; L<4 ; L++)
cout<<B[L] <<'#';
cout<<endl;
for (L=0 ; L<2 ; L++)
cout<<C[L] <<'#';
}
(i) class student
{ char *name;
int i ;
public:
student( )
{ i =0 ; name = new char [i+1];
}
student (char *s)
{ i =strlen(s); name=new char[i+1];
strcpy (name , s);
}
void display( )
{cout<<name<<endl;}

10
void manipulate(student & a, student & b)
{ i = a.i + b.i;
delete name;
name=new char[i+1];
strcpy(name, a.name);
strcat(name, b.name);
}
};
void main( )
{ char * temp = “Jack”;
student name1 (temp), name2(” Jill”), name3(”John”),S1,S2;
S1 .manipulate (name1, name2);
S2.manipulate (SI, name3);
S1.display ( );
S2.display ( );
}
(j) char *s=”GOODLUCK”;
for(int x = strlen(s)-1 ; x>=0 ; x--)
{
for(int y=0 ; y<=x ; y++)
cout<<s[y];
cout<<endl;
}
(k) void main()
{ char *NAME = "ComPUteR";
for(int x=0; x<strlen(NAME); x++)
{ if(islower(NAME[x])
NAME[x]=toupper(NAME[x]);
else
{ if(x%2= =0)
NAME[x]=tolower(NAME[x]));
else
NAME[x]=NAME[x-1];
}
}
puts(NAME);
}
(l) 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[]=”Mouse Fun”;
changestring (message, position);
cout<<message<<” @ “<<position;
}
(m) int funs (int &x, int y=10)
{ if (x%y == 10)
return ++x;
else
return y-- ;
}
void main( )

11
{ int p=20, q=23;
q = funs(p, q);
cout <<p<<”;”<<q<< endl;
q = funs(p);
cout <<p<<”;”<<q<<endl;
}
(n) Find the output of the following program :
# include < iostream.h>
void Withdef (int HisNum = 30)
{ for (int I=20 ; I<= HisNum; I+=5)
cout<<I<<” ”;
cout<<endl;
}
void Control (int & MyNum)
{ MyNum += 10;
Withdef(MyNum);
}
void main ()
{ int YourNum = 20;
Control (YourNum);
Withdef();
cout<<”Number=”<<YourNum<<endl;
}

(3) Looping, Library Functions, Strings etc.


(a) for (int sum=0,int i=5; i<=25; i+=5)
{
cout<<i<<”\t”;
sum+=i;
}
cout<<”\nsum=”<<sum;
(b) void main()
{ long Number = 7583241;
int First=0, Second=0;
do
{ int R=Number%10;
if (R%2==0)
First+=R;
else
Second+=R;
Number /=10;
} while (Number>0);
cout<<First <<”\t “<<Second;
}
(c)Choose the possible output from the following:
void main()
{ int r;
randomize();
r=random(20)+random(2);
cout<<r;
}
(i) 25 (ii) no output (iii) 15 (iv) Error

(d) Choose the possible output from the following, if 5 is entered in N:


void main( )
{ int N, Guessme;
randomize( );

12
cin>>N;
Guessme=random(N)+10;
cout<<Guessme<<endl;
}
(i) 5 (ii) 12 (iii) both (iv) none
(e) void main( )
{ char Mes1[ ]=”HuB”, Mes2[ ]=”ThaT”, Mes3[ ]=”BeSt”;
int L1=strlen(Mes1), L2=strlen(Mes2), L3=strlen(Mes3);
int N=L1+L2+L3;

for(int c=0; c<N; c++)


{ if(c%4==0)
{ cout<<Mes2[L2-1];
L2--;
}
else if(c%3==0)
{ cout<<Mes1[L1-1];
L1--;
}
else
{
cout<<Mes3[L3-1];
L3--;
}
}// end of loop
}
(f) void main()
{
char * NAME = “AdmiNiStrAtiOn”;
for( int x=0; x<strlen(NAME); x++)
if(islower(NAME[x]))
NAME[x] = toupper(NAME[x]);
else
if(isupper (NAME[x]))
if(x%2==0)
NAME[x] = NAME[x +1];
else
NAME[x] - - ;
cout<<NAME <<endl;
}
(g) Choose the possible output from the following:
void main( )
{
randomize();
int Score[ ] = {25,20,34,56, 72, 63}, Myscore;
Myscore = Score[2] + random(2);
cout<<Myscore<<endl;
}
(i) 56 (ii) 34 (iii) 40 (iv) None of the above
(h) In the following program, if the value of Guess entered by the user is 65, which is not an expected
output(s) from the following options (i), (ii), (iii) and (iv)?
#include <iostream.h>
#include <stdlib.h>
void main()
{ int Guess, New;
randomize();
cin>>Guess;

13
for (int I=1;I<=4;I++)
{
New=Guess+random(I);
cout<<(char)New;
}
}
(i) ABBC (ii) ACBA (iii) BCDA (iv) CABD
(i) In the following program, if the value of N given by the user is 20, whatmaximum and
minimum values the program could possibly display?
#include <iostream.h>
#include <stdlib.h>
void main()
{
int N,Guessnum;
randomize();
cin>>N;
Guessnum=random(N-10)+10;
cout<<Guessnum<<endl;
}
(j) In the following C++ program, fill in the blanks for the statement1 with the help of random function, if the
number generated by the random number is supposed to be between the range of 20-2000.
void main()
{ int r;
randomize();
r=___________________//statement 1
cout<<r;
}
(k) int x=12;
void main()
{
int x=10;
cout<<x<<endl;
{
int x=20;
cout<<::x<<endl;
}
x=30;
cout<<::x<<x<<endl;
}
(4) Class Objects and Constructors etc.
(a) class xlist
{ int p, q, r;
public:
xlist (int a, int b, int c=10)
{ p=a;
q=b;
r=c; }
void display()
{
cout<<” P= “<<p<<” Q= “<<q<<” R = “<<r<<”\n”;
}
};

void main()
{ xlist adata{15, 20, 25};
xlist pdata{20, 40};
adata.display();

14
pdata.display();
}
(b) class state
{ private:
char *stname;
int size;
public:
state( )
{ size=0;
stname=new char[size+1];
}
state(char *s)
{ size = strlen(s);
stname = new char[size+1];
strcpy(stname, s);
}
void disp( )
{ cout<<stname<<endl;
}
void repl(state &a, state &b)
{ size = a.size + b.size;
delete stname;
stname=new char[size+1];
strcpy(stname, a.stname);
strcat(stname, b.stname);
}
};
void main( )
{ char *st1="Punjab";
clrscr( );
state ob1(st1), ob2("Uttaranchal"), ob3("Madhyapradesh"), s1, s2;
s1.repl(ob1,ob2);
s2.repl(s1,ob3);
s1.disp( );
s2.disp( );
}
(c) class A
{ public:
A()
{ cout<<”CONSTRUCTOR A \n”; }
~A()
{ cout<<”DESTRUCTOR A \n”; }
};
class B
{ public:
B()
{ cout<<”CONSTRUCTOR B \n”; }
~B()
{ cout<<”DESTRUCTOR B \n”; }
};
void main()
{ B OB1;
A OA1; }
(d) class MAIN
{ public:
MAIN()
{ x();

15
cout<<"CONSTRUCTOR ";
}
void x()
{ cout<<"HELLO "; }
~ MAIN()
{ cout<<"\nHELLO DESTRUCTOR\n"; }
};
void main()
{ MAIN one;
}
(e) class base1
{ protected:
int a;
public:
base1 (int x)
{a=x;
cout<<"Constructing Base 1 \n";
}
~base1()
{ cout<<" Destructing Base1 \n";
}
};
class base2
{ protected:
int b;
public:
base2 (int y)
{ b=y;
cout<<"Constructing Base 2\n";
};
~base2()
{ cout<<" Destructing Base 2\n";
}
};
class derived : public base2, public base1
{ int c;
public:
derived(int i, int j, int k ) : base2 (i), base1 (j)
{ c=k;
cout <<"Constructing Derived\n";
}
~derived()
{ cout<<"Destructing Derived\n";
}
void show()
{ cout<<"1. "<<a<<"\t2. "<<b<<"\t 3. "<<c<<"\n"; }
};
int main()
{ clrscr();
derived ob(14,15,16);
ob.show();
return 0;
}
(f) class play
{ int code;
char playname[25];
public:

16
void getname()
{ code=101; strcpy (playname, “CRICKET”);
}
void display()
{ cout<<"PLAY CODE:"<<code <<"\t PLAY NAME : "<<playname;
}
};
class player : public play
{ int n;
public:
void getname()
{ play :: getname();
n=11;
}
void display()
{ play :: display();
cout<<"\n NO. OF PLAYERS: "<<n;
}
};
void main()
{ player p;
p.getname();
p.display();
}
(g) class student
{ public:
student()
{ cout<<”\n Computer Science“;
}
~student()
{ cout<<” Subject”;
}
}st;
void main()
{ cout<<” is my best“;
}

D. Rewrite the following program after removing syntactical error(s). Make underline in each
correction(s).
(1) (a) #include<iostream.h>
type def int integer;
struct number

17
{ integer a [5];
}
void main();
{ number x
for(int i=0;i<5;i++)
cin>>x[i].a;
for(int j=0; j<5, j++)
cout>>a[i]>>”\t”;
getch();
}
(b) #include<iostream.h>
#include<conio.h>
struct EMP
{ int code;
char *name;
float sal=0.0;
};
EMP E1={101, ‘ABHIJEET KUMAR’ , 7500.50};
VOID MAIN()
{ EMP e2;
clrscr();
if ( strcmp (E1.name, “ABHIJEET”) = =0 )
cout<<E1.name;
else
E1.name=”ABHIJEET”;
cout<<E1.name;
getch():
}
(c) #include <iostream.h>
void main( )
{ struct movie
{ char movie_name [20];
char movie type;
int ticket cost = 100;
}MOVIE;
gets(movie_name);
gets(movie_type);
}
(d) #include<iostream.h>
struct alpha
{ int x;
char p;
}
void main()
{
alpha s1={12,”r”};
s2=s1;
cout<<”number is= “<<s2.x<<”, character is =”<<p;
}
(e) void main()
{ INT a=5;
const int b=7;
large(a,b);
}
void large(int x, int & y)
{ if(x>=y)
x--;

18
else
y--;
cout<<x<<”;” <<y<<endl;
}
(f) #include<iostream.h>
#define SIZE =10
VOID MAIN()
{ int a[SIZE]={10, 20, 30, 40, 50};
float x=2;
SIZE=5;
for(int i=0 ; i<SIZE ; i++)
cout<<a[i]%x;
}
(g) include<iostream.h>
void main()
{ int p[ ]={12. 13. 14. 15}; q, number=4;
q=5;
for [ int i = number+1; i>=0;i--]
switch(i)
{
case 0:
case 1:
case 2:
case 3: cout>>p[i]*q;
break;
case 4:
case 5: cout>>p[i]+q;
break;
}
}
(h) #include<iostream.h>
class game
{ int points=900,track;
public
game() { track=10; }
void initial (int p, int t)
{ points+=p;
track+=t;
}
void trackchange()
{ points++,track++;
}
void status()
{ cout<<points<<"@"<<track<<endline;
}
};
void main()
{g.game;
g.initial(10,5);
g.trackchange;
g.status();
}
(i) #include<iostrem.h>
void main( )
{ First = 10, Second = 20;
Jumpto(First;Second);
Jumpto(Second);

19
}
void Jumpto(int N1, int N2 = 20)
{ N1=N1+N2;
count<<N1>>N2;
}
(j) #include <iostream.h>
const int Size 5;
void main()
{ int Array[Size];
Array = {50, 40, 30, 20, 10};
for(Ctr=0 ; Ctr<Size ; Ctr++)
cout>>Array[Ctr];
}
(2) Class & OOPs etc
(a) #include<iostream.h>
#include<conio.h>
class INT
{ int x;
public:
getINT (int a){ x=a; }
void putdata();
{ cout<<a; }
void main()
{ INT obj1;
obj1.getINT(25);
obj1.putdata(75);
getch();
}
(b) #include<iostream.h>
class test
{ int i;
float j;
public:
void test (void )
{ i=0; j=0.0; }
init( )
{ cin>>i>>j; }
display( )
{ cout<<"\ni="<<i;
cout<<”\n j= “<<j; }
};
void test(int a, float b)
{ i=a;
j=b; }
};
void main()
{ test t1;
test t2(10,12.5);
display(t1, t2);
}

(c) #include<iostream.h>
class INT
{ int x;
public:
void INT()

20
{ x=5; }
void INT(int a)
{ x=a; }
void putdata();
{ cout<<a;
}
void main()
{ INT obj1;
INT obj2(25);
INT obj3(55);
obj1.putdata(75);
obj2.putdata();
obj3.putdata();
}
(d) #include<iostream.h>
class maine
{ int x;
float y;
protected;
long x1;
public;
maine()
{ };
maine(int s, t=2.5)
{ x=s;
y=t; }
getdata()
{ cin>>x>>y>>x1;
}
displaydata()
{ cout<<x<<y<<x1;
}
};
void main()
{ clrscr();
maine m1(20,2.4);
maine m2(1,1.5,234);
maine m3(10);
maine m4;
}
(e) #include [iostream.h]
class MEMBER
{ int Mno;float Fees;
PUBLIC:
void Register(){cin>>Mno>>Fees;}
void Display{cout<<Mno<<" : "<<Fees<<endl;}
};
void main()
{ MEMBER M;
Register();
M.Display();
}
(f) class base { public: int x; };
class d1 : public base { public: int y; };
class d2 : public base { public: int z; };
class d3 : public d1, public d2
{ public: int total; };

21
void main()
{d3 ob;
ob.x =25;
ob.y =50;
ob.z =75;
ob.total = ob.x + ob.y + ob.z;
cout <<ob.x<<"\t"<<ob.y<<"\t"<<ob.z<<"\tTotal: "<<ob.total;
}

E. Q.1 Fill in the blanks:


(1) ______________constructor should be called before the derived class constructor.
(2) In copy constructor the argument is ___________and passed only by __________.
(3) A structure can be defined by keyword __________.
(4) A class may have _______and________as members.
(5) Functions defined inside the class are automatically___________.
(6) ________________ members of base class are not inheritable.
(7) _______________ inheritance form may have multiple bases.
(8) Public members of base are become _____________in derived class in protected visibility
mode.
(9) Public members of base are become _____________in derived class in public visibility
mode.
(10) Protected members of base are become _____________in derived class in public visibility
mode.
(11) Constructors will be invoked when_______________.
(12) ______________members of class could be accessible by objects.
(13) The destructor will be invoked when _______________.
(14) __________________concepts of OOPs are shown by a class.
(15) An object includes _______________ data members of class in its memory space.
(16) ___________ function is used to find error when an input or output operation has failed
during file handling.
(17) _______________ this mode is used to append the data in a file.
(18) ________________ is used to tell the position of get pointer in a file.
(19) ____________ function should be used to set the position of put pointer in a file.
(20) write() function in file handling is associated to __________stream.

Answers:Review of C++ (Unit -1)


Total Marks=12
QNo. Answers

22
A. (Theoretical)
(1) A Global Variable is a variable that is accessible every where in program. All functions of
program can share or use this. A local variable is defined inside a local body or a function. It can
be used within that area only.
int a; // Global variable
void main()
{ int m; // Local Variable
……}
(2) The logical errors are occurred, when a wrong logic or calculation was implied by user, this type
of error could not detect by compiler. Runtime error occurs during the execution of program,
this may stop the program execution. These are harder to detect. Syntax error occurs when user
type the instruction or statement, which violet the c++ grammar rules.
Examples:
X = Y + Z : //syntax error, semicolon is required at end
X = Y / Z; // Give run time error, when Z becomes zero. It gives infinite value
if(a>5000) // if a is required to test less than 5000, then it is a logical error,
// because > G.T. sign is applied in the condition.
(3) When a function is called with arguments and only the values of actual arguments are being
passed to formal arguments and there is no link between actual and formal arguments, is called,
call by value method. In call by reference method only the memory reference of actual
arguments is being passed to formal arguments. The actual and formal arguments are linked
together in this method, means if any changes made in formal argument, will also make the
changes in actual argument.
(4) The fundamental data types in c++ are classified as follows:
(i) Integer Data Type: Numeric data without fractions. It is divided into following types:
short integer: short ( Note: these three are also in signed and unsigned group)
integer: int
long integer: long
(ii) Floating Point Data Type: Numeric data with fractions. It is divided into following types:
float, double, long double
(iii) Character Data Type: Characters single or string, it is of two types:
unsigned char or char
(iv) void: empty data set, used to define empty argument list or a function which does not have
any return type
(5) typedef is a user defined data type, which is used to declare a variable as a data type definer and
it can be used to declare the other same data type variables. For i.e.
typedef int Integer;
Integer m; // m is act as a int variable
#define is used to define the symbolic constants in the program. It also used to define the macro
function. For i.e. #define PI 3.1425347 // PI is treated as constant
#define F(a) a*a*a // this is a macro which replace the call F(2) by 2*2*2 in the program
(6) The enumerated data type is used to declare integer constants and it is more convenient than
const because it define more than one constants for a data. For e.g.
enum { start, pause, go }; // this is a list of enum int constants they are having
//automatic enumerated values started from 0, 1…
//start =0, pause=1 and go = 2.
We can assign any constant number to any enum list members. i. e. enum list(s=4, p, g);
(7) if statement switch statement
a. It can evaluate any relational or logical condition. a. It can test only equality relation
b. A series of expressions we have to give under the b. All statements separated in different cases.
satisfying condition. c. This has limited uses, i.e. in menu driven
c. It is more versatile. It can be applied to any type of prog. only
conditions. d. It supports only int and single char, while
d. It can handle floating point tests. comparing equality test.
(8) Scope is the range or area of applicability of a variable, in which it can work.
Life time of a variable means the time duration in which its value remain live in the memory.
(9) struct Addr
{ int hno;

23
char streetname[20], city[25], state[25];
};
struct EMP
{ int empcode;
char name[25], job[20];
Addr address;
float salary;
};
(10) The Actual Parameter are the data members of calling function which are likely to transfer into
called function and Formal Parameters are the members of called function which are used to
receive the values/ references of actual parameters of calling function.
void main() //calling function
{ int a;
cin>>a;
void fun(int );
func(a); // passing a to fun, here a is actual parameter
…….
}
void fun(int b) // called function, b is formal parameter
{
………}
(11) When a member function is called by an object, it is automatically passed an implicit argument
that is a pointer to the object, which link to the object involved in this call. This pointer is called
“this pointer”. For e.g
class emp
{ int no;
char name[25];
public:
void prnobj()
{ cout<<this->name<<”; “<<this->no; // name print of the object who calls this function
}
………
};
It require sometime to compare with other object’s data in a function.
(12) #define F(a) a*a*a // in this example every call of F(a) replace a*a*a into the main
void main()
{ int a=3;
a= F(a);
cout<<a; // it print 27 in output
}
(13) double SUMSEQUENCE(double X, int N)
{ int I, Sign=1, F=1;
double Sum=0
for(I =1, J = 1 ; I <= N ; I+=2, J++ )
{ for(int m=I; m>=1; m--)
F = F *m;
Sum + = (F / (pow(X, J)) ) * Sign;
Sign =Sign * -1;
}
return (Sum);
}

(14) Compiler Interpreter

24
• It read full programand covert into • It convert line by line of program
Object Code (m/c) • Easy to debug
• Difficult to debug • It does not do optimization
• It gives code optimization. • Faster in smaller programs
(15)
• Faster to convert large programs

A Class is a template representing a group of objects that share common properties and
behavior. Class binds common data and their related behaviors (functions) into a closed unit,
which can be accessed by their objects only not to any others. A class has three sections: private,
protected and public. Private and protected members have class scope, whereas the public
(16)
section member can be accessed outside the class, but only by objects of itself. A class has 2
types of members, data member and member functions.
Type casting means changing the data type of an expression/ variable into another data type by
using (type) operator and automatic type conversion means, the conversion process is done by
compiler itself. For example:
(17)
A= (float) b/c; // expression will converted into float type then store in A in float.
int m=4.5; // m stores only 4, this is automatic casting
main() return the 0 number to Operating System and this is used to test whether the program has
been successfully executed or not.
B. Header File Naming
(1) exit():- process.h/stdlib.h, rand():- stdlib.h, seekg():-fstream.h,
getch():- conio.h, setw():- iomanip.h, isdigit():- ctype.h,
strcpy():- string.h, gotoxy():- conio.h, abs():- math.h,
strlen():- string.h, pow():- math.h, isupper():- ctype.h,
gets():- stdio.h, fabs():- math.h, isalnum():- ctype.h,
random():- stdlib.h, strcmpi():- string.h, frexp():- math.h,
toascii():- ctype.h, rename():- stdio.h, remove():- stdio.h,
open():- fstream.h
(2) (a) iostream.h, ctype.h, string.h, stdio.h
(b) iostream.h, math.h, conio.h, stdlib.h
(c) iostream.h, stdio.h, conio.h, string.h
(d) iostream.h, stdlib.h

C. Structure Problems output:


(1) (a) Processor; 12000
(b) 30 ; 60
31 ; 70
(c) 30 45 60 75 90 sum = 300
(d) 10 x 15 x 6
11 x 16 x 6
11 x 14 x 16
(e) PLAY CODE PLAY NAME NO. OF PLAYER
2 hockey 11
3 football 11
4 basketball 7
(f) A E I O U
b c d f g h
(g) Amount = 750, Amount = 700, Amount = 1250, Amount = 900
Share Values : 25 and 45
(h) 26 5 9
(i) Name : Neelam
Roll : 8
Age : 17
(j) Rno : 1
Name : a M I T
Rno : 2
Name : s U M I T
25
(k) TiLeP 550
AiLJP 430
(l) aab#raSgr
(2) Functions, Pointer & Array Problems:
(a) 12 42
(b) 10, 15, 20, 25, 30
10, 15, 20
Number = 30
(c) 20 400 420
20 20 420
(d) 9 8 7 6 5
(e) 10 : 11 : 12 : 13 :
20 : 21 : 22 :
(f) 2 @ 4 @ 8 @ 10 @
4 # 8 # 16 # 20 #
(g) 24 26
(h) 7 # 9 # 5#
30 # 50 # 70 # 40#
2100 # 1200#
(i) Jack Jill
Jack JillJohn
(j) GOODLUCK
GOODLUC
GOODLU
GOODL
GOOD
GOO
GO
G
(k) coMMuTEE
(l) MouSe Fun @ 8
(m) 20 ; 23
20 ; 10
(n) 20 25 30
20 25 30
Number = 30
(3) Answers: Looping, Library Functions, Strings etc.
(a) 5 10 15 20 25
Sum = 75
(b) 14 16
(c) (iii) 15
(d) (ii) 12
(e) TtSBaeuBhH
(f) dDMIiItTR@TTnN
(g) (ii)34
(h) (iv) CABD
(i) Max: 20 and Min : 10
(j) void main()
{ int r;
randomize();
r= random(2000-20+1) + 20 //statement 1
cout<<r;
}
(k) 10
10 12
12 30
(4) Class Objects and Constructors etc.

26
(a) P = 15 Q = 20 R = 25
P = 20 Q = 40 R = 10
(b) PunjabUttaranchal
PunjabUttaranchalMadhyapradesh
(c) CONSTRUCTOR B
CONSTRUCTOR A
DESTRUCTOR A
DESTRUCTOR B
(d) HELLO CONSTRUCTOR
HELLO DESTRUCTOR
(e) Constructing Base 2
Constructing Base 1
Constructing Derived
1. 15 2. 14 3. 16
Destructing Derived
Destructing Base1
Destructing Base 2
(f) PLAY CODE:101 PLAY NAME : CRICKET
NO. OF PLAYERS: 11
(g) Computer Scienceis my best Subject

D. Rewrite the following program after removing syntactical error(s). Make underline in each

27
correction(s).
(1) (a) #include<iostream.h>
#include<conio.h>
typedef int integer; //space
struct number
{ integer a [5];
};
void main()
{ number x;
for(int i=0;i<5;i++)
cin>>x.a[i];
for(int j=0; j<5, j++)
cout<<x.a[i] <<”\t”;
getch();
}
(b) #include<iostream.h>
#include<conio.h>
#include<string.h>
struct EMP
{ int code;
char *name;
float sal;
};
EMP E1={101, ”ABHIJEET KUMAR” , 7500.50};
void main()
{ //EMP e2; // not require
clrscr();
if ( strcmp (E1.name, “ABHIJEET”) = =0 )
cout<<E1.name;
else
E1.name=”ABHIJEET”;
cout<<E1.name;
getch();
}
(c) #include <iostream.h>
#include<stdio.h>
void main( )
{ struct movie
{ char movie_name [20];
char movie type;
int ticket_cost;
}MOVIE;
gets(MOVIE.movie_name);
gets(MOVIE.movie_type);
}
(d) #include<iostream.h>
struct alpha
{ int x;
char p;
};
void main()
{alpha s1={12,’r’}, s2;
s2=s1;
cout<<”number is= “<<s2.x<<”, character is =”<<s2.p;
}

(e) #include<iostream.h>

28
void large( int , int &);
void main()
{ int a=5;
int b=7;
large(a,b);
}
void large(int x, int & y)
{ if(x>=y)
x--;
else
y--;
cout<<x<<”;” <<y<<endl;
}
(f) #include<iostream.h>
#define SIZE 10
void main()
{ int a[SIZE]={10, 20, 30, 40, 50};
int x=2;
//SIZE=5;
for(int i=0 ; i<SIZE ; i++)
cout<<a[i]%x;
}
(g) include<iostream.h>
void main()
{ int p[]={12, 13, 14, 15} , q, number=4;
q=5;
for ( int i = number+1 ; i>=0 ; i--)
switch(i)
{case 0:
case 1:
case 2:
case 3: cout<<p[i]*q; break;
case 4:
case 5: cout<<p[i]+q; break;
}
}
(h) #include<iostream.h>
class game
{ int points, track;
public:
game() { track=10; points = 900;}
void initial (int p, int t)
{ points+=p;
track+=t;
}
void trackchange()
{ points++;
track++;
}
void status()
{ cout<<points<<"@"<<track<<endline;
}
};
void main()
{ game g;
g.initial(10,5);
g.trackchange();

29
g.status();
}
(i) #include<iostream.h>
void main( )
{ int First = 10, Second = 20;
Jumpto(First, Second);
Jumpto(Second);
}
void Jumpto(int N1, int N2 = 20)
{ N1=N1+N2;
cout<<N1<<N2;
}
(j) #include <iostream.h>
const int Size = 5;
void main()
{ int Array[Size] = {50, 40, 30, 20, 10};
for(int Ctr=0 ; Ctr<Size ; Ctr++)
cout <<Array[Ctr];
}

(2) Class & OOPs etc


(a) #include<iostream.h>
#include<conio.h>
class INT
{ int x;
public:
void getINT (int a){ x=a; }
void putdata()
{ cout<<a; }
};
void main()
{ INT obj1;
obj1.getINT(25);
obj1.putdata();
getch();
}
(b) #include<iostream.h>
class test
{ int i;
float j;
public:
test (void )
{ i=0; j=0.0; }
void init( )
{ cin>>i>>j; }
void display( )
{ cout<<"\n i="<<i;
cout<<”\n j= “<<j;
}
test(int a, float b)
{ i=a;
j=b; }
};
void main()
{ test t1;
test t2(10,12.5);
t1.display();

30
t2.display();
}
(c) #include<iostream.h>
class INT
{ int x;
public:
INT()
{ x=5; }
INT(int a)
{ x=a; }
void putdata();
{ cout<<a;
}
};
void main()
{ INT obj1;
INT obj2(25);
INT obj3(55);
obj1.putdata();
obj2.putdata();
obj3.putdata();
}
(d) #include<iostream.h>
class maine
{ int x;
float y;
protected:
long x1;
public:
maine()
{ };
maine(int s, float t=2.5)
{ x=s;
y=t; }
void getdata()
{ cin>>x>>y>>x1;
}
void displaydata()
{ cout<<x<<y<<x1;
}
};
void main()
{ clrscr();
maine m1(20, 2.4);
mainem2(1, 1.5);
maine m3(10);
maine m4;
}
(e) #include <iostream.h>
class MEMBER
{ int Mno; float Fees;
public:
void Register() { cin >> Mno >> Fees; }
void Display() { cout << Mno << " : " << Fees << endl; }
};

void main()

31
{ MEMBER M;
M.Register();
M.Display();
}
(f) class base { public: int x; };
class d1 : virtual public base { public: int y; };
class d2 : virtual public base { public: int z; };
class d3 : public d1, public d2
{ public: int total; };
void main()
{ d3 ob;
ob.x =25;
ob.y =50;
ob.z =75;
ob.total = ob.x + ob.y + ob.z;
cout <<ob.x<<"\t"<<ob.y<<"\t"<<ob.z<<"\tTotal: "<<ob.total;
}
E. Q.1 Fill in the blanks:
(1) Base Class constructor should be called before the derived class constructor.
(2) In copy constructor the argument is passed only by reference.
(3) A structure can be defined by keyword struct.
(4) A class may have data andfunctions as members.
(5) Functions defined inside the class are automatically inline.
(6) Private members of base class are not inheritable.
(7) Multiple inheritance may have multiple bases.
(8) Public members of base are become protected in derived class in protected visibility mode.
(9) Public members of base are become public in derived class in public visibility mode.
(10) Protected members of base are become protected in derived class in public visibility mode.
(11) Constructors will be invoked when the object will create.
(12) Public members of class could be accessible by objects.
(13) The destructor will be invoked when object goes out of scope.
(14) Encapsulation, Data Abstraction and Data Hiding concepts of OOPs are shown by a
class.
(15) An object includes all data members of class in its memory space.
(16)fail() function is used to find error when an input or output operation has failed during file
handling.
(17) ios::app this mode is used to append the data in file.
(18) tellg() is used to tell the position of get pointer in file.
(19) seekp() function should be used to set the position of put pointer in a file.
(20) write() function in file handling is associated to ofstream stream.

Unit-2: OOPs, Class, Constructor and Inheritance


32
Total Marks=12
QNo. Questions Theoretical
A.
1 What is polymorphism? Define the function overloading with example?
2 What is Inheritance, state its various forms?
3 What is class? State the concepts shown by the class & object?
4 What do you understand by Encapsulation and data hiding? Also, give a suitable c++ code to illustrate
both.
5 Define the inline functions and write the restrictions for inline function.
6 What is a constructor? Define its need and few characteristics?
7 What is a copy constructor and explain the situations in which a copy construction will be invoked?
8 What is destructor? State its various characteristics.
9 What is a Class and define the scope rules for its members?
10 Compare the default and parameterised constructor with example?
11 Define the static members of a class?
12 Define the use of virtual base class in Inheritance. Give a suitable example.
13 What are visibility modes in inheritance, explain the protected visibility mode with a suitable example?
14 What do you understand by object oriented programming paradigm? Give some characteristics of
OOPs?
15 Define Multilevel &Multiple inheritances in context of OOP with suitable example.
16 Compare the various visibility modes in inheritance, with example?
17 Define the nested class with example.

B. Practical Questions
1 Read the following class and give answer the following question (i) & (ii)
class Seminar
{ int Time;
public:
Seminar() //Function 1
{ Time=30; cout<<"Seminar starts now"<<end1;
}
void Lecture() //Function 2
{ cout<<"Lectures in the seminar on"<<end1;
}
Seminar(int Duration) //Function 3
{ Time=Duration; cout<<"Seminar starts now"<<end1;
}
~Seminar() //Function 4
{ cout<<"Vote of thanks"<<end1;
}
};

i) In Object Oriented Programming, what is Function 4 referred as and when does it get invoked/called?
ii) In Object Oriented Programming, which concept is illustrated by Function 1 and Function 3 together?
Write an example illustrating the calls for these functions.

2 Read the following class and give answer the following question (i) & (ii)
class Match
{ int Time;
public:
Match() //Function 1
{
Time=0;
cout<<"Match commences"<<end1;
}
void Details() //Function 2

33
{ cout<<"Inter Section Basketball Match"<<end1;
}
Match(int Duration) //Function 3
{ Time=Duration;
cout<<"Another Match begins now"<<end1;
}
Match(Match &M) //Function 4
{ Time=M.Duration;
cout<<"Like Previous Match "<<end1;
}
~Match() { } // Function 5
};
i) Which category of Function 4 belongs to and what is the purpose of using it?
ii) Write statements that would call the member Functions 1 and 3
3 Write a constructor for the following class that initializes the private members by parameters:
class ABC
{ int i, j;
float k;
public:
- - --
};
4 Answer the questions(i) and (ii) after going through the following class :
class Exam
{ int year;
public :
Exam(int y) { year=y; } //constructor 1
Exam(Exam &t); //constructor 2
}
(i) Create an object, such that it invokes constructor 1.
(ii) Write complete definition for constructor 2.
5 Write the parameterised constructor definition for the both classes given below:
class alpha
{ int a
float b;
char c;
public:
----------- //constructor definition
…... };
class beta : public alpha
{ int x;
public:
……………..//constructor definition
};
6 Read the following program code and explain the problem in the code, give the solution and justify.
#include<iostream.h>
class base
{ public: int x;
};
class d1 : public base
{ public: int y;
};
class d2 : public base
{ public: int z;
};
class d3 : public d1, public d2
{ public: int total;
};

34
void main()
{ d3 ob;
ob.x=25;
ob.y=50;
ob.z=75;
ob.total=ob.x+ob.y+ob.z;
cout <<ob.x<<"\t"<<ob.y<<"\t"<<ob.z<<"\tTotal: "<<ob.total;
}
7 class data
{ int num ;
public :
data ( int n )
{ num = n ; }
void show ( )
{ cout << n <<endl; }
};
class database : public data
{ int a;
public :
________________________
};
Define a constructor for the derived class database, which assigns values to the data members of derived
as well as base class.
C. Define Class

1 Define a class Student with following specifications:


Private data : Rollno, name, sub_marks[5], total
Public:
• getdata() function to get values
• calc() function to calculate total marks
• display() to display the output
2 Define a class Bank having private data:
bank_code int, name char(50), city char(25)
Public:
• Define functions to read and display all the data members.
• Aconstructor to initialise the object by values of bank_code, name and city from arguments.
3 Define a class Play in c++ with the following specifications:
Private data :
Playcode int,
Playtitle 25 char,
Duration float,
Noofscenes int
Public Members:
• A constructor to initialise duration as 45 and noofscenes as 5.
• Newplay() to accept values for playcode and playtitle.
• Moreinfo() to assign the values of duration and noofscenes with the help of corresponding
values passed as parameters to this function.
• Showply() to print all values on screen.
4 Define a class Stud with the following specifications:
private:
rollno(int type ), class(int type), per(float type)
protected:
getper() :- a function to enter percentage (per)
public:
• Stud():- constructor receive arguments to initialize the private members,
• Stud():- default constructor used to initialize null (dummy) values,
• getdata():- a function to accept the rollno of student, class and call the getper()
35
• printdata():- a function that print all data at output
• displaygrade():- a function to display grade of the student as below
if per>=80 then “grade is A”
if per>=60 and <80 then “grade is B”
if per>=40 and <60 then “grade is C”
if per<40 then “grade is D”
5 Define a class Worker with the following specifications:
private:
Wname (worker’s name), hrwrk (hours worked), wgrate (wage rate), totwag ( total wage)
calwag():- is a function calculate the total wage of the worker and returns
public:
• Worker():- default constructor assign null values
• inputdata():- a function to accept the values of wname, hrwrk, wgrate and call calcwg()
and store value of totwag
• outputdata():- a function that display the all data members.
6 Define a class Book with the following specifications:
private: bookno, title, price, totalcost():- is a function having an int argument of quantity and
used to calculate the total cost of the no. of books and return the value
public:
• getdata():- a function to accept the values of bookno, title and price
• purchase():- a function that read value of no of books (quantity) and pass it to
totalcost() and display the total cost
7 Define a class Flight in C++ with following description:
Private Members:
• A data member Flight number of type integer
• A data member Destination of type string
• A data member Distance of type float
• A data member Fuel of type float
• A member function CALFUEL() to calculate the value of Fuel as per the
following criteria
Distance Fuel
<=1000 500
>1000 and <=2000 1100
>2000 2200
Public Members:
• FEEDINFO()-- to allow user to enter values for Flight Number, Destination, Distance & call
function CALFUEL() to calculate the quantity of Fuel
• SHOWINFO() -- to allow user to view the content of all the data members
8 Define a class TEST in C++ with following description:
Private Members:
TestCode of type integer, Description of type string, NoCandidate of type integer, CenterReqd
(number of centers required) of type integer, A member function CALCNTR() to calculate and
return the number of centers as (NoCandidates/100+1)
Public Members:
• SCHEDULE() - to allow user to enter values for TestCode, Description, NoCandidate & call
function CALCNTR() to calculate the number of Centers
• DISPTEST() - to allow user to view the content of all the data members
9 Define a class Competition in C++ with the following descriptions:
Data Members:
Event_no integer
Description char(30)
Score integer
qualified char
Member functions:
• A constructor to assign initial values Event_No number as 101, Description as “State level”,
Score is 50 and qualified as ‘N’.
• Input(), To take the input for event_no, description and score.
36
• Award(int), To award qualified as ‘Y’, if score is more than the cutoffscore passed as
argument to the function else ‘N’.
• Show(), To display all the details.
10 Define a class Travel in C++ with the description given below :
Private Members :
T_Code of type string, No_of_Adults of type integer, No_of_Children of type integer, Distance of type
integer, TotalFare of type float
Public Members :
• A constructor to assign initial null or 0 values.
• AssignFare( )- which calculates and assigns the value of the data member TotalFare as follows :
For each Adult
Fare (Rs) For Distance (Km)
500 >=1000
300 <1000 &>=500
200 <500
For each Child the above Fare will be 50% of the Fare mentioned above.
For example :
If Distance is 750, No_of_Adults = 3 and No_of_Children = 2
Then TotalFare should be calculated as
No_of_Adults * 300 + No_of_Children * 150, i.e. 3 * 300 + 2 * 150 = 1200
• EnterTravel() - to input the values of the data members T_Code, No_of_Adults, No_of_Children and
Distance; and invoke the AssignFare( ) function.
• ShowTravel() - which displays the content of all the data members for a Travel.
11 Define a class Movie in C++ with the description given below:
Private Members:
Name_of_movie of type character array(string)
Date_of_release of type character array(string)
Name_of_director of type character array(string)
Star of type int
Total_print_release of type int
Public Members:
• A default constructor to assign initial values as follows:
Name_of_movie NULL
Date_of_release 1/1/2007
Name_of_director NULL
Star 2
Total_print_release 100
• A function calculate_star() which calculates and assigns the value of data member Star as
follows:
Total Print Release Star
>= 1000 5
< 1000 &>=500 4
< 500 &>=300 3
< 300 &>=100 2
< 100 1
• A function EnterMovie() to input the values of the data members Name_of_movie,
Date_of_release, Name_of_director and Total_print_release
• A function ShowMovie() which displays the contents of all the data members for a movie.
12 Define a class Shop in C++ with the description given below :
private members:
name array of 40 characters
address array of 40 characters
type of item array of 3X20 characters
availqty array of 3 integers
totalqty integers

37
public members:
• Init() : function to ask and store the values of address, type of items, availqty and calculate
the totalqty, where totalqty = sum of all availqty.
• purchase(): function to ask the qty purchased and type of item from the user and updates the
totalqty and availqty accordingly .
for example: if the type of items available in the shop are: “Cosmetic”,
”FoodProducts”, ”Medicines”. And the shop keeper purchases the “Cosmetic”
item then updates the availqty and totalqty of the “Cosmetic” item.
• display(): function to display the details of the item in the following format :
Name : <SHOP NAME >
Address :<ADDRESS >
Items : <Type of Item 1> <Type of Item 2> <Type Of item 3>
Balance Stock : <avialqty> <availqty> <availqty>
Total Quantity: <totqty>
13 Define a class ELECTION with the following specifications. Write a suitable main ( ) function also to
declare 3 objects of ELECTION type and find the winner and display the details.
Private members :
Data : candidate_name , party , vote_received
Public members : Functions :
• Enterdetails ( ) – to input data
• Display ( ) – to display the details of the winner
• Winner ( ) – To return the details of the winner, receive array 3 candidates data and return the
winner object after comparing the votes received by three candidates.
14 Define a class named MOVIE in C++ with the following description:
Private members:
Hall_No integer
Movie_Name Array of characters (String)
Week integer (Total number of weeks the same movie is shown)
Week_Collection int
Total_Collection int
Public Members :
• Function Read_Data( ) to read an object of MOVIE type
• Function Display( ) to display the Movie_Name and Total_Collection.
• Function Update_total ( ) to update the total collection and Weekly collection once the
week changes (increase the week by 1). Total collection will be incremented by
Weekly collection and Weekly collection is made Zero.
• Function Update_Weekcoll() to update the Week_Collection as follows:
Week_collection += n; where n is received by argument
15 Assume that you are writing a text based medieval video game. Your video game will have two types of
characters, the player and the devil. A player has to know the values of certain attributes of characters.
Health integer
Strength integer
Agility integer
Type of weapon String
Type of armor String
A player must be able to perform the following actions:
• Player()- Constructor Initialize Health by 16, Strength by 12, Agility by 14, Type of weapon by
“Mace” and Type of armor by “leather”.
• Attackdevil()- Display the following message ‘Attack devil with’ Type of weapon
• Gettreasure () - Increments the value of the players health by 1
Define a class Player with the above specifications.
16 Define a class Telephone in C++ with following description:
Private Members:
Name 20 character
Address 50 character
Teleno 8 digit phone number
PreviousMR int, Previous Meter Reading
38
PresentMR int, Present Meter Reading
Amount float
A member function Calbill() to calculate and return the amount payable assuming the price of a
telephone call is Rs 0.50. amount = PresentMR – PreviousMR * 0.50
Public Members:
• A constructor to give initial value 0 to PreviousMR and PresentMR .
• A function Readinfo() to allow user to enter values the data members and call function
Calbill() to calculate the total amount .
• A function Showinfo() to view the content of all the data members.
17 Declare a class with the following specifications:
class name Taxpayer
Data members: int pan - to stores the personal account number
char name[20] - to store the name of a person
float taxincome - to store the total annual taxable income
float tax - to store the tax that is calculated
Member functions:
• Inputdata() - to enter the data for a taxpayer
• Display() - to display the data for a taxpayer
• ComputeTAX() - to computer tax for a taxpayer
The tax is calculated according to the following rules:
Total annual income Rate of taxation
Upto 60000 0%
60000 to 150000 5%
150000 to 500000 10%
above 500000 15%
18 Define a class FLAT in C++ with the following description:
Private members:
1) Name of Society of type string
2) House number of type integer
3) Number of members of type integer
4) Flat type of string
5) Income of float type
6) Allotflat( ) a member function to allocate flat type according to income.

Income Flat type


>=10000 HIGH
>=5000 and <10000 MID
<5000 LOW
Public members:
1) A function ACCEPT( ) to allow user to enter values for name of society, house number,
number of members, income and call Allotflat( ) to assign Flat type.
2) A function DISPLAY( ) to allow user to view the content of all the data members.
D Inheritance
1 class PUBLISHER
{ char Pub[12];
double Turnover;
protected:
void Register();
public:
long No;
PUBLISHER();
void Enter();
void Display();
};
class BRANCH
{ char City[20];
protected:
39
float Employees;
public:
BRANCH();
void Haveit();
void Giveit();
};
class AUTHOR : private BRANCH , public PUBLISHER
{ int Acode;
char Aname[20];
float Amount;
public:
AUTHOR();
void Start();
void Show();
};
(i) Write the names of data members, which are accessible from objects belonging to class AUTHOR.
(ii) Write the names of all the member functions which are accessible from objects belonging to class
BRANCH.
(iii) Write the names of all the members which are accessible from member functions of class
AUTHOR.
(iv) How many bytes will be required by an object belonging to class AUTHOR?
(v) Name the inheritance form shown by the above code.
2 Answer the questions (i) to (iv) based on the following:
class CUSTOMER
{ int Cust_no;
char Cust_Name[20];
protected:
void Register();
public:
CUSTOMER();
void Status();
};
class SALESMAN
{ int Salesman_no;
char Salesman_Name[20];
protected:
float Salary;
public:
SALESMAN();
void Enter();
void Show();
};
class SHOP : public CUSTOMER , public SALESMAN
{ char Voucher_No[10];
char Sales_Date[8];
public:
SHOP();
void Sales_Entry();
void Sales_Detail();
};
(i) Write the names of members which are accessible from objects belonging to class SHOP.
(ii) Write the names of the entire data member which are inherited into class SHOP.
(iii) Write the names of all the members which are accessible from member functions of class SHOP.
(iv) How many bytes will be required by an object belonging to class SHOP?

40
3 class university
{ int NOC; //number of colleges
protected:
char Uname[25]; // university name
public:
university();
char state[25];
void enterdata();
void displaydata();
};
class college : public university
{ int NOD; //no of department
char cname[25]; //name of college
protected:
void affiliation();
public:
college();
void enrol (int, int);
void show();
};
class department : public college
{ char dname[25]; //name of department
int nof; //no of faculty members
public:
department();
void display();
void input();
};

(i) Which class’s constructor will be called first at the time of declaration of an object of class
department?
(ii) How many bytes will be required by an object belonging to class department?
(iii) Name the member functions, which are accessible from the object of class department.
(iv) Name the data members, which are accessible from the object of class college.
(v) Name the inheritance form shown by the above code.
4 class Trust
{ char name[25];
long noofschools;
protected:
int members;
char chaiman[25];
public:
Trust();
void Enter();
void Display();
};
class School : protected Trust
{ int number;
char City[20];
protected:
long noofemployees;
public:
School();
int schoolcode;
void Input();
void Show();
};

41
class Employee : public School
{ char Ename[25];
char post[25];
double Salary;
public:
Employee();
void Enrol();
void Display();
};
a) Write the names of all data members, which are accessible from object belonging to class Employee.
b) How many bytes will be required by an object belonging to class Employee?
c) Write the names of all member functions, which are accessible from objects belonging to class School.
d) Write the name of all members private, protected, public in the class employee.(including inherited
members)
5 Consider the following declaration and answer the questions given below:
class vehicle
{ int wheels;
protected : int passenger;
public : void inputdata(int , int );
void outputdata();
};
class heavy_vehicle : protected vehicle
{ int diesel_petrol;
protected : int load;

public : void readdata(int , int);


void writedata();
};
class bus : private heavy_vehicle
{ char make[20];
public : void fetchdata( char);
void displaydata();
};
[a] Name the base class and derived class of the class heavy_vehicle.
[b] Name the data member(s) that can be accessed from function displaydata.
[c] Name the data member(s) that can be accessed by an object of bus class.
[d] How many bytes will be required by an object belonging to class bus?
[e] Write the protected members of class heavy_vehicle.
[f] Write the private & protected members of class bus.
[g] Is the function outputdata() is accessible by the object of class bus? Give the reason.
[h] Name the inheritance form shown by the above code.
6 class MNC
{ char Cname[25];
protected:
char Hoffice[25];
public:
MNC();
char Country[25];
void Enterdata();
void Displaydata();
};
class Branch : public MNC
{ long NOE;
char Ctry[25];
protected:
void Association();
public:

42
Branch();
void Add();
void Show();
};
class Outlet : public Branch
{ char State[25];
public:
Outlet();
void Enter();
void Output();
};
a) Which class’s constructor will be called first at the time of declaration of an object of class Outlet?
b) Name the member function(s), which are accessed from the object of class Outlet.
c) Name the data member(s), which are accessible from the object(s) of class Branch.
d) Name the protected member(s), class Outlet.
e) Name the data member accessible by the function of class Outlet.
7 Answer the questions (i) to (iv) based on the following code :
class Employee
{ int id;
protected :
char name[20];
char doj[20];
public :
Employee();
~Employee();
void Get();
void show();
};
class Daily_wager : protected Employee
{ int wphour;
protected :
int nofhworked;
public :
void getd();
void showd();
};
class Payment : private Daily_wager
{ char date[10];
protected :
int amount;
public :
Payment();
~Payment();
void show();
};
(i) Name the member functions, which are accessible by the objects of class Payment.
(ii) From the following, Identify the member function(s) that can be called directly from the object of
class Daily_wager class
show(), getd(), Get()
(iii) Find the memory size of object of class Daily_wager.
(iv) Is the constructors of class Employee will copied in class Payment? Due to inheritance.
(v) Name the private members of class Payment
8 Answer the questions (i) to (iv) based on the following class declaration:
class Medicine
{ char category[10];
char Date_of_Manufacture[10];
char Date_Of_Expiry[10];

43
protected:
char company[20];
public:
int x,y;
Medicine();
void Enter();
void Show();
};
class Tablet :protected Medicine
{ protected:
char tablet_name[30];
char volume_label[20];
void disprin();
public:
float price;
Tablet();
void enterdet();
void showdet();
};
class PainReliver : public Tablet
{ int Dosage_units;
long int tab;
char effects[20];
protected:
int use_within_Days;
public :
PainReliver()
void enterpr();
void showpr();
};
i) How many bytes will be required by an object of class Tablet and an object of class PainReliver
respectively?
ii)Write names of all the data members which are accessible from the object of class PainReliver.
iii) Write names of all member functions which are accessible from objects of class PianReliver.
iv) Write the names of all the data members which are accessible from the functions enterpr().
9 Consider the following declarations and answer the questions given below:
class Animal
{ int leg:
protected:
int tail;
public:
void INPUT (int );
void OUT ( );
};
class wild : private Animal
{ int Non_veg;
protected:
int teeth;
public:
void INDATA (int, int )
void OUTDATA( );
};
class pet : public Animal
{ int veg;
public:
void DISP (void);
};

44
(i) Name the base class and derived class of the class wild.
(ii) Name the data member(s) that can be accessed from function DISP ( ).
(iii) Name the member function(s), which can be accessed from the objects of class pet.
(iv) Is the member function OUT( ) accessible by the objects of the class wild? Give reason.
10 Consider the following C++ declaration and answer the questions given below:
class A
{ void any();
protected:
int a, b;
void proc();
public:
A( );
void get( );
void put( );
};
class B: protected A
{ int c, d;
protected:
int e, f;
void get2( );
public:
B( );
void put2( );
};
class C: private B
{ int p;
protected:
int q;
void get3( );
public:
void show3( );
};
(a) Name all the member functions which are accessible by the objects of class C.
(b) Name all the protected members of class B
(c) Name all the data members which are accessible from member functions of class C
(d) Which class constructor will be called first at the time of declaration of an object of class C. Give
reason?
(e) Is the member function proc() which can be accessed form the objects of class C
11 Answer the questions (i) to (iv) based on the following code:
class country
{ int h;
protected:
int s;
public:
void input(int);
void output();
};
class state : private country
{ int t;
protected:
int u;
public:
void indata(int,int);
void outdata();
};
class city : public state
{ int m;

45
public:
void display(void);
};
(i) Name the data members that can be accessed from function display();
(ii) Name the member function(s), which can be accessed from the objects of class city.
(iii) Is the member function output() accessible by the objects of the class state? Give reason?
(iv) Name the members of class city, inherited from other classes.
12 Answer the questions (i) to (iv) based on the following code :
class Trainer
{ char TNo [5], TName [20], Specialisation [10];
int Days;
protected :
float Remuneration;
void AssignRem (float);
public :
Trainer ( ) ;
void TEntry ( );
void TDisplay ( );
};
class Learner
{ char Regno [10], LName [20], Program [10];
protected :
int Attendance, Grade;
public:
Learner ( );
void LEntry ( );
void LDisplay ( );
};
class Institute : public Learner, public Trainer
{ char ICode[10], IName [20];
public:
Institute ( );
void IEntry ( );
void IDisplay ( );
};
(i) Which type of Inheritance is depicted by the above example?
(ii) Identify the member function(s) that cannot be called directly from the objects of class
Institute from the following: (give reason)
TEntry( ), LDisplay(), AssignRem()
(iii) Write name of all the data member(s) accessible from member functions of class Institute.
(iv) If class Institute was derived privately from class Learner and protectively from class
Trainer, then:
(a) Name the member function(s) that could be accessed through Objects of class Institute.
(b) Name the protected members of class Institute inherited from the other classes.
13 Answer the questions (i) to (iv) based on the following code :
class Goods
{ int id;
protected :
char name[20];
long qty;
void Incr(int n);
public :
Goods();
~Goods();
void Get();
};
class Food_products : protected Goods

46
{ char exp_dt[10];
protected :
int id;
int qty;
public :
void getd();
void showd();
};
class Cosmetics : private Goods
{ int qty;
char exp_date[10];
protected :
int id;
public :
~Cosmetics();
Cosmetics();
void show();
};
(i) What will be the memory size of the object belongs to class Cosmetics.
(ii) Name the member functions accessible through the object of class Food_products.
(iii) From the following, identify the member function(s) that cannot be called directly from the
object of class Cosmetics. (give reason)
show(), getd(), Get()
(iv) If the class cosmetics inherit the properties of food_products class also in public visibility
mode, then name the type of inheritance with class Cosmetics.
14 Answer the questions (i) to (iii) based on the following code:
class toys
{ char Code;
char Manufacturer [10];
public:
toys( );
void Read_toy_details ( );
void Disp_toy_details( );
};
class electronic : public toys
{ int no_of_types;
float cost_of_toy;
public:
void Read_elect_details ( );
void Disp_elect_details ( );
};
class infants : private electronic
{ int no_of_buyers;
char delivery date[10];
public:
void Read_infant_details ();
void Disp_jnfant_details();
};
void main ( )
{ infants MyToy; }
(i) Mention the member names which are accessible by object MyToy declared in main ().
(ii) What is the size of MyToy in bytes?
(iii) Mention the data member name, which are accessible by the object of class electronics
15 Consider the following C++ declarations and answer the questions given below:
class Aayurved
{ void anyval();
protected:

47
int x,y;
void procval();
public:
void getvalA();
void putvalA();
};
class yoga : protected Aaryuved
{ int a, b;
protected:
int c, d;
void getvalB();
public:
void putvalB();
};
class Wisdom: private yoga
{ int p;
protected:
int q;
void getval();
public:
void showval();
};
i) Name all the member functions, which are accessible by the objects of class wisdom.
ii) Name all the private members of class yoga.
iii) Name the data members, which are accessible from member functions of class wisdom
iv) Name the OOPS concept implemented above and its type.
v) Name the data members accessible by function putvalB().
16 Consider the following C++ declarations and answer the questions given below:
class RED
{ char n [ 20 ];
void input ( );
protected :
int x , y ;
void read ( );
public :
RED ( );
RED ( int a );
void get_red ( );
void put_red ( );
};
class WHITE : protected RED
{ int a , b ;
protected :
int c , d ;
void get_white( );
public:
WHITE ( );
void put_white ( );
};
class BLACK : private WHITE
{ int * p ;
char st[20];
protected :
int q;
void get_black( );
public:
BLACK ( );

48
void put_black ( );
}ob;

a) Name the data members and functions which are accessible by the objects ob.
b) Give the size of object ob.
c) Name the members accessible by function get_black( );
17 Answer the questions (i) to (iii) based on the following:
class NATION
{ int H;
protected:
int S;
public:
void INPUT(int);
void OUTPUT();
};
class WORLD: private NATION
{ int T;
protected:
int U;
public:
void INDATA(int,int);
void OUTDATA();
};
class STATE: public WORLD
{ int M;
public:
void DISPLAY(void);
};
i) Name the data member(s) that can be accessed from function DISPLAY( )
ii) Name the member function(s), which can be accessed from the objects of class STATE
iii) Is the member function OUTPUT( ) accessible by the objects of class WORLD?

18 class exam
{ int mark ;
char sub [ 30 ];
public :
exam ( ) //Function 1
{ marks = 0 ;
strcpy ( sub , “ computer “ );
}
exam ( char s [ ] ) //Function 2
{ marks = 0 ;
strcpy ( sub , s );
}
exam ( int m ) //Function 3
{ marks = m ;
strcpy( sub , “ c ++ “ );
}
exam ( char s [ ] , int m ) //Function 4
{ marks = m ;
strcpy ( sub , s ); }
};

(a) Write statements to execute all four functions


(b) Can we overload a destructor?
(c) What concept of OOPS is demonstrated by the four functions?

49
Answers: Unit -2 : OOPS
QNo Answers
A. 1 Polymorphism is the ability for a data or a thing to be processed in more than one form. It is the
property by which one function can respond in different ways. A function name having several
definitions which are having different argument types or return types.e.g.
void square(int a, int b)
{ return (a*b);
}
void square(int x, float y)
{ return ( x*y);
}
2 Inheritance is the property of OOPS, by which one class can inherit its property from another class.
Its main advantage is reusability of codes. Its different form are as follows:
a. Single Inheritance
b. Multiple Inheritance
c. Multilevel Inheritance
d. Hierarchical Inheritance
e. Hybrid Inheritance
3 A class is a way to bind the data describing an entity and its associated functions together in a closed
boundary, which can be accessible outside only by its objects. The class and objects show
Encapsulation, Data Hiding and Abstraction concepts of OOPS.

4 Wrapping the data and their associated function together in a closed boundary, which can not
accessible outside the class, except its objects is called Encapsulation. The data define in the class
are hidden from the outside of class is called data hiding and they are accessible only by the
functions of that class.

5 The inline function will be executed in the same line of function call statement. The function body
will be transferred in to the calling function and they will be executed in that line only. Inline
functions are faster than the normal functions and they reduce the overheads of calling functions.
The restrictions of inline function are:
a. Function returns and having loops or switch or goto statements
b. Functions not returning values if a return statement exist.
c. Function contains static variables.
d. Recursive functions.

6 Constructor is a member function of class, which has same name as class name and used to initialise
the data members of class. Constructor is required to initialise the data members for an object and
there is no other ways to initialise. (Except input function, but it need to be called separately but
constructor invoked itself automatically). Some characteristics of constructors are:
a. It invoked automatically, when objects are created.
b. It does not have any return type. (not even void)
c. It may not be static.
d. Constructor obeys the usual access rules of class.
e. They can not be inherited.
7 A copy constructor is a constructor used to make copy of an object and assign to another object. The
situations in which a copy construction invoked are:
a. When an object initialized by another object.
b. When a functions returns an object.
c. When an object passed by value.

8 Destructor is a member function of class, which has same name as class name and used to de-
initialise the object of class from memory. Its various characteristics are :
a. It invoked automatically, when objects will go out of scope or program ended.
b. It does not have any return type. (not even void)

50
c. It may not be static.
d. Destructor obeys the usual access rules of class.
e. They can not be inherited.
9 A class is a way to bind the data describing an entity and its associated functions together in a closed
boundary, which can be accessible outside only by its objects. A class has three sections private,
protected and public. The scope rules for them are as follows:
Private and Protected: class Scope (local)
Public: depend on object scope, for a local object, local and for a global object global.

10 The default constructor does not have any argument and parameterised constructor have
argument(s). for ex.
class temp
{ int a,b;
public:
temp() //default constructor
{ a=0; b=1; }
Temp(int I, int J) //parameterised constructor
{ a= I; b=J }
…………};
11 A class may have two types of static member, static data and static member functions. The static
data members and common for all objects and its value will be shared by all objects. The static
member function is the function which access only static data member of the class, it can be invoked
directly by using class name followed by :: and followed by static function name.

12 Virtual base class is used to resolve the ambiguity in hybrid Inheritance. When a class A derives two
base classes like B and C and than B and C derives one class T then the properties of class A will be
delicately entered in the class T through B and C class. This problem can be solved by making the
base A virtual in declaration of class B & C. So a virtual class helps to stop duplicate properties in
inheritance.
class base { public: int x; };
class d1 : virtual public base { public: int y; };
class d2 : virtual public base { public: int z; };

class d3 : public d1, public d2


{ public: int total; };
void main()
{ d3 ob;
ob.x =25;
ob.y =50;
ob.z =75;
ob.total = ob.x + ob.y + ob.z;
cout <<ob.x<<"\t"<<ob.y<<"\t"<<ob.z<<"\tTotal: "<<ob.total;
}
13 The visibility modes in inheritance defines the type of member of a class will be inherits into
another class. There are three types of visibility modes in inheritance: Private, Protected and Public
For ex.
class A
{ int a;
protected:
int b;
public:
void getA();
void showA();
};
class B: protected A
{ int x;
protected:

51
int y; // int A::b inherited from class A in protected section
public: // void A::getA(), void A::showA() inherited in protected section
void getb();
void showB();
};

14 OOPS is superset of object based programming. It defines the program in view of objects, an object
a real entity which has some characteristics (data) and behavior (functions). The program is
designed in such a way to solve the object. The characteristics of OOPS are:
a. Data Abstraction: The act of representing essential features without including the
background details or explanations.
b. Encapsulation: The wrapping up of data and its functions in a closed boundary or single
unit.
c. Inheritance: One class can inherit its property from another class. Its main advantage is
reusability of codes.
d. Polymorphism: The ability for a data or a thing to be processed in more than one form. It is
the property by which one function can respond in different ways.
e. Modularity: Program can be decomposed into a set of cohesive and loosely coupled
modules.
15 Multilevel Inheritance: A class derives another class and which also derives other class.
Multiple Inheritance: Multiple base classes derives a single class.
Example can be shown from further questions.

16 Visibility modes in Inheritance define the inheritable members of base class into derived class. The
comparison is as follows:
Class Members/ Visibility modes: Private Protected Pubic
Private Not Inheritable in all modes
Protected Private Protected Protected
Public Private Protected Public

17 When a class declaration of an object of a class is declared in a class definition is called nesting of
classes. The inner class object must be used only by the outer class objects. This is also known as
“containership”.
class Outer
{ int m;
class Inner
{ int a;
public:
void getI()
{ cin>>a; }
void prn()
{ cout<<”A= “<<a; }
} obin;
public:
void getO()
{
cin>>m;
obin.getI();
}
void disp()
{
cout<< “Outer m= “<<m<<endl;
cout<<”Inner a=” <<obin.prn()<<endl;
}
};

52
B. Answer to Practical Questions:

1 i) Function 4 is known as Destructor and it get invoked/ called when the object goes out of scope or
program ended.
ii) Function 1 and Function 3 shows function overloading concept of Object Oriented Programming.
For example:
void main()
{ seminar obj1; // this will call Function 1
Seminar obj2(20); // this will call Function 2……}
i) The Function 4 is a copy constructor and it is used to copy one object into another object.
ii)
2 Match M1; // this will call Function 1
Match M2( 10); // this will call Function 3
3 ABC( int a, int b, float c)
{ i = a;
j = b;
k = c;
}
4 (i) Exam e1(2000); // this will invoke the constructor 1
(ii) Exam:: Exam( Exam & t)
{ year = t. year;
}
5 alpha( int I, int J, float K) // alpha class Constructor
{ a = I;
b = J;
c = K;
}
beta ( int m, int n, int q, float p) : alpha(n, q, p) // arguments passed to base constructor
{ x= m; //should placed right side in single inheritance
}
6 This is an example of hybrid inheritance and this will create an ambiguity to access x member of
class base in the class d3, because of duplicate entry in the class d3 (one from class d1 and one from
class d2). To solve this problem we should define the class base as virtual in the declaration of
class d1 and d2 as follows:
class d1 : virtual public base
{
…..
}
class d2 : virtual public base
{
……
}
7 database( int m, int n) : data (int n)
{ a = m;
}
C. Define Class

1 class Student
{ int Rollno, sub_marks[5], total;
char name[25];
public:
void getadata();
void calc();
void display();
};

53
void Student :: getdata()
{ cin>> Rollno;
for( int i = 0; i< 5 ; i++)
{ cin>>sub_marks[i];
}
gets(name);
}
void Student :: calc()
{ for( int t=0, int i = 0; i< 5 ; i++)
{ t = + sub_marks[i]; }
total = t;
}
void Student :: display ()
{ cout<<” Roll Number : “<< Rollno <<” Name : :<< name<<endl;
for( int i=0; i<5 ; i++)
cout<< “ SUB “<< i+1 << “ : “ << sub_marks[i]<< “ \t”;
cout<< “ \n Total Marks : “<<total;
}
2 class Bank
{ private:
int bank_code;
char name[50], city [25];
public:
Bank(int c, char n[], char p[])
{ bank_code = c;
strcpy(name, n);
strcpy(city, p);
}
void readdata()
{ cin>>bank_code;
gets(name); gets(city);
}
void display()
{ cout<<”Code: “<<bank_code<<” Name: “<<name<<” City:”<<city<<endl;
}
3 class Play
{ private :
int Playcode, Noofscene;
char Playtitle[25];
float Duration;
public:
Play()
{Duration= 45;
Noofscene =5;
}
void Newplay()
{ cin>>Playcode;
gets(Playtitle);
}
void Moreinfo(int n, float p)
{ Duration = p;
Noofscenes = n;
}
void Showply()
{ cout<<Playcode<<” “<<Playtitle<<” “<<Noofscene<<” “<<Duration<<endl;
}
};

54
4 class Stud
{ private:
int rollno, Class;
float per;
protected:
void getper()
{ cin>>per;
}
public:
Stud(int i, int j, float k)
{ rollno=i;
Class=j;
per=k;
}
Stud()
{ rollno=0;
Class=0;
per=0;
}
void getdata()
{ cin>>rollno>>Class;
getper();
}
void printdata()
{ cout<<”Roll no: ”<<rollno<<”Class: ”<<Class<<” Percentage:”<<per;
}
void displaygrade()
{
if (per>=80)
cout<<“grade is A”;
else if (per>=60 )
cout<<“grade is B”;
else if (per>=40)
cout<<”grade is C”;
else
cout<<“grade is D”;
}
};
5 class Worker
{ private:
float hrwrk, totwag, wgrate;
char Wname[25] ;
float calwag()
{ return (hrwrk* wgrate);
}
public:
Worker()
{ hrwrk=0; totwag=0; wgrate= 0; strcpy((Wname, “NULL”);
}
void inputdata()
{
cin>>hrwrk>>wgrate;
gets(Wname);
totwag = calwag();
}

55
void outputdata()
{ cout<< “Woker name “<<Wname<<” Hour Worked: “<<hrwrk;
Cout<<”Wage rate: ”<<wgrate<<”Total Wage : “<<totwag;
}
};
6 class Book
{ private: int bookno;
float price;
char title[50];
float totalcost(int qty)
{ return ( qty * price); }
public:
void getdata()
{ cin>>bookno>>price;
gets(title);
}
void purchase()
{int q;
cout<<”enter the no of books to be purchased: ”;
cin >>q;
cout<<”Total cost =”<<totalcost(q);
}
};
7 class Flight
{ private :
int Flightno;
char Destination[25];
float Distance, Fuel ;
void CALFUEL()
{ if (Distance>2000)
Fuel=2200;
else if(Distance>1000)
Fuel = 1100;
else
Fuel = 500;
}
public :
void FEEDINFO()
{ cin>>Flightno;
gets(Destination);
cin>>Distance;
CALFUEL();
}
void SHOWINFO()
{
cout<< “ Flight number : “<< Flighno<<”Destination : “<<Destination<<” Distance : “
<<Distance<< “ Total Fuel = “<<Fuel;
}
};
8 class TEST
{private :
int TestCode, NoofCandidate , CenterReqd;
char Description[50];
int CALCNTR()
{ return (NoofCandidates/100 + 1);
}
public:

56
void SCHEDULE()
{
cin>>TestCode>> NoofCandidate;
gets(Description);
centerReqd=CALCNTR() ;
}
void DISPTEST()
{ cout<<TestCode<< NoofCandidate<<Description<<CenterReqd;
}
};
9 class Competition
{ int Event_no, Score;
char Description[50], qualified;
public:
Competition()
{ Event_No = 101;
strcpy(Description ,“State level”);
Score = 50 ; qualified =‘N’;
}
void Input()
{ cin>>Event_no>>Score.
gets(Description);
}
void Award(int cuts)
{ if(Score>cuts)
qualified = ‘Y’;
else
qualified= ‘N’;
}
void Show()
{ cout<< Event_no<< Score<< Description<< qualified;
}
};
10 class Travel
{ private :
int No_of_Adults, No_of_Children, Distance;
char T_Code[10];
float TotalFare;
public :
Travel()
{ No_of_Adults=0; No_of_Children =0; Distance =0;
strcpy(T_Code, “ “);
TotalFare = 0 ;
}
void AssignFare( )
{ int f;
if ( Distance>=1000)
f = 500;
else if (Distance>=500)
f = 300;
else
f = 200;
TotalFare = No_of_Adults * f + (No_of_Children * f)/2;
}
void EnterTravel()
{ cin>>T_Code>> No_of_Adults>> No_of_Children >>Distance;
AssignFare( );

57
}
void ShowTravel()
{ cout<< T_Code<< No_of_Adults<< No_of_Children <<Distance<< TotalFare;
}
};
11 class Movie
{ private :
int Star, Total_print_release;
char Name_of_movie[30], Date_of_release[20], Name_of_director[25];
public :
Movie()
{ strcpy(Name_of_movie, “ NULL”);
strcpy(Date_of_release, “1/1/2007”);
strcpy(Name_of_director, “NULL”);
Star = 2; Total_print_release = 100;
}
void calculate_star()
{
if (Total_print_release>=1000)
Star = 5;
else if(Total_print_release>= 500)
Star = 4;
else if(Total_print_release>= 300)
Star = 3;
else if (Total_print_release>= 100)
Star = 2;
else
Star = 1;
}
void EnterMovie()
{ gets(Name_of_movie);
gets(Date_of_release); gets(Name_of_director);
cin>>Total_print_release;
}
void ShowMovie()
{
cout<<Name_of_movie<<Date_of_release<<Name_of_director<<Total_print_release<<Star;
}
};
12 class Shop
{ int availqty[3], totalqty ;
char name[40], address[40], typeofitem[3][20]; // let there are only 3 item types available
public :
void init();
void purchase();
void display();
};
void Shop::init()
{ int t=0;
gets(name); gets(address);
for(int j=0;j<3;j++)
gets(typeofoitem[j]);
for(int i=0;i<3;i++)
{ cin>>avaiqty[i];
t += avaiqty[i];
}
totalqty[i] = t;

58
}
void Shop::purchase()
{ int qty;
char name[20];
cout<<”enter the name of item and quantity to be purchased”;
gets(name) ; cin>>qty;
for(int i=0; i<3;i++)
{ if (strcmp(typeofitem, name)= = 0)
{ availqty[i] += qty; totalqty += qty;
}
}
}
void Shop::display()
{ cout<<”Name : “<<name<<endl;
cout<<”Address :”<<address<<endl;
cout<<”Items “;
for(int i=0;i<3;i++)
cout<<”\t”<< typeofitem[i];
cout<<”\n Balance Stock :”;
for(int i=0;i<3;i++)
cout<<”\t”<<availqty[i];
cout<<”\n\t\t\tTotal Quantity= “<<totalqty;
}
13 class ELECTION
{ private :
long vote_received;
char candidate_name[25] , party [40];
public : :
void Enterdetails ( )
{ gets(candidate_name); gets(party);
cin>>vote_received;
}
void Display ( )
{ cout<< “Candidate Name: “<<candidate_name<< “Party: “ <<party<<“
Vote:“<<vote_received;
}
ELECTION Winner (ELECTION candidates[] )
{ int max=0; long L = candidates[0].vote_received;
for(int i=1 ; i<3 ; i++)
{ if (L < candidates[i].vote_received)
{ L = candidates[i].vote_received; max = i;
}
}
return(candidates[max]);
}
};
void main()
{ ELECTION E[3], temp;
for( int i=0 ; i<3; i++)
{ E[i] . Enterdetails();
}
Temp.Winner(E);
}
14 class Movie
{ int Hallno;
char MovieName[30];
int Week, Week_Coll, Total_Coll ;

59
public:
void Read_Data()
{ cin>>Hallno;
gets(Moviename);
cin>>Week
}
void Display()
{ cout<<<<Moviename<<endl<<Total_Coll;
}
void Update_Total()
{ Total_coll + = Week_Coll;
Week + = 1;
Week_Coll =0;
}
void Update_Weekcoll(int n)
{ Week_Coll + = n;
}
};
15 class Player
{ int Health, Strength, Agility;
char Weapon[25];
char Armor[25];
public:
Player()
{ Health=16;
Strength = 12;
Agility = 14;
strcpy( Weapon, “Mace”);
strcpy( Armor, “Leather”);
}
void Attackdevil()
{ cout<<”Attack Devil with : “<<Weapon;}
void Gettreasure()
{ Health + = 1; }
};
16 class Telephone
{ char Name[20], Address[50];
long Teleno;
int PreviousMR, PresentMR;
float Amount;
float Callbill()
{ float t = (PresentMR - PreviousMR) * 0.50;
return(t); }
public:
Telephone()
{ PresentMR =0;
PreviousMR = 0;
}
void Readinfo()
{ gets(Name);
gets(Address);
cin>>Teleno>> PresentMR>>PreviousMR;
Amount = Callbill();
}
void Showinfo()
{ cout<<”Telphone user Details: \n”;
cout<<” Name :”<<Name<<”\t Address : “<<Address<<”\n Telephone number :”<<Teleno<<”\n

60
Bill Amount : “<<Amount<<endl;
}
};
17 class TaxPayer
{ int pan;
char name[20];
float taxincome, tax;
public:
void Inputdata()
{ cin>>pan;
gets(name);
cin>>taxincome;
}
void Display()
{ cout<<”PAN : :<<pan<< “ Name : “<<name<< “ total income: <<taxincome<< “ Total Tax
Payable :”<< tax<<endl;
}
void ComputeTAX(0
{
if( taxincome>500000)
tax = taxincome * 0.15;
else if (taxincome>150000)
tax = taxincome * 0.10;
else if (taxincome>60000)
tax = taxincome * 0.05;
else
tax = 0;
}
};
18 class FLAT
{ int Houseno, noofmember;
char Name[30], Flattype[10];
float Income;
void Allotflat()
{ if(Income >= 10000)
strcpy(Flattype, “HIGH”);
else if (Income > = 5000)
strcpy(Flattype, “MID”);
else
strcpy(Flattype, “LOW”);
}
public:
void ACCEPT()
{ cin>>Houseno>>noofmember;
gets(Name);
cin>>Income;
}
void DISPLAY()
{ cout<< Houseno<<”\n”<<noofmember;
cout<<” Name: “<<Name<<” Type of Flat Allotted : ”<<Flattype<<endl;
cout<<” Total Income :”<< Income<<endl;
}
};
D. Inheritance
1 (i) long PUBLISHER:: No
(ii) BRANCH :: Haveit (), BRANCH :: Giveit ().
(iii) Acode, Aname, Amount, City, Employee, Haveit(), Giveit(), Pub, Turnover, No,

61
Register(), Enter(), Display().
(iv) The object belonging to class AUTHOR require 12+8+4+20+4+2+20+4 = 74 bytes.
(v) Multiple Inheritance

2 (i) Sales_Entry(), Sales_Detail(), Status(), Enter(), Show()


(ii) Salary
(iii) Voucher_No, Sales_Date, Salary, Enter(), Show(), Register(), Status()
(iv) 66

3 (i) university
(ii) 106
(iii) display(), input(), enroll(), show(), enterdtata(), displaydata()
(iv) state
(v) Multilevel

4 a) schoolcode
b) 142
c) Input(), Show()
d) Private:- Ename, post, salary
Protected:- noofemployees, members, chairman, Enter(), Display()
Public: Enrol(), Display(), schoolcode, Input(), Show()

5 [a] base- vehicle, derived – bus


[b] make, load. Passenger
[c] NIL
[d] 28
[e] load, passenger
[f] Private:- make, load, passenger Protected:- NIL
[g] No, because it becomes protected in class heavy_vehicle and then it become private in class bus,
so a private member can not access by an object.
[h] Multilevel

6 a) MNC
b) Enter(), Output(), Add(), Show(), Enterdata(), Displaydata()
c) Country
d) Association(), Hoffice
e) State, Hoffice, Country

7 (i) Show()
(ii) getd()
(iii) 46
(iv) No, because constructors are never inherits
(v) date, nofhworked, getd(), showd(), name, doj, Get(), show()

8 (i) 108, 136


(ii) price
(iii) enterpr(), showpr(), enterdet(), showdet()
(iv) company, x, y, tablet_namr, volume_label, price, Dosage_units, tab, effects,
use_within_Days

9 (i) Base class: Animal and Derived class: pet.


(ii) veg, teeth
(iii) DISP(), INPUT(), OUTDATA()
(iv) No, because OUT ( ) is become private in the class wild, so it cannot accessible by the
objects.

62
10 (a) show3(),
(b) e, f, get2(), a, b, proc(), get(), put()
(c) p, q, e, f, a, b
(d) A class constructor will be called first, then B class constructor and in last C
class constructor will be executed, because always a base class constructor gets
execution before the derived class constructor, in inheritance.
(e) No
11 (i) m, u
(ii) display(), indata(), outdata()
(iii) No, because it becomes the private in class state and private member can not accessed
by the object.
(iv) u, indata(), outdata()

12 (i) Multiple
(ii) AssignRem(): because it became protected in the class institute
(iii) ICode, IName, Grade, Attendance, Remuneration
(iv) (a) IEntry(), IDisplay()
(b) Remuneration, AssignRem(), TEntry(), TDisplay()
13 (i) 40
(ii) getd(), showd()
(iii) Getd(): because it is a function of class Food_products and this class not related with
class cosmetics.
(iv) Multiple

14 (i) Read_infant_details(), Disp_infant_details()


(ii) 29
(iii) Nil

15 (i) showval()
(ii) a, b
(iii) p, q, c, d, x, y
(iv) Inheritance, Multilevel
(v) a, b, c, d, x, y

16 a. put_black()
b. 56
c. *p, st, q, c, d, get_white(), put_white(), x, y, read(), get_red(), put_red()
17 (i) M, U
(ii) DISPKAY(), INDATA(), OUTDATA()
(iii) No, because it comes to private section of class WORLD.

18 (a) exam e1; // call to Function 1


exam e2(“Phy”); // call to Function 2
exam e3(45); // call to Function 3
exam e4(“Chem”, 92); // call to Function 4
(b) No
(c) Polymorphism: Function overloading

63
Unit -3: Array and Data Structure
Total Marks=14
Q.No Question
A. 2-D Array Memory address calculations:

1 An array X[30][10] is stored in the memory with each element requiring four bytes of storage. If the base
address of X is 4500, find out memory location of X[12][8] and x[2][4], if the content is stored along with the
row.
2 An array X[10][20] is stored in the memory with each element requiring four bytes of storage. If the base
address of X is 1000, find out memory location of X[2][18] and x[9][19], if the content is stored along the
column.
3 An array val[1..15][1..10] is stored in the memory with each element requiring two bytes of storage. If the
base address of array val is 1500, determine the location of val[12][9] when the array val is stored:
a. Row wise
b. Column wise
4 A 2-D array defined as A[-4..7, -1..3] requires 2 words of storage space for each element. Calculate the
address of A[6,2] and A[-2,2], given the base address as 100,if the array is stored in row major
implementation.
5 If an array B[11][8] is stored as column wise and B[2][2] is stored at 1024. Find out the base address and
address of B[5]3], where each of its elements occupying 4 bytes.
6 An array ARR[35][15] is stored in the memory along the row with each of its element occupying 4 bytes.
Find out the base address and the address of an element ARR[20][5], if the location ARR[12][10] is stored at
the address 3000.
7 An array S[40][30] is stored in the memory along the row with each of the element occupying 1 bytes, find
out the memory location for the element S[15][5], if an element s[20][10] is stored at memory location 5700
8 An array ARR[-4..5][-2..4] is stored in the memory with each element occupying 2 bytes of space.
Assuming the address of ARR[9][11] is 4500 then compute the base address of ARR, when the array is
stored as :
9 i) Row wise ii) Column wise
A two dimensional array A [-1...5] [-4…5] having integers (long int), is stored in the memory along the
column, find out the memory location for Base Address and the element A [2][2], if an element A [0][3] is
10 stored at the memory location 5000.
An array A[-1..5][-1..10] is stored in the memory along the row with each element occupying 2 bytes.
Find out the address of the element A[3][2], where the base address of array is 2500.
B. 1- D Array Functions

1 Write a user define function, which receive an float array A containing 10 salaries of employees, arrange the
array in descending order of salary using bubble sort method.
2 Write a function in C++, which accepts an integer array and size as arguments and sort all the elements in
ascending order using selection sort technique.
3 Write a function in C++, which accepts an integer array, its size and an element as arguments and search that
element by using binary search algorithm.
4 Write a function named Merge ( ), which receive three arrays of integers type X, Y and Z with their sizes m,
n and s respectively(where s = m +n). Assume the both arrays X and Y were sorted in ascending order. The
function will merge X and Y store into third array Z and it should be in ascending order.
e.g: X- 2, 4, 8, 15, 21
Y- 3, 9, 18, 22, 25
Then Z- 2, 3, 4, 8, 9, 15, 18, 21, 22, 25
5 Write a function named Merging( ), which receive three arrays of integers type X, Y and Z with their sizes m,
n and s respectively(where s = m +n). Assume the array X is sorted in ascending and Y is sorted in
descending order. The function will merge X and Y store into third array Z and it should be in ascending
order.
e.g: X- 2, 4, 8, 15, 21
Y- 25, 22, 18, 9, 3
Then Z- 2, 3, 4, 8, 9, 15, 18, 21, 22, 25

64
6 Write a function in C++, which accepts an integer array and its size as arguments and exchanges the values of
first half side elements with the second half side elements of the array.
example : if the array is 8, 10, 1, 3, 17, 90, 13, 60 then rearrange the array as
17, 90, 13, 60, 8, 10, 1, 3
7 Write a function in C++, which accepts an integer array and its size as arguments and exchanges the values at
alternate locations.
example : if the array is 2, 9, 1, 23, 47, 10, 3, 6 then rearrange the array as
9, 2, 23, 1, 10, 47, 6, 3
8 Write a function in C++, which accepts an integer array and its size as arguments and replaces elements
having even values with its half and elements having odd values with twice its value.
Example : if an array of five elements initially contains the elements as
3, 4, 5, 16, 9
then the function should rearrange the content of the array as: 6, 2, 10, 8, 18
9 Write a function in C++, which accepts an integer array and its size as arguments and replaces elements
which are divisible by 3 with thrice of its value and elements which are divisible by 2 with twice of its value
and others remain unaltered.
Example : if an array of five elements initially contains the elements as
3, 4, 5, 16, 9, 13, 25, 40
then the function should rearrange the content of the array as
9, 8, 5, 32, 27, 13, 25, 80
10 Write a program in C++, to use a function for replace the repeating elements in an array by 0. Do not use
parallel array. The order of the array should not change.
Eg : Array : 10 , 20 , 10 , 50 , 30 , 20 , 10
Result : 10 , 20 , 0, 50 , 30 , 0, 0
11 Write a function in C++, which accepts an integer array and its size as parameters and rearranges the array in
reverse, without using another array. if an array of nine elements initially contains the elements as 4, 2, 5, 1,
6, 7, 8, 12, 10
then the function should rearrange the array as 10, 12, 8, 7, 6, 1, 5, 2, 4
12 Write a function in C++, which accepts an integer array and its size as an arguments and prints the output
(using nested loops) in following format :
Example : if the array is having: 12459
Then the output should be:
1
22
4444
55555
999999
13 Write a function in C++, which accepts a character array and its size as arguments and reverse that array
without using second array and library function.
Example : if the array is having “Computer Science”
Then after reversal it should rearranged as “ecneicS retupmoC”
14 Write a function in C++, which receive an int array as argument with its size and count how many even and
odd numbers are there.
For ex. The array have: 1, 5, 20, 16, 14, 19, 21
Then total even = 3 and odd = 4
15 Write a function in C++, which accepts an integer array, its size and a specific element as arguments. The
function will search the element and also count how many time it appears in the array.
16 Assume an array E containing elements of structure employee is required to be arranged in descending order
of salary. Write a C++ function to arrange the same with the help of bubble sort method. The array and its
size is required to be passed as parameters to the function. Definition of structure Employee is as follows :
struct employee
{ int Eno; char name[25];
float salary;
};
17 Assume an array S containing elements of structure Student. Write a C++ function to display the record of all
the students in array having >=75 percentage marks. The array and its size are required to be passed as
arguments.

65
18 Write a function in C++, which accept an int array with its size and calculate the sum of all positive and all
negative numbers and count the total number of zeros in the array.
For ex:Array contains: 2, -1, 10, 0, -3, -7, 4, 0, 20
Then result is: sum of positive = 36, sum of negative = -11, Zero = 2
C. 2-D Array functions

1 Write a function in C++, which accepts a 2D array of integers as argument and displays the elements of
middle row and the elements of middle column. [Assuming the 2D Array to be a square matrix with odd
dimensioni.e. 3×3, 5×5, 7×7 etc...]
Example, if the array content is
354
769
218
Output through the function should be :
Middle Row : 7 6 9
Middle Column : 5 6 1
2 Write a function in C++, which accepts a 2D array of integers as argument and displays the elements which
lie on diagonals. [Assuming the 2D Array to be a square matrix with odd dimension i.e. 3×3, 5×5, 7×7 etc.]
Example, if the array content is
543
678
129
Output through the function should be :
Diagonal One : 5 7 9
Diagonal Two : 3 7 1
3 Write a function in C++, which accepts an integer array and its size,with one 2 d array as arguments and then
assigns the elements of 1 d array into 2 d array in the following format:
(Hint: the size row and column of 2 d array should be constant in argument like: if 1 d array is of size 4 than
2d array size should be 4 x 4)
If the array is 1, 2, 3
If the array is 1, 2, 3, 4, 5, 6
The resultant 2 D array is
The resultant 2 D array is given below
given below
0 0 0 0 0 1 0 0 1
0 0 0 0 2 1 0 2 1
0 0 0 3 2 1 3 2 1
0 0 4 3 2 1
0 5 4 3 2 1
6 5 4 3 2 1
4 Write a function in C++, which accepts a 2D array of integers as argument and assign the elements which are
divisible by 3 or 5 into a one dimensional array of integers.
12 3 9 14 
24 25 16 31
If the 2 - D array is  
19 32 45 27
 
11 5 28 18 
The resultant 1- D arrays is :12 , 3 , 9 , 24 , 25 , 45 , 9 , 5 , 18
5 Write a user define function Repeat(), which takes a two dimensional int array as argument and convert all
repeated element into zero in each row.
6 Write a user define function Convert(), which takes an one dimensional array with size N and one 2-D array
as argument and convert 1-D array into two dimensional array as follows:
Suppose arr[6]= { 1,2,3,4,5,6}
Resultant array should be: Arr[6][6] = 1 2 3 4 5 6
123450
123400
123000
120000
100000
7 Write a function in C++ called Shift( ), to rearrange the matrix as shown. The function should accept the
matrix as argument and display the rearranged matrix. Do not use parallel matrix.
66
Original Matrix Rearranged Matrix
1 2 -3 -2 1 0 -3 4
0 -1 2 1 2 -1 9 2
-3 9 -4 4 -3 2 -4 3
4 2 3 -1 -2 1 4 -1
Or
Original Matrix Rearranged Matrix (Transpose)
1 2 -3 1 0 -3
0 -1 2 2 -1 9
-3 9 -4 -3 2 -4
8 Write a function in C++ named UpperHalf(), which takes a two dimensional array A as argument and prints
the upper half to the array.
e.g.: Matrix original The output will be
2315 2315
3157 157
1068 68
2254 4
9 Write a function in C++, which accepts a 2 D array of integers as parameter, which displays the sum of row
elements.
Example array is:
5 3 8
10 0 4
7 4 6
The Output will be as follows
Sum of Row One is : 16
Sum of Row Two is : 14
Sum of Row Three is : 17
10 Write a function in C++, which accepts a 2 D array of integers and its arguments as parameters and which
counts the even numbers in each row.
D. Conversion of Polish Notations using Stack Implementation

1 Convert the following infix expression into postfix expression. Show the stack status after execution of each
operation.
a) A*(B+(C+D)*(E+F)/G)*H
b) A*(B+D)/E-F-(G+H/K)
c) A*(B+(C+D)*(E↑F)/G)*H
d) (A+B/C*D-F*T)
e) (True && false) | | !(false | | true)
f) TRUE OR FALSE AND NOT FALSE OR FALSE
g) A AND NOT B OR A AND C AND B OR NOT C
2 Evaluate the following postfix expression using a stack and show the Contents of stack after execution of
each operation:
(i) 50, 40, +, 18, 14, -, 4, *, +
(ii) 120, 45, 20, +, 25, 15, -, +, *
(iii) 15, 3, 2, +, /, 7, +, 2, *
(iv) 16 , 2 , 6 , + , / , 2 , * , 1 , –
(v) 5, 6 , 4 , - , * , 4 , 1 , - , 2 , ^ , +
(vi) 5 10 2 + * 20 10 / -
(vii) TRUE, FALSE, TRUE, FALSE, NOT, OR, TRUE , OR,OR,AND
(viii) FALSE, TRUE, FALSE, TRUE ,NOT, OR, TRUE, OR, OR, AND
(Hint: Consider the each ‘NOT’, ‘OR’, ‘AND’ as operators and ‘FALSE’ and ‘TRUE’ are operands, each symbol is separated by comma
for your references only, comma is not a operator included here)
E. Stack (with array & Link List)
1 class Stack
{ int data[10];
int top;
public:

67
Stack( ) { top=-1;}
void push ( ); // to push an element into the stack
void pop ( ) ; // to pop an element into the stack
void display( );// to display all the elements from the stack
};
Complete the above class with all function definition.
2 Consider the following portion of a program, which implements a Stack for Book names. Write the definition
of function Push (), to insert a new node of Book type into stack array ST.
struct Book
{ char names[4][20]; //max. four book name in a node.
}node;
class StackofBooks
{ Book ST[10];
public :
int Top;
StackofBooks()
{ Top = -1;
}
void Push();
void Pop();
};
3 Define the functions stackpush( ) and stackpop( ) of the following class STACK. The function
stackpush() -to create a new node dynamically and push the node into. The function stackpop ( ) - to delete
nodes from the stack.
struct Node
{ char name[20];
int age;
Node *Link;
};
class STACK
{ Node * Top;
public:
STACK( ) { TOP=NULL;}
void stackpush( );
void stackpop( );
~STACK( );
};
4 Write a function in C++, to create a set of nodes belongs to the following structure type in a dynamically
allocated stack. The function will receive the top as argument.
struct Library
{ int Bookid;
char Title[50];
char Author[50];
Library *next;
}*Top;
5 struct student
{ char name[20];
student *next;
};
Write a function in C++, to create a set of nodes to the above structure type in a dynamically allocated stack
and display a particular student’s record from stack at output.
6 Write a function in C++, to delete a node containing names of student, from a dynamically allocated stack of
student. Assume the stack has already a set of nodes of following structure. The function receives the value of
top by reference.
struct student
{ char name[20];
student *next;

68
};
7 Write a function to Insert (Push) a new node in a linked stack. The stack may have some elements where as
each node has been created by using the following structure. The function will create a new node and insert
it. (The function will receive the top as referenced argument.)
struct Node
{ int item;
Node *next;
};
8 Write a function to insert an int element into a stack (use array implementation: int Stack[100]). The function
will receive the stack and top as arguments. Display the stack array after insertion.
9 Define the Push and Pop functions in the following class Stack. Push() creates dynamic nodes and add them
to stack and Pop() perform the pop operation and delete the node. The structure of each node is as follows:
struct Node
{ int x, y;
Node * next;
};
class Stack
{
Node *Top;
public:
Stack() { Top=NULL; }
void Push();
void Pop();
};
10 Write a function in C++, to delete a node containing Book’s information, from a dynamically allocated Stack
of Books implemented with the help of the following structure. Assume the stack has already contains a set
of Book nodes, take the top pointer by reference as argument.
struct Book
{
int BNo;
char BName[20];
Book *Next;
};
11 Consider the following portion of a program which implements passengers Queue for a bus.
Write the definition of function Insert(), to insert a new node in the queue with required information and
function Delete(), to delete a node from the queue.
struct Node
{ int P_id;
char P_name[25];
Node *Link;
};
class QUEUE
{ Node *Rear, *Front;
public:
QUEUE( ) { Rear =NULL; Front= NULL; }
void Insert ( );
void Delete ( );
~QUEUE ( );
};

12 Write a user define function, to declare a linear queue using array implementation, where each node is the
object of following class. The function will insert a set of objects in the queue.
class Item
{ int code;
char name[20];
char descp[50];
float cost;

69
int qty;
public:
void getdata();
void display();
int retcode()
{ return code; }
};
13 Write a function in C++, to perform delete operation in a dynamically allocated queue considering the
following descriptions. The function will receive the front and rear as arguments.
struct Node
{ int u; float v;Node * next;
};
14 Write a function in C++, to perform insert operation on a dynamically allocated Queue containing roll
numbers of students. Also declare the relevant class/structure and pointer.
15 Write a function in C++, to search a node containing name of student, from a dynamically allocated Queue of
names implemented with the help of following structure. Assume the Queue contains a set of nodes. The
function receive the value of front and rear as arguments and display the name of student found or not found.
struct student
{ char name[20];student *next;
}*front , *rear;
16 Write a function in C++, to insert a node containing movie’s information, from a dynamically allocated
Queue of movie implemented with the help of following structure. The function will receive the value of
front and rear and a pointer to new node (to be insert). It will print all the nodes after insertion.
struct movie
{ int MNo;char MovieName[30];movie *link;
};
17 Consider the following portion of a program, which implements names queue for Books. Write the definition
of function Insert(), to insert a new node in the queue with required information.
struct Book
{ char names[4][20]; // each node contain max. 4 book names
};
class QueueofBooks
{ Book Q[10];
public :
int front ,rear;
QueueofBooks()
{ front=rear=-1;
}
void Insert();
void Delete();
};
18 Write a function INSERT(), which perform insertion operation in a Queue using linked list implementation.
Let the Queue is already exist and the function create new dynamic nodes and insert them into Queue as per
asked by user. The function also displays the total number of nodes in the Queue. The structure of each node
should be as follows:
struct Node
{ int m,p;
Node *next;
};

70
Answers to Unit -3: Array and Data Structure
Total Marks=14
QNo. Answers
A. Answer : 2- D array Memory address calculations
Formula for the Row Major order 2- D Array:
Address of [ i , j ]th element =B.A. + W(C(i – Lr ) + (j - Lc )) , where B.A. = Base Address,
W = Size of each element, C = No. of Columns, Lr = Lower Bound of Row, Lc = Lower Bound of Column.
Formula for the Column Major order 2- D Array:
Address of [ i , j ]th element =B.A. + W( (i – Lr ) + R(j - Lc )) , where B.A. = Base Address, W =
Size of each element, R = No. of Rows, Lr = Lower Bound of Row, Lc = Lower Bound of Column.

1 For the given Row Major order problem: w= 4, C= 10, Lr= Lc = 0, BA = 4500
Address of X[12][8] = 4500 + 4 ( 10 (12-0) + ( 8-0))
= 5012 Ans
Address of X[2][4] = 4500 + 4 ( 10 (2-0) + ( 4-0))
= 4596 Ans
2 For the given Column Major order problem: w= 4, R= 10, Lr= Lc = 0, BA = 1000
Address of X[2][18] = 1000 + 4 ( (2-0) +10 ( 18-0))
= 1728 Ans.
Address of X[9][19] = 1000 + 4 ( (9-0) +10 ( 19-0))
= 1796 Ans.
3 For the given problem: w= 2, R= 15, C = 10, Lr= 1, Lc = 1, BA = 1500
(a) in Row Major order: Address of Val[12][9] = 1500 + 2 ( 10 (12-1) + ( 9-1))
= 1736 Ans.
(b) in Column major order: Address of Val[12][9] = 1500 + 2 ( (12-1) + 15( 9-1) )
= 1762 Ans.
4 For the given Row Major problem: w= 2, C= 3 – (-1) +1 = 5, Lr= -4, Lc = -1, BA = 100
Address of A[6, 2] = 100 + 2 ( 5 (6 + 4) + ( 2 + 1))
= 206 Ans
Address of A[-2, 2] = 100 + 2 ( 5 (-2 + 4) + ( 2 + 1))
= 126 Ans
5 For the given Column Major order problem: w= 4, R= 11, Lr= Lc = 0
Address of B[2][2] => 1024 = BA + 4 ( (2-0) +11 ( 2-0))
B.A.= 1024 – 96 = 928 Ans.
Address of B[5][3] = 928 + 4 ( (5-0) +11 ( 3-0))
= 1080 Ans.
6 For the given Row Major order problem: w= 4, C= 15, Lr= Lc = 0, BA = ?
Address of ARR[12][10] => 3000 = BA + 4 ( 15 (12-0) + ( 10-0))
B.A. = 3000- 760 = 2240 Ans
Address of X[20][5] = 2240 + 4 ( 15 (20-0) + ( 5-0))
= 3460 Ans
7 For the given Row Major order problem: w= 1, C= 30, Lr= Lc = 0, BA = ?
Address of ARR[20][10] => 5700 = BA + 1 ( 30 (20-0) + ( 10-0))
B.A. = 5700- 610 = 5090
Address of X[15][5] = 5090 + 1 ( 30 (15-0) + ( 5-0))
= 5545 Ans
8 For the given problem: w= 2, R= 10, C = 7, Lr= -4, Lc = -2, BA = ?
(a) in Row Major order: Address of ARR [9][11] => 4500 = BA + 2 ( 7 (9+4) + ( 11+2))
BA = 4500-208 = 4292 Ans.
(b) in Column major order: Address of ARR [9][11] => 4500 = BA + 2 ( (9+4) + 10( 11+2))
BA = 4500-286 = 4214 Ans
9 For the given Column Major order problem: w= 4, R= 7, Lr= -1, Lc = -4, BA = ?
Address of A[0][3] => 5000 = BA + 4 ( (0+1) +7 ( 3+4))
B.A.= 5000 - 200 = 4800 Ans.
Address of A[2][2] = 4800 + 4 ( (2+1) +7 ( 2+4))
= 4980 Ans.

71
10 For the given Row Major problem: w= 2, C= 10 – (-1) +1 = 12, Lr= -1, Lc = -1, BA = 2500
Address of A[3, 2] = 2500 + 2 ( 12 (3+1) + ( 2 + 1))
= 2602 Ans

B Answer: User defined function for 1 –D Array


1 void sort(float a[], int size)
{ float t;
for(int i =0; i<size-1 ; i++)
{ for(int j=0; j< size -1 – i ; j++)
{ if(a[j]<a[j+1])
{ t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
cout<<”\nShow array in pass: “<<i+1<<endl;
for(int k = 0; k < size; k++)
cout << a[k]<<” “;
}
return;
}
2 void SelSort(int x[], int s)
{ int t, small, pos;
for(int i = 0 ; i< s; i++)
{ small = x[i];
pos = i;
for(int j = 1+i ; j<s ; j++)
{ if( x[j] < small)
{ small = x[j];
pos = j;
}
}
t = x[i];
x[i] = x[pos];
x[pos] = t;
cout<<”\nShow array in pass: “<<i+1<<endl;
for(int k = 0; k < s; k++)
cout << x[k]<<” “;
}
return;
}
3 void Bsearach(int a[], int size, int n)
{ int beg = 0, mid, last = size-1, f=0;
while(beg<=last)
{ mid = (beg+last)/2;
if(n==a[mid])
{ cout<<”Element found!!”;
f = 1;
break;
}
else if(n > a[mid])
beg = mid + 1;
else
last = mid – 1;
}
if (f = = 0)

72
cout<< “ Element not found!!!“;
}

4 void Merge( int x[], int m, int y[], int n, int z[], int s)
{ for(int i=0, j=0, k=0 ; i<m && j<n ; )
{ if(x[i] < y[j])
z[k++] = x[i++];
else
z[k++] = y[j++];
}
if(i<m)
while(i<m)
z[k++] = x[i++];
else
while (j<n)
z[k++] = y[j++];
cout<<”Show array after Merge”<<endl;
for(k = 0; k < s ; k++)
cout << z[k]<<” “;
return;
}
5 void Merging( int x[], int m, int y[], int n, int z[], int s)
{ for(int i=0, j=n-1, k=0 ; i<m && j>=0 ; )
{ if(x[i] < y[j])
z[k++] = x[i++];
else
z[k++] = y[j--];
}
if(i<m)
while(i<m)
z[k++] = x[i++];
else
while (j>=0)
z[k++] = y[j--];
cout<<”Show array after Merge”<<endl;
for(k = 0; k < s ; k++)
cout << z[k]<<” “;
return;
}
6 void Exchange(int a[], int size)
{ int k, t;
if( size%2 = = 0)
k = size / 2;
else
k = size / 2 + 1;
for( int i=0 ; i< size/2 ; i++, k++)
{ t = a[i];
a[i] = a[k];
a[k] = t;
}
cout<<”Show array after rearrangement:”<<endl;
for(k = 0; k < size; k++)
cout << a[k]<<” “;
}
7 void Rearrange(int a[], int size)
{ int k, t;
for( int i=0 ; i< size-1 ; i+=2)

73
{ t = a[i];
a[i] = a[i+1];
a[i+1] = t;
}
cout<<”Show array after rearrangement:”<<endl;
for(k = 0; k < size; k++)
cout << a[k]<<” “;
}
8 void Modify(int a[], int size)
{ for( int i=0 ; i< size ; i++)
{ if(a[i]%2 = = 0)
a[i] / = 2;
else
a[i] * = 2;
}
cout<<”Show array after rearrangement:”<<endl;
for(i = 0; i < size; i++)
cout << a[i]<<” “;
}
9 void Replace(int a[], int size)
{ for( int i=0 ; i< size ; i++)
{ if(a[i]%3 = = 0)
a[i] * = 3;
else if(a[i]%2 = = 0)
a[i] * = 2;
else
continue;
}
cout<<”Show array after rearrangement:”<<endl;
for(i = 0; i < size; i++)
cout << a[i]<<” “;
}
10 void Repeat(int a[], int size)
{ for( int i=0 ; i< size ; i++)
{ for( int j=1+i ; j< size ; j++)
{ if(a[j] = = a[i])
a[j] = 0;
}
}
cout<<”Show array after rearrangement:”<<endl;
for(i = 0; i < size; i++)
cout << a[i]<<” “;
}
11 void Reverse(int a[], int size)
{ int t;
for( int i=0, j = size-1 ; i< size/2 ; i++, j--)
{ t = a[i];
a[i] = a[j];
a[j] = t;
}
cout<<”Show array after rearrangement:”<<endl;
for(int k = 0; k < size; k++)
cout << a[k]<<” “;
}
12 void Pattern(int t[], int size)
{ for( int i=0 ; i< size ; i++)
{ for( int j=0 ; j<= i ; j++)

74
cout << t[i]<<” “;
cout<<endl;
}
}

13 void Reverse(char a[], int size)


{ int k = strlen(a);
char t;
for( int i=0, j = k-1 ; i< k/2 ; i++, j--)
{ t = a[i];
a[i] = a[j];
a[j] = t;
}
cout<<”Reverse String:”<<a;
}
14 void Countodd(int a[], int size)
{ int counte = 0, counto = 0;
for( int i=0 ; i< size ; i++)
{ if(a[i]%2 = = 0)
counte++;
else
counto++; }
cout<<”Total Even :”<<counte;
cout<<”\nTotal Odd :”<<counto;
}
15 void Search(int a[], int size, int n)
{ int i, count = 0;
for( int i=0 ; i< size ; i++)
if(a[i]= = n)
count++;
if (count = = 0)
cout<< “ Element not found!!!“;
else
cout<< “ Element found and it appears “<<count<<” Times”;
}
16 void StructSort(employee emp[], int size)
{ employee temp;
for(int i =0; i<size-1 ; i++)
{ for(int j=0; j< size -1 – i ; j++)
{ if(emp[j].salary < emp[j+1].salary)
{ temp = emp[j];
emp[j] = emp[j+1];
emp[j+1] = temp;
}
}
}
cout<<”Show Employee Records after Sorting”<<endl;
for(i = 0; i < size; i++)
{ cout<<”Employee : “<<i+1<<endl;
cout << emp[i].Eno<<”\t “<< emp[i].name<<”\t “<< emp[i].salary<<”\n “;
}
return;
}
17 void StudentPer(Student S[], int size)
{ cout<<”Show Students Records having >=75% Marks:”<<endl;
for(int i =0; i<size ; i++)
{ if(S[i].PerMarks>=75)

75
cout << S[i].Rollno<<”\t “<< S[i].Name<<”\t “<< S[i].PerMarks<<”\n “;
}
return;
}

18 void Countnum(int a[], int size)


{ int countn = 0, countp = 0, countz=0;
for( int i=0 ; i< size ; i++)
{ if(a[i] > 0)
countp++;
else if(a[i] < 0)
countn++;
else
countz++;
}
cout<<”Total Positive : ”<<countp;
cout<<”\nTotal Negative : ”<<countn;
cout<<”\nTotal Zero : ”<<countz;
}
C. Answer: User defined function for 2 –D Array

1 void Middle(int a[3][3])


{ int i =3/2; // 3 is the number of row
cout<<”Middle Row: ”;
for(int j = 0; j<3; j++)
cout<<a[i][j]<<” “;
cout<<”Middle Column : ”;
j=3/2; // 3 is the number of columns
for(int i = 0; i<3; i++)
cout<<a[i][j]<<” “;
}
2 void Diagonal(int a[3][3])
{ int i, j;
cout<<”Main Diagonal: ”;
for(j = 0; j<3; j++)
cout<<a[j][j]<<” “;
cout<<”\n Side Diagonal : ”;
for(i = 0,j=3-1 ; i<3 ; i++, j--)
cout<<a[i][j]<<” “;
}
3 void one2d(int a[], int s, int m[4][4])
{ for(int i=0; i<s, i++)
for(int j=0, k=s-1 ; j<i ; j++, k--)
m[i][k] = a[j];
cout<<”Display 2 d Array :\n”:
for(i=0; i<s; i++)
{ for(j=0; j<s ; j++)
cout<<m[i][j]<<” “;
cout<<endl;
}
}
4 void Assign(int a[3][3], int m[], int size) //the approximat size of 1 d array to be passed
{ int count =0;
for(int i= 0,k=0; i<3 ; i++)
{ for( int j=0 ; j<3 ; j++)
{ if (a[i][j] %3==0 || a[i][j]%5==0)
{ m[k++] = a[i][j];

76
count++;
}
}
}
cout<<” New assigned array: \n”;
for(i=0; i<count ; i++)
cout <<m[i]<<” “;
}
5 void Repeat(int x[3][3])
{ for(int i=0, k=0; i<3 ; i++)
{ for(int j=1; j<3 ; j++)
if(x[i][k] == x[i][j])
x[i][j]=0;
}
cout<<”Resultant Matrix”;
for(i=0;i<3;i++)
{ for(k=0 ; k<3 ; k++)
cout<<x[i][k]<<” “;
cout<<endl
}
}
6 void Convert(int a[], int s, int m[4][4]) //one d array size should be 4 only
{ for(int i=0; i<s, i++)
for(int k=0 ; k<s-i ; k++)
m[i][k] = a[k];
cout<<”Display 2 d Array :\n”:
for(i=0; i<s; i++)
{ for(j=0; j<s ; j++)
cout<<m[i][j]<<” “;
cout<<endl;
}
}
7 void Shift(int m[4][4])
{ int i, j, t;
for(i=0; i<4, i++)
{ for(j=0+i ; j<4 ; j++)
{ if(i != j)
{ t = m[i][j];
m[i][j] = m[j][i];
m[j][i] = t;
}
}
}
cout<<”Display 2 d Array :\n”:
for(i=0; i<4; i++)
{ for(j=0; j<4 ; j++)
cout<<m[i][j]<<” “;
cout<<endl;
}
}
8 void UpperHalf(int a[4][4])
{ for(int i=0; i<4; i++)
{ for(int j=0; j<4 ; j++)
if(i<=j)
cout<<a[i][j]<<” “;
else
cout<<” “;

77
cout<<endl;
}
}
9 void Sum(int a[3][3])
{ int i, j, sum;
for(i=0 ; i<3 ; i++)
{ sum = 0;
for(j=0 ; j<3 ; j++)
{ cout<<a[i][j]<<” “;
sum += a[i][j];
}
cout<< “Sum of Row: “<<i+1<<” = “<<sum<<endl;
}
}
10 void Count(int a[3][3])
{ int i, j, C;
for(i=0 ; i<3 ; i++)
{ C = 0;
for(j=0 ; j<3 ; j++)
{ if(a[i][j] % 2 = = 0)
C++;
}
cout<< “No. of Evens in Row: “<<i+1<<” = “<<C<<endl;
}}
D. Answer to Convert Infix to Postfix Notations
1 a) To convert this infix into postfix, first enclose the given expression into ( ). We take use a
stack to solve the problem: (A*(B+(C+D)*(E+F)/G)*H)

SNo Symbol Action Stack Output


Scanned Performed Expression
1 ( Push ( $(
2 A o/p $( A
3 * Push * $(* A
4 ( Push ( $(*( A
5 B o/p $(*( AB
6 + Push + $(*(+ AB
7 ( Push ( $(*(+( AB
8 C O/P $(*(+( ABC
9 + Push + $(*(+(+ ABC
10 D O/P $(*(+(+ ABCD
11 ) Pop + ( $(*(+ ABCD+
12 * Push * $(*(+* ABCD+
13 ( Push ( $ ( * ( + *( ABCD+
14 E o/p $ ( * ( + *( ABCD+E
15 + Push + $ ( * ( + *(+ ABCD+E
16 F o/p $ ( * ( + *(+ ABCD+EF
17 ) Pop + ( $(*(+* ABCD+EF+
18 / Pop *, push / $(*(+/ ABCD+EF+*
19 G o/p $(*(+/ ABCD+EF+*G
20 ) Pop / + ( $(* ABCD+EF+*G/+
21 * Pop *, push * $(* ABCD+EF+*G/+*
22 H o/p $(* ABCD+EF+*G/+*H

78
23 ) Pop * ( $ ABCD+EF+*G/+*H*
So the final out put postfix expression is: A B C D + E F + * G / + * H *

b) A*(B+D)/E-F-(G+H/K)
To convert this infix into postfix, first enclose the given expression into ( ). We take use a stack
to solve the problem: (A*(B+D)/E-F-(G+H/K))

SNo Symbol Action Stack Output


Scanned Performed Expression
1 ( Push ( $(
2 A o/p $( A
3 * Push * $(* A
4 ( Push ( $(*( A
5 B o/p $(*( AB
6 + Push + $(*(+ AB
7 D o/p $(*(+ ABD
8 ) POP + ( $(* ABD+
9 / Pop * ,Push / $(/ ABD+*
10 E O/P $(/ ABD+*E
11 - Push - $(/- ABD+*E
12 F o/p $(/- ABD+*EF
13 - Pop - / ,Push - $(- ABD+*EF-/
14 ( Push ( $(-( ABD+*EF-/
15 G o/p $(-( ABD+*EF-/G
16 + Push + $(-(+ ABD+*EF-/G
17 H o/p $(-(+ ABD+*EF-/GH
18 / push / $(-(+/ ABD+*EF-/GH
19 K o/p $(-(+/ ABD+*EF-/GHK
20 ) Pop / + ( $(- ABD+*EF-/GHK/+
21 ) Pop –( $ ABD+*EF-/GHK/+-
So the final out put postfix expression is: A B D + * E F - / G H K / + -
c) A*(B+(C+D)*(E↑F)/G)*H
To convert this infix into postfix, first enclose the given expression into ( ). We take use a stack
to solve the problem: (A*(B+(C+D)*(E↑F)/G)*H)

SNo Symbol Action Stack Output


Scanned Performed Expression
1 ( Push ( $(
2 A o/p $( A
3 * Push * $(* A
4 ( Push ( $(*( A
5 B o/p $(*( AB
6 + Push + $(*(+ AB
7 ( Push ( $(*(+( AB
8 C o/p $(*(+( ABC
9 + Push + $(*(+(+ ABC
10 D O/P $(*(+(+ ABCD
11 ) Pop + ( $(*(+ ABCD+
12 * Push * $(*(+* ABCD+
13 ( Push ( $(*(+*( ABCD+
14 E Push E $(*(+*( ABCD+E
79
15 ↑ Push ↑ $(*(+*(↑ ABCD+E
16 F o/p $(*(+*(↑ ABCD+EF
17 ) Pop ↑, ( $(*(+* ABCD+EF↑
18 / Pop *,push / $(*(+/ ABCD+EF↑*
19 G o/p $(*(+/ ABCD+EF↑*G
20 ) Pop / + ( $(* ABCD+EF↑*G/+
21 * Pop *, push * $(* ABCD+EF↑*G/+*
22 H o/p $(* ABCD+EF↑*G/+*H
23 ) Pop * ( $ ABCD+EF↑*G/+*H*
So the final out put postfix expression is: ABCD+EF↑*G/+*H*
d) (A+B/C*D-F*T)
SNo Symbol Action Stack Output
Scanned Performed Expression
1 ( Push ( $(
2 A o/p $( A
3 + Push + $(+ A
4 B o/p $(+ AB
5 / Push/ $(+/ AB
6 C o/p $(+/ ABC
7 * Pop / push * $(+* ABC/
8 D o/p $(+* ABC/D
9 - Pop * + push - $(- ABC/D*+
10 F o/p $(- ABC/D*+F
11 * Push * $(-* ABC/D*+F
12 T o/p $(-* ABC/D*+FT
13 ) Pop * - $ ABC/D*+FT*-
So the final out put postfix expression is: ABC/D*+FT*-
e) (True && false) | | !(false | | true)
To convert this infix into postfix, first enclose the given expression into ( ). We take use a stack
to solve the problem: ((True && false) | | !(false | | true))

SNo Symbol Action Stack Output


Scanned Performed Expression
1 ( Push ( $(
2 ( Push ( $( (
3 True o/p $(( True
4 && Push && $((&& True
5 False o/p $((&& True False
6 ) Pop &&, ( $( True False &&
7 || Push | | $(| | True False &&
8 ! Push ! $(| | ! True False &&
9 ( Push( $(| | ! ( True False &&
10 False o/p $(| | ! ( True False && False
11 || Push | | $(| | ! ( | | True False && False
12 True o/p $(| | ! (| | True False && False True
13 ) Pop | |, ( $(| | ! True False && False True| |
14 ) Pop !, | |, ( $ True False && False True | | ! | |
So the final out put postfix expression is: True False && False True | | ! | |

80
f) TRUE OR FALSE AND NOTFALSE ORFALSE
To convert this infix into postfix, first enclose the given expression into ( ). We take use a stack
to solve the problem: (TRUE OR FALSE AND NOT FALSE OR FALSE).

SNo Symbol Action Stack Output


Scanned Performed Expression
1 ( Push ( $(
2 TRUE o/p $( TRUE
3 OR Push OR $( OR TRUE
4 FALSE Push && $( OR TRUE FALSE
5 AND Push AND $( OR AND TRUE FALSE
6 NOT Push NOT $( OR AND TRUE FALSE
NOT
7 FALSE o/p $( OR AND TRUE FALSE FALSE
NOT
8 OR Pop $( OR TRUE FALSE FALSE NOT
NOT,AND,OR,pu AND OR
sh OR
9 FALSE o/p $( OR TRUE FALSE FALSE NOT
AND OR FALSE
10 ) Pop OR, ( $ TRUE FALSE FALSE NOT
AND OR FALSE OR

So the final out put postfix expression is: TRUE FALSE FALSE NOT AND OR FALSE OR

2 Answer to Convert Postfix to Infix Notations (Note:comma is given in the Q. for user’s reference only)
(i) 50, 40, +, 18, 14, -, 4, *, +

SNo Symbol Action Stack Evaluation


Scanned Performed
1 50 Push 50 $ 50
2 40 Push 40 $ 50 40
3 + Calc. + $ 90 50 + 40 = push 90
4 18 Push 18 $ 90 18
5 14 Push 14 $ 90 18 14
6 - Cal. - $ 90 4 18-14 = push 4
7 4 Push 4 $ 90 4 4
8 * Cal. * $ 90 16 4 * 4 = push 16
9 + Calc. + $ 106 90 + 16 = push 106

Ans: 106
(ii) 120, 45, 20, +, 25, 15, -, +, *

SNo Symbol Action Stack Evaluation


Scanned Performed
1 120 Push 120 $ 120
2 45 Push 45 $ 120 45
3 20 Push 20 $ 120 45 20
4 + Cal. + $ 120 65 45 + 20 = push 65
5 25 Push 25 $ 120 65 25
6 15 Push 15 $ 120 65 25 15
7 - Calc. - $ 120 65 10 25 - 15 = push 10
81
8 + Cal. + $ 120 75 65 + 10 = push 75
9 * Calc. * $ 106 120 * 75 = push 9000

Ans: 9000

(iii) 15, 3, 2, +, /, 7, +, 2, *

SNo Symbol Action Stack Evaluation


Scanned Performed
1 15 Push 15 $ 15
2 3 Push 3 $ 15 3
3 2 Push 2 $ 15 3 2
4 + Cal. + $ 15 5 3 + 2 = push 5
5 / Calc. / $3 15 / 5 = push 3
6 7 Push 7 $37
7 + Calc. + $ 10 3 + 7 = push 10
8 2 Push 2 $ 10 2
9 * Calc. * $ 20 10 * 2 = push 20
Ans: 20
(iv) 16 , 2 , 6 , + , / , 2 , * , 1 , –

SNo Symbol Action Stack Evaluation


Scanned Performed
1 16 Push 16 $ 16
2 2 Push 2 $ 16 2
3 6 Push 6 $ 16 2 6
4 + Cal. + $ 16 8 2 + 6 = push 8
5 / Calc. / $2 16 / 8 = push 2
6 2 Push 2 $22
7 * Calc. * $4 2 * 2 = push 4
8 1 Push 1 $41
9 – Calc. - $3 4 – 1 = push 3
Ans: 3
(v) 5, 6 , 4 , - , * , 4 , 1 , - , 2 , ^ , +
SNo Symbol Action Stack Evaluation
Scanned Performed
1 5 Push 5 $5
2 6 Push 6 $56
3 4 Push 4 $564
4 - Calc. - $5 2 6 - 4 = push 2
5 * Calc. * $ 10 5 * 2 = push 10
6 4 Push 4 $ 10 4
7 1 Push 1 $ 10 4 1
8 - Calc. - $ 10 3 4 – 1 = push 3
9 2 Push 2 $ 10 3 2
10 ^ Calc. ^ $ 10 9 3 ^ 2 = push 9
11 + Calc. + $ 19 10 + 9 = push 19
Ans: 19

82
(vi) 5 10 2 + * 20 10 / -
SNo Symbol Action Stack Evaluation
Scanned Performed
1 5 Push 5 $5
2 10 Push 10 $ 5 10
3 2 Push 2 $ 5 10 2
4 + Cal. + $ 5 12 10 + 2 = push 12
5 * Calc. * $ 60 5 * 12 = push 60
6 20 Push 20 $ 60 20
7 10 Push 10 $ 60 20 10
8 / Calc. / $ 60 2 20 * 10 = push 2
9 - Calc. - $ 58 60 - 2 = push 58
Ans: 58
(vii) TRUE, FALSE, TRUE, FALSE, NOT, OR, TRUE , OR,OR,AND
SNo Symbol Action Stack Evaluation
Scanned Performed
1 TRUE Push TRUE $ TRUE
2 FALSE Push FALSE $ TRUE FALSE
3 TRUE Push TRUE $ TRUE FALSE TRUE
4 FALSE Push FALSE $ TRUE FALSE TRUE
FALSE
5 NOT Calc. NOT $ TRUE FALSE TRUE TRUE NOT FALSE =
PUSH TRUE
6 OR Calc. OR $ TRUE FALSE TRUE TRUE OR TRUE
= TRUE
7 TRUE Push TRUE $ TRUE FALSE TRUE TRUE
8 OR Calc. OR $ TRUE FALSE TRUE TRUE OR TRUE
= TRUE
9 OR Calc. OR $ TRUE TRUE FALSE OR TRUE
= TRUE
10 AND Calc. AND $ TRUE TRUE AND
TRUE = TRUE
Ans: True
(viii) FALSE, TRUE, FALSE, TRUE ,NOT, OR, TRUE, OR, OR, AND

SNo Symbol Action Stack Evaluation


Scanned Performed
1 FALSE Push FALSE $ FALSE
2 TRUE Push TRUE $ FALSE TRUE
3 FALSE Push FALSE $ FALSE TRUE FALSE
4 TRUE Push TRUE $ FALSE TRUE FALSE
TRUE
5 NOT Calc. NOT $ FALSE TRUE FALSE NOT TRUE =
FALSE PUSH FALSE
6 OR Calc. OR $ FALSE TRUE FALSE FALSE OR
FALSE = FALSE
7 TRUE Push TRUE $ FALSE TRUE FALSE
TRUE
8 OR Calc. OR $ FALSE TRUE TRUE FALSE OR TRUE
= TRUE
9 OR Calc. OR $ FALSE TRUE TRUE OR TRUE
= TRUE

83
10 AND Calc. AND $ FALSE FALSE AND
TRUE = TRUE
Ans: False

E. Answers of Stack (with array & Link List)


1 void stack::push ( ) // to push an element into the stack
{ int n;
cout<<"Enter an element";
cin>>n;
if(top = =9)
cout<<"Stack Overflow!!\n";
else
data[++top] = n;
}
void stack::pop()
{ int n;
if(top = = -1)
cout<<"Stack Underflow!!\n";
else
{ n = data[top--]; cout<<"element poped: "<<n<<endl;
}
}
2 void StackofBooks::Push()
{ Book B1;
int n;
cout<<"Enter how many books you want to store: ";
cin>>n;
for(int i=0; i<n ; i++)
gets(B1.names[i]);
if(Top == 9)
cout<<"Stack is full";
else
{ ST[++Top] = B1; cout<<"New Node Pushed ";
}
}
3 void STACK :: stackpush()
{ Node *ptr;
ptr = new Node;
cout<<"Enter information for a new node: Name and Age..\n";
gets(ptr ->name);
cin>>ptr -> age;
ptr ->Link = NULL;
if(Top == NULL)
Top = ptr;
else
{ ptr -> Link = Top; Top = ptr;
}
cout<<"Element Pushed";
}
void STACK :: stackpop()
{ Node *save;
if(Top == NULL)
cout<<"Stack Empty";
else
{ save = Top;
Top = Top ->Link;
cout<< save -> name<<" " <<save -> age<< "\t Node Deleted (Poped) !!!!\n";

84
delete save;
}
}

4 void LibStack(Library *Top)


{ Library * ptr;
while(1)
{ ptr = new Library;
cout<<"Enter information for the new node of library type:\n";
cin>>ptr -> Bookid;
gets(ptr->Tilte);
gets(ptr->Author);
ptr -> next = NULL;
if(Top = NULL)
Top = ptr;
else
{ ptr ->next = Top; Top = ptr;
}
cout<<” Node Pushed…\n”;
char ch;
cout<<"Do you want to enter more Nodes....(Enter y/Y for yes)";
cin>>ch;
if(ch=='y'||ch=='Y')
continue;
else
break;
}
}
5 void StuStack(Student *Top)
{ Student * ptr;
while(1)
{ ptr = new Student;
cout<<"Enter information for the new node of library type:\n";
gets(ptr->name);
ptr -> next = NULL;
if(Top = NULL)
Top = ptr;
else
{ ptr ->next = Top; Top = ptr;
}
cout<<” Node Pushed…\n”;
char ch;
cout<<"Do you want to enter more Nodes....(Enter y/Y for yes)";
cin>>ch;

if(ch=='y'||ch=='Y')
continue;
else
break;
}
//Display a node
char n[20];
cout<<"Enter a name to be search: ";
gets(n);
for(newptr = Top; newptr != NULL ; newptr = newptr ->next)
{ if(strcmp(newptr ->name, n) == 0)
{ cout<<"Name Found!!\n"; break;

85
}
}
if(newptr = =NULL)
cout<< "Name is not found in the stack!!";
}
6 void Pop(student * Top)
{ student * save;
if(Top == NULL)
cout<<" Stack is Empty!!";
else
{ save = Top;
Top = Top -> next;
cout<<" Deleted Node Name : "<<save ->name<<endl;
delete save;
}
}
7 void ItemStack(Node *Top)
{ Node * ptr;
ptr = new Node;
cout<<"Enter information for the new node :\n";
cin>>ptr->item;
ptr -> next = NULL;
if(Top = NULL)
Top = ptr;
else
{ ptr ->next = Top; Top = ptr;
}
cout<<” Node Pushed…\n”;
}
8 void Insert (int Stack [], int & Top)
{ int n;
cout<<"Enter a new number for insertion: ";
cin >> n;
if(Top == size -1 ) // assume the size is defined globally as 100
cout<<"Stack is Full!!!";
else
{ Stack[++Top] = n; cout<< Element Inserted!!!\n";
}
// Display Stack Containts....
cout<<"Stack Top: ";
for(int i = Top ; i >= 0 ; i-- )
{ cout<<Stack[i] << "--> ";
}
cout<<"Stack End";
}
9 void Stack :: Push()
{ Node *ptr;
ptr = new Node;
cout<<"Enter information for a new node: x and y..\n";
cin>>ptr -> x>>ptr ->y;
ptr ->next = NULL;
if(Top == NULL)
Top = ptr;
else
{ ptr -> next = Top; Top = ptr;
}
cout<<"Element Pushed";

86
}
void Stack :: Pop()
{ Node *save;
if(Top == NULL)
cout<<"Stack Empty";
else
{ save = Top;
Top = Top ->Link;
cout<< save -> x<<" " <<save -> y<< "\t Node is Deleted (Poped) !!!!\n";
delete save;
}
}
10 void DelStack(Book * Top)
{ Book *ptr;
if(Top == NULL)
cout<<"Stack Empty!!!";
else
{ ptr = Top;
Top = Top -> Next;
cout<<"Deleted Book Node: "<<ptr ->Bno<<" "<<ptr ->Bname<<" \n";
delete ptr;
}
}
11 void QUEUE :: Insert()
{ Node * ptr;
ptr = new Node;
cout<<"Enter the information for the new node: ";
cin>>ptr ->P_id;
gets(ptr ->P_name);
ptr -> Link = NULL;
if(Rear = =NULL)
Rear = Front =ptr;
else
{ Rear - > Link = ptr; Rear = ptr;
}
}
void QUEUE :: Delete()
{ Node *ptr;
if(Front = = NULL)
cout<<"Queue Empty !!!";
else
{ ptr= Front;
if(Front == Rear)
Front = Rear = NULL;
else
Front = Front ->Link;
cout<<"Deleted Passanger node :"<<P_id<<" " <<P_name<<endl;
delete ptr;
}
}
12 void LQ( )
{ Item Q[50], T;
int F=-1, R=-1;
char ch;
while(1)
{ cout<<"Enter the new node information: \n";
T.getdata();

87
if(R==49)
cout<<"Queue is Full!!!";
else
{ if(F==-1)
F= R =0;
else
F++;
Q[F] = T;
cout<<"Element Inserted in Q";
}
cout<<”Do you want to insert more elements…\n”;
cin>>ch;
if(ch != 'y' )
break;
} //end of loop
}// end of Function
13 void Delete(Node *F, Node *R)
{ Node *ptr;
if(F == NULL)
cout<<”Empty Queue!!!”;
else
{ ptr = F;
if(F == R)
F = R = NULL;
else
F = F ->next;
cout<< “Node Deleted: ”<<ptr->u<< “ “ <<ptr -> v;
delete ptr;
}
}
14 struct Stu
{ int rollno;
Stu *next;
}*F, *R, *Ptr;
void Insert(Stu * F, Stu * R)
{ Stu S1;
Ptr = new Stu;
cout<<" Enter information for new node: " ;
cin>>Ptr ->rollno;
Ptr ->next = NULL;
if(R==NULL)
F = R = Ptr;
else
{ R -> next = Ptr; R = Ptr; }
} // End of Function
15 void Search(student *F, student*R)
{ student * ptr;
char n[20];
cout<<"Enter a name to be search :";
gets(n);
if(F = = NULL)
cout<<" Queue is Empty !!! ";

else
{ for(ptr = F ; ptr ! = NULL ; ptr = ptr ->next)
if( strcmp(ptr - > name, n) = = 0)
{ cout<<ptr -> name <<" Name is found "; break;

88
}
}
if (ptr = = NULL)
cout<<" Name is not found in the Queue";
}
16 void Movie_Ins(movie *F, movie * R, movie * newptr)
{ if(R = = NULL)
F = R = newptr;
else
{ R -> link = newptr;
R = newptr;
}
for(movie * ptr = F ; ptr ! = NULL ; ptr = ptr -> link)
cout<< ptr ->MNo<< " " <<ptr ->MovieName<<endl;
}
17 void QueueofBooks : : Insert()
{ Book B1;
int n;
cout<<"Enter how many books you want to store: (Max. 4)";
cin>>n;
for(int i=0; i<n ; i++)
gets(B1.names[i]);
if(Rear = = 9)
cout<<"Queue is full !!!";
else
{ if(Rear = = -1)
Front = Rear = 0;
else
Rear ++;
Q[Rear] = B1;
cout<< "Book node inserted !";
}
}
18 void INSERT(Node * front, Node * rear)
{ Node * ptr;
char ch;
while( 1)
{ ptr = new Node;
cout<<" Enter information for new node..\n";
cin>> ptr ->m>>ptr ->p;
ptr -> next = NULL;
if(rear == NULL)
front = rear = ptr;
else
{ rear ->next = ptr; rear = ptr; }
cout<<" Do you want to enter more nodes in the Queue. Enter y for yes\n”:
cin>>ch;
if(ch=='y'||ch=='Y')
continue;
else
break;
} // end of Loop
for(int i, count = 0, ptr = front ; ptr != NULL ; ptr = ptr ->next)
count ++;
cout<<”Total Number of node in the Queue = ”<<count;
}

89
Unit -4: File Handling
Total Marks=06
Q.No Questions
A. Theoretical Question
1 Why we need data files programming, explain methods to opening a data files, show the syntax.
2 Define the various file modes used to open data files?
3 Differentiate between the text and binary files? Give examples to open the both type of files.
4 Compare the ios::app and ios::ate file modes.
5 Define the following file handling functions, with their syntax:
a) read () b) write() c) seekp() d) seekg() e) eof() f) tellg() g) tellp() h) fail()

B. File handling functions related problems: (Short Answers)


1 Observe the program segment given below carefully, and answer the question that follows :
class Labrecord
{ int Expno;
char Experiment[20];
char Checked;
int Marks;
public :
void EnterExp( ); //function to enter Experiment details
void ShowExp ( ) ; //function to display Experiment details
char RChecked ( ) //function to return Expno
{return Checked;}
void Assignmarks(int M) //function to assign Marks
{ Marks = M;}
};
void ModifyMarks()
{ fstream File;
File.open(“Marks.Dat”,ios::binary|ios::in|ios::out);
Labrecord L;
int Rec = 0;
while (File.read((char*)&L, sizeof(L)))
{ if(L.RChecked( )== ‘ N ‘ )
L.Assignmarks(0)
else
L.Assignmarks(10)
_____________________ //statement 1
_____________________ //statement 2
Rec ++ ;
}
File.close ();
}
If the function ModifyMarks() is supposed to modify Marks for the records in the file MARKS.DAT based
on their status of the member Checked (containing value either Y or ‘N’).
2 Observe the program segment given below carefully and write C++ statements for the
statement 1 and statement 2. Where statement 1 is required to position the file write pointer
to an appropriate place in the file and statement 2 is to perform the write operation with the
modified record.
class PracFile
{ intPracno;
char PracName[20];
int TimeTaken;
int Marks;
public:
90
void EnterPrac( ); // function to enter PracFile details
void ShowPrac( ): // function to display PracFile details
int RTime() // function to return TimeTaken
{ return TimeTaken; }
void Assignmarks (int M) // function to assign Marks
{ Marks = M; }
};
void AllocateMarks( )
{ fstreamFile;
File.open(“MARKS.DAT”,ios::binary|ios::in|ios::out);
PracFile P;
int Record = 0;
while (File.read(( char*) &P, sizeof(P)))
{ if(P.RTime()>50)
P.Assignmarks(0)
else
P.Assignmarks(10)
______________ //statement 1
______________ //statement 2
Record + + ;
3 }
File.close();
}
If the function AllocateMarks () is supposed to Allocate Marks for the records in the file
MARKS.DAT based on their value of the member TimeTaken.
Write C++ statements for the statement 1 and statement 2, where, statement 1 is required to position the
file write pointer to an appropriate place in the file and statement 2 is to perform the write operation with the
modified record.
Observe the program segment given below carefully and fill in the blanks marked as statment1 and
statement2 using write() and remove() functions for performing the required task.
#include<fstream.h>
class Emp
{ int Eno;
char name[20];
public :
void deleteRec(int Eid); //function which will delete the data of a specific employee
}eobj;
void Emp::deleteRec(int Eid)
{ fstream file;
file.open(“Emp.dat”, ios::in|ios::out | ios::binary);
ofstream ofile(“temp.dat”);
4 while(file.read((char *) this, sizeof(eobj)))
{ if( this -> Eno != Eid)
_________________//statement1
}
________________//statement 2
rename(“temp.dat”,”Emp.dat”);
}
Following program intends to display a text file with each word in new line.
#include<fstream.h>
void main()

91
{ ifstream fin(“abc.txt”);
char word[20];
while( !fin.eof() )
5 { _______________ //statement 1
cout<<word<<endl;
}
_______________ //statement 2
}
Complete the above program by providing missing functionality.

Observe the program segment given below carefully and fill the blanks marked as statement 1 and statement
2 using seekg() and tellg() functions for performing the required task:
#include<fstream.h>
class employee
{ int Eno; char Ename[20];
public:
int countrec(); //Function to count the total number of record
};
int employee :: countrec()
{ employee item;
fstream file;
file.open(“EMP.DAT”,ios::binary|ios::in);
6 ------------------------ //statement 1
int Bytes = -------------------- //statement 2
int count = Bytes / sizeof(item);
file.close();
return count;
}

Observe the program given below carefully and fill the blanks marked as ST1, ST2, ST3 and ST4 for
performing the required task.
#include<fstream.h>
class COOLDRINKS
{ int dcode;
char dname[10]; int dsize;
float dprice;
public:
void getdrinks()
{ cin>>dcode>>dname>>dsize>>dprice;}
void showdrinks()
{ cout<<dcode<<dname<<dsize<<dprice;}
};
void read(); /* General functions to call the class member function.*/
void show();
void main()
{ read();
show();
}
void read() //Definition of read()
{ COOLDRINKS DR1; // declares the class object
------------------------- // ST1 declare the file object
afile.open(“drinks.dat”, ios::app|ios::binary);
DR1.getdrinks(); // call the member function to input data.
afile.write((char *)&DR1, sizeof(COOLDRINKS));
------------------------ // ST2 close the file.
}
void show() //Definition of show()

92
7 { COOLDRINKS DR1;
fstream bfile;
------------------------ // ST3 open the file for reading.
bfile.read((char *)&DR1, sizeof(COOLDRINKS));
------------------------ // ST4 display the record.
bfile.close();
}
Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement
2 using seekg() and tellg() functions for performing the required task.
#include <fstream.h>

class Student
{ int roll; char sname[20];
public:
int recordcount(); //Function to count the total number of records
};
int Item::recordcount()
{ fstream fillin;
fillin.open(“STUD.DAT”,ios::binary|ios::in);
8 ______________________ //Statement 1
int Bytes = ______________________ //Statement 2
int c = Bytes / sizeof(Item);
fillin.close();
return c;
}

Observe the following program segment given below carefully and fill the blanks marked as statement 1 and
statement 2 using seekp() and seekg() functions for performing the required task.
#include < fstream.h>
class sound
{ int sno; sitem[20];
public:
void found(int); // function to search and display the content from a particular record number
void modify(int); // function to modify the content of a particular record number
};
void sound::found(int recno)
{ fstream ofile;
ofile. Open(“things.dat”, ios::binary | ios ::in | ios::out);
_________________________________________ // statement 1
ofile. read( (char*) this , sizeof(sound) );
cout<<sno<<”==”<<sitem<<endl;
ofile.close();
}
void sound ::modify(int recno)
{ fstream ofile;
9 ofile. open (“things.dat”, ios::binary | ios::in | ios::out);
cout<<sno;cin.getline(sitem,20);
__________________________________ // statement 2
ofile.write ((char*)this, sizeof(sound));
ofile.close();
}

class Book
{ int Bookno;
char Book_name[20];
public:
void enterdetails(); //function to enter book details

93
void showdetails(); //function to display details
int retbno() // return book no
{ return Bookno; }
};
void Modify(Book New) //function to replace a particular object in file by argument obj
{ fstream File;
File.open("Book.dat", ios::binary | ios:: in | ios:: out);
Book OB;
int Rec=0, F=0;
while(File.read((char *) & OB, sizeof(OB)) && ! F)
{ Rec++;
if(New.retbno() = = OB.retbno())
{ -----------------------------------------//Statement 1
File.write((char * ) & New,sizeof(New));
F=1;
}
}
if(!F)
cout<<"Record for modification does not exist!!";
File.close();
}

C. Functions for file I/O operations


1 Write a function to store percentage marks of 20 students of computer subject into a file “HYM.txt”.
2 Write a function to store a set of customer’s record into a file “customer.dat”.
struct Customer
{ int customer_id;
char name[20];
float order_amount;
};

3 Write a function appenddata() to open the file “customer.dat” that is defined in the q. no. 2 above and append
it by add 5 more customer record.

4 Declare a structure telerecwhich contains name (20 characters) and telephone number. Write a function to
create a binary file “Tele.dat” to stores data of the type telerec. The function will store 3 records into file and
display them.

5 Assume a binary file FUN.DAT is containing objects belonging to a class LAUGHTER (as defined below).
Write a user defined function in c++ to add one more object belonging to class LAUGHTER at the bottom of
it.
class LAUGHTER
{ int idno;
char type[5];
char Desc[255];
public:
void newentry()
{
cin>>idno; gets(type); gets(Desc);
}
void display()
{
cout<<idno<<”: “<<Type<<endl<<Desc<<endl;
}
};
6 Write a function in c++ to count the total number of alphabets present in the text file “dataone.txt”. Imagine
the file has been already with some amount of text data.

94
7 Assuming that a text file named “TEXT1.TXT” already contains some text written into it, write a function
named vowelwords(), that reads the file TEXT1.TEXT and creates a new file named “TEXT2.TXT”, which
shall contain only those words from the file TEXT1.TXT which does not 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 and When it Rains.
8 Write a function in C++ to read the content from a text file NOTES. TXT, count and display the number of
Words present in it.

9 Write a function in C++ tocount of the word the/The as an independent word in a text file “STORY.TXT”.
For example, if the content of the file STORY.TXT is
There was a monkey in the zoo. The
monkey was very naughty.
Then the output of the program should be 2.

10 Given a binary file SPORTS.DAT, containing records of the following structure type :
struct Sports
{char Event[20];
char Participant[10][30];
};

11 Write a function in C++ that would read contents from the file “SPORTS.DAT” and creates a file named
ATHLETIC.DAT copying only those records from SPORTS.DAT where the event name is “Athletics”.

12 Write a function in C++ which will print the text file “story.txt” in reverse form. For example , if the file is
having - computer science is my best subject.
Then the output will be: tcejbus tseb ym si ecneics retupmoc.

13 Write a function to count the number of VOWELS present in a text file named “PARA.TXT”.

14 Write a function in C++ to count and display the number of words starting with capital alphabet like
‘Kamlesh’ or ‘Tourist’etc. present in a text file “poem.txt”.
Example: If the file “poem.txt” contains the following lines,
Kamlesh is captain of Udaipur cricket team.
Tourist generally visit Zoo of Udaipur.
Today telephone is dead, please note down complain.
The function should display the output as 6
15 Given a binary file “BUS.DAT”, containing records of the following class bus type.
class bus
{ int bus_no;
char desc[40];
int distance; //in km
public:
void bus::read()
{ cin>>bus_no; gets(desc) ; cin>>distance; }
void bus::display()
{ cout<<bus_no; puts(desc); cout<<distance; }

int bus::retdist()
{ return distance; }
};
Write a function in C++ that would read contents of file “BUS.DAT” and display the details of those buses
which travels distance more than 100 km.
16 Assuming the class EMP given below, write functions in C++ to perform the following:-
a. Write the objects of EMP to binary file.
b. Reads the objects of EMP from binary file and display them on screen.

95
class EMP
{ int Eno;
char Ename[0];
public:
void Getit(){ cin>> Eno; gets(Ename); }
void Showit() { cout<< Eno<<Ename;<<endl; }
};
17 Write a C++ program, which reads one line at a time form the disk file “TEST . TXT”, and displays it to a
monitor. Your program has to read all the contents of the file. Assume the length of the line not to exceed 80
characters. You have to include all the header files if required.

18 Following is the structure of each record in a data file named “Colony.dat”


struct Colony
{ char colony_code[10];
char colony_name[10];
int no_of_people;
};
Write a function to update the file with a new value of No_of_people of a particular colony code. The
function will increment the value of no_of_people and display all records after modification.

19 Write a function in C++ which read the content of a text file “Doc.txt” and count and print the statistics of the
file as follows:
total alphabets: total digits: total Sp. Characters:
size of the file in form of bytes:

20 Write a function in C++ which will increase the qty of a particular type of item from the file “stock.dat” .
Assuming that the binary file is containing the records of following structure :

struct Products
{ int id, type, qty; char Iname[30];
}; note: Accept the item type and new qty (to be increased) from user.

21 Assuming a binary file “Jokes.dat” is containing objects belonging to a class Joke(as defined below).Write a
user defined function in C++ to add more objects belonging to class Joke at the bottom of it
class JOKE
{ int Jokeid;
char Type[5];
public:
void getjoke()
{ cin>> Jokeid;
cin>> Type;
}
void display()
{ cout<< Jokeid;
cout<< Type;
}
};
22 Given a binary file Apply.dat, containing records of the following class Applicant type.
class Applicant
{char a_rno[10];
char a_name[30];
int a_score;
public:
void enroll()
{ gets(a_rno);gets(a_name);cin>>a_score;
}
void status()

96
{ cout<<setw(12)<<a_admno;
cout<<setw(32)<<a_name;
cout<<setw(3)<<a_score<<endl;
}
int returnscore()
{ return a_score;
}
};
Write a function in C++, that would read contents of file APPLY.DAT and display the details of those
applicants whose a_score is in between 75 and 90.

23 Write a function in C++ to open binary file “stock.dat”, which contains a set of records of following structure
Products. The function will display the full records having the type is “Electronics”.
struct Products
{ int id, type;
char Iname[30];
};

24 In an organization, the monthly salary of employees gets deposited in a bank. The bank gives interest of 2.5%
per month. At the end of the month the bank sent detailed information of the employees to the organization in
a binary file named “CUST.DAT”. Write a function in C++ to calculate the interest and display it from
“CUST.DAT”, assuming the binary file is containing the objects of the following class:
class ORG
{ char Account_holder_name[20];
int Account_Number;
float Balance;
public:
float retbalance( )
{ return Balance; }
void display( )
{ cout<<Account_holder_name<<Account_number<<Balance; }
};

25 Write a function InsFile() in c++, which open the data file “Story” and add some more data records in the file
without deleting the previous content. The file Story has already contains a set of data records belong to the
following structure. Display all the records in the file at output.
struct serial
{char Title[50], Author[30];
int length;
};
Write a function DispFile() in c++, which open the data file “Story” (as given in the above question no. 6. )
and search a particular Author’s record in file. If found then display the record at output?

97
Answers to Unit -4: Data File Handling
Total Marks=06
QNo. Answers
A.
1 Data files are needed to store program data permanently, so they can be utilise forever by this
program and some other programs also.
To open a data file there are 2 methods:
a) constructor method: constructor of stream class will create a data file and open it for the
program. Syntax: filestream StreamObject (“File name”);
b) using open(): this function also help us to open one or more data file in a program. It is
used when a program is having more than one file.
Syntax: Filestream streamobject;
Streamobject . open(“File name”, file modes);
2 The file modes are used to specify how a file is to be used, e.g. for read, for write or append. The
various file modes are:
a. ios::in – open a file for reading file content (i/p mode), stream type is ifstream.
b. ios::out - open a file for writing (o/p mode), stream type is ofstream.
c. ios::app - open a file for writing in append mode (o/p mode), stream type is ofstream.
d. ios::binary – open a binary file, by default files are opened in text mode. This is in both
stream.
e. ios::nocreate – open a file which is already exist, if not than it fails the open().
f. ios::noreplace – open a new file which should not be exists already, otherwise it fails.
3 Text file stores information in ASCII codes and every line is terminated with a special end of line
character. Some internal translation required when i/o data. Binary files strores the information in
the same as they are in memory, so no translation required. No delimiter required in line. E.g.
ofstream fout (“Filename.txt”); // open text file
ofstream fout;
fout.open(“filename.dat”, ios::out | ios::binary);
4 ios::app mode is used for appending a file and ios::ate mode can be used for appending or reading
both.
5 a) read() : This is a ifstream function, used for reading file contents as a stream/ bunch of
bytes. It is used for inputting a set of data like: array, structure or class objects etc.
Syntax: streamobject . read((char *) &buf, sizeof(buf));
b) write() : This is a ofstream function, used to write a bunch of bytes into file. The data
written by write (), can be readed only by read().
Syntax: streamobject . write((char *) &buf, sizeof(buf));
c) seekp(): This is a ofstream function, used to move the put pointer in a file at a particular
position. Syntax: streamobject.seekp(offset, direction);
direction: ios::beg, ios::end and ios::cur
offset: a number give number of bytes to move from the direction
d) seekg(): This is a ifstream function, used to move the get pointer in a file at a particular
position. Syntax: streamobject.seekg(offset, direction);
direction: ios::beg, ios::end and ios::cur
offset: a number give number of bytes to move from the direction
e) eof() : This is used to tell the compiler that the file is ended
f) tellg() : This is used to return the current position of get pointer in the file. It return a
number.
g) tellp() : This is used to return the current position of put pointer in the file. It return a
number.

98
h) fail() : This return a true, if a particular file operation has failed.

B. File handling functions related problems: (Short Answers)


1 File.seekp((Rec) * sizeof(L)); // Statement 1
File.write((char *) & L, sizeof(L)) // Statement 2

2 File.seekp((Record ) * sizeof(P)); // Statement 1


Or
File.seekp(File.tellg() - sizeof(P)); // Statement 1
File.write((char *) & P, sizeof(P)) // Statement 2

3 file.write((char *) this, sizeof(eobj)) // Statement 1


remove(“Emp.dat”); // Statement 2

4 fin>>word; //Statement 1
fin.close(); // Statement 2

5 file.seekg(0,ios::end); //Statement 1
file.tellg(); // Statement 2

6 ofstream afile; // ST 1
afile.close(); // ST 2
bfile.open(“drinks.dat”, ios::in | ios::binary); // ST 3
DR1.showdrinks(); // ST 4

7 fillin.seekg(0,ios::end); //Statement 1
fillin.tellg(); // Statement 2

8 ofile.seekg(recno); //Statement 1
ofile.seekp(recno); // Statement 2

9 File.seekp((Rec-1) * sizeof(New));

C. Answers to Functions for file I/O operations


1 void EnterMarks()
{ int marks;
ofstream fout("HYM.TXT");
for(int i=0 ; i<20 ; i++)
{ cout<<"enter marks of student "<<i+1<<" : " ;
cin>>marks;
fout<<marks;
}
fout.close();
}
2 void CustRec()
{ customer c;
char ch;
ofstream fout("customer.dat");
while(1)
{ cout<<"enter record of customer : " ;
cout<<"enter id : "; cin>>c.customer_id;
cout<<"enter name : "; gets(c.name);
cout<<"enter order amount : "; cin>>c.order_amount;
fout.write((char *) & c, sizeof (c));
cout<<"Do you want ot enter more records, Enter Y for Yes: ";
cin>>ch;
if(ch=='y'||ch=='Y')

99
continue;
else
break;
}
fout.close();
ifstream fin("customer.dat"); //reopen the file to print the record of file
while(fin.read((char *) & c, sizeof (c)))
{ cout<<"\n id : "; cout<<c.customer_id;
cout<<"\n name : "; puts(c.name);
cout<<"\n order amount : "; cout<<c.order_amount;
}
fin.close();
}
3 void AppRec()
{ customer c;
int i =1;
ofstream fout;
fout.open("customer.dat", ios::app);
while(i<=5)
{ cout<<"enter record of customer : "<<i<<endl ;
cout<<"enter id : "; cin>>c.customer_id;
cout<<"enter name : "; gets(c.name);
cout<<"enter order amount : "; cin>>c.order_amount;
fout.write((char *) & c, sizeof (c));
i++;
}
fout.close();
}
4 struct telerec
{ char name[20];
long no;
};
void TeleRec()
{ telerec t;
int i = 1;
ofstream fout;
fout.open("Tele.dat", ios::out | ios::binary);
while(i<=3)
{ cout<<"enter record of Telephone customer : " ;
cout<<"enter name : "; gets(t.name);
cout<<"enter phone no. : "; cin>>t.no;
fout.write((char *) & t, sizeof (t));
i++;
}
fout.close();
ifstream fin;
fin.open("Tele.dat", ios::in | ios::binary); //reopen the file to print the record of file
while(fin.read((char *) & sizeof (t)))
{ cout<<"\n name : "; puts(t.name);
cout<<"\n Phone no. : "; cout<<t.no;
}
fin.close();
}
5 void append()
{ fstream afile;
afile.open("FUN.DAT", ios::binary | ios::app);
LAUGHTER LAUG;

100
int n,i;
cout<<" How many objects you want to add: ";
cin>>n;
for(i=0 ; i<n ; i++)
{ LAUG.Newentry();
afile.write((char *) & LAUG, sizeof(LAUG));
}
afile.close();
}
6 void Countalpha()
{ ifstream afile;
afile.open("dataone.txt");
char ch;
int n = 0;
while(afile)
{ afile.get(ch);
if(isalpha(ch))
n++;
}
cout<<" Total number of alphabets are: "<<n;
afile.close();
}
7 void Vowel()
{ fstream afile, bfile;
char *ch;
afile.open("TEXT1.TXT", ios::in);
bfile.open("TEXT2.TXT", ios::out);
while(!afile.eof())
{ afile>>ch;
if(ch[0] != 'A' && ch[0] != 'E' && ch[0] != 'I' && ch[0] != 'O' && ch[0] != 'U' )
bfile<<ch;
}
afile.close();
bfile.close();
}
8 void Words()
{ ifstream IP("NOTES.TXT", ios::in);
char ch;
int count=0;
while(!IP.eof())
{ IP.get(ch);
if(isspace(ch))
count++;
}
IP.close();
cout<<"Total number of words = "<<count;
}
9 void Countthe()
{ fstream afile("STORY.TXT", ios::in);
char ch[50];
int count=0;
while(!afile.eof())
{ afile>>ch;
if(strcmpi(ch, "the")==0)
count++;
}
afile.close();

101
cout<<"Total number of words = "<<count;
}
10 void Athletics()
{ fstream afile, bfile;
Sports S;
afile.open("SPORTS.DAT", ios::in);
bfile.open("ATHLETICS.DAT", ios::out);
while(afile.read((char *) &S, sizeof(S)))
{ if(strcmp(S.Event, "Athletics" ) ==0)
bfile.write((char *) &S, sizeof(S));
}
afile.close();
bfile.close();
getch();
}
11 void ReverseFile()
{ clrscr();
ifstream IP("story.txt", ios::in);
char ch;
int i=-1,r;
IP.seekg(0,ios::end);
r=IP.tellg();
do {
IP.seekg(i,ios::end);
IP.get(ch);
cout<<ch;
i--;
r--;
}while(r>0);
IP.close();
getch();
}
12 void countcowel()
{fstream afile;
char ch;
int count=0;
afile.open("PARA.TXT", ios::in);
while(!afile.eof())
{ afile>>ch;
ch=toupper(ch);
if(ch == 'A' || ch == 'E' || ch == 'I' || ch== 'O' ||ch== 'U' )
count++;
}
afile.close();
cout<<" Total Vowels : "<<count;
}
13 void CountTitle()
{ ifstream afile;
char ch[20];
int count=0;
afile.open("r1.TXT", ios::in);
while(!afile.eof())
{ afile>>ch;
if(isupper(ch[0]))
count++;
}
afile.close();

102
cout<<"Total number of words having capital Title: "<<count;
}
14 void BusDetails()
{ ifstream fin;
bus S;
fin.open("BUS.DAT", ios::in);
while(fin.read((char *) &S, sizeof(S)))
{ if((S.retdist() > 100)
S.display();
}
fin.close();
}
15 a). void Write()
{ ofstream fout;
EMP S;
int i=0,n;
fout.open("BUS.DAT", ios::out);
cout<<"Enter how many object you want to enter in to file: ";
cin>>n;
while(i<n)
{ S.Getit();
fout.write((char *) &S, sizeof(S));
i++;
}
fout.close();
}
b). void Read()
{ ifstream fin;
EMP S;
fin.open("BUS.DAT", ios::in);
cout<<"Employee Records from File Are:\n";
while( fin.read((char *) &S, sizeof(S)))
{ S.Showit();
cout<<"\n";
}
fout.close();
}
16 #include<fstream.h>
void main()
{ ifstream afile("r1.TXT", ios::in);
char ch[80];
int i=1,count=0;
while(!afile.eof())
{ afile.getline(ch,80);
cout<<"Line "<<i<<": "<<ch<<endl;
count++;
}
afile.close();
cout<<"Total number of Lines = "<<count;
}
17 void Colony_Modify()
{ fstream afile("Colony,dat", ios::out|ios::in);
Colony c;
char m[10];
int n, pos=0;
cout<<"Enter the colony code and new value of no of people to modify : ";
cin>>m>>n;

103
while(afile.read((char *) & c, sizeof(c)))
{
if(strcmp(c.colony_code,m)==0)
{ c.no_of_people +=n;
afile.seekp((pos)*sizeof(c));
afile.write((char *) & c, sizeof(c));
cout<<"record modified";
break;
}
pos++;
}
afile.seekg(0);
cout<<"records after modification:\n";
while(afile.read((char *) & c, sizeof(c)))
cout<<c.colony_code<<" "<<c.colony_name<<" "<<c.no_of_people<<endl;
afile.close();
}
18 void CountChar()
{ ifstream afile("r1.TXT", ios::in);
char ch;
int counta=0, countb=0, countc = 0, size =0 ;
while(afile>>ch)
{
if(isalpha(ch))
counta++;
else if(isdigit(ch))
countb++;
else if(ispunct(ch))
countc++;
else
continue;
}
afile.seekg(0,ios::end);
size =afile.tellg();
afile.close();
cout<<" Total alphabets : "<<counta<<" Total digits : "<<countb<<" Total Sp. Character :
"<<countc;
cout<<" Total Size of File : "<<size;
}
19 void Increase()
{ fstream fin("stock.dat", ios::out|ios::in | ios::binary);
Products p;
int t;
int n, pos=0;
cout<<"Enter the type of product and new value of qty (quantity) of product to modify : ";
cin>>t>>n;
while(fin.read((char *) & p, sizeof(p)))
{ if(p.type == t)
{ p.qty +=n;
fin.seekp( (pos) * sizeof(p) );
fin.write( (char *) & p, sizeof(p) );
cout<<"record modified";
break;
}
pos++;
}
fin.seekg(0);

104
cout<<"records after modification:\n";
while(fin.read((char *) & p, sizeof(p)))
cout<<p.id<<" "<<p.Pname<<" "<<p.type<<" "<<p.qty<<endl;
fin.close();
}

20 void Append()
{ ofstream file;
file.open("Jokes.dat", ios::binary | ios::app);
JOKE J;
int n, i;
cout<<" How many objects you want to add: ";
cin>>n;
for(i=0 ; i<n ; i++)
{ J.getjoke();
file.write((char *) & J, sizeof(J));
}
file.close();
}
21 void Display()
{ ifstream file("APPLY.DAT", ios::binary | ios::in);
Applicant J;
while(file.read((char *) & J, sizeof(J)))
{ if(J.returnscore() >=75 && J.returnscore()<=90)
J.status();
}
file.close();
}
22 void CalcINT()
{ ifstream file("CUST.DAT", ios::binary | ios::in);
ORG obj;
float intr;
while(file.read((char *) & obj, sizeof(obj)))
{ intr = obj.retbalance()*0.025;
obj.display();
cout<<" Interest calculated : "<<intr<<endl;
}
file.close();
}

105
Unit -5: Database & SQL
Total Marks=08
Q.N. Questions
A. Database and SQL Theory
1 Define the following terms used in the database:
Relation, Tuple, Degree, Cardinality, Domain, Attribute
2 What is the importance of a Primary Key in a table? Explain with a suitable example.
3 What do you understand by DDL and DML? Write at least two DDL and DML commands.
4 What do you understand by Foreign Key and Primary Key in a relation?
5 What is a relation? What is the difference between a Tuple and an attribute?
6 What are the main advantages of database? Explain the various level of database abstraction
(Implementation)?
7 What is a Key? Define the various keys used in database in brief?
8 Define the following operation in relational algebra, with example:
a) Union b) Set Difference c) Intersection d) Cartesian Product
9 What is a View? Write syntax to create a view from a table.
10 Differentiate between relational data model and network data model?

B. Relational Algebra
1 Consider the following relation Customer and write the relational algebra statements for the following
problems:
Supp_C Supp-name Status City
ode
1 Raj 10 Delhi
2 Vinay 30 Mumbai
3 Anuj 40 Bangalore
4 Sandeep 50 Jaipur
5 Rakesh 60 Delhi
(a) Select the records of Delhi city.
(b) Display Supp-name with Status, where the status is >=40.
(c) Display the Supp_Code and name
2 Song Drama
Rollno Name age
Rollno Name age 1 r 14
1 r 14 2 p 13
3 x 14 3 x 14
5 y 15 7 z 15
7 z 15 8 m 14

Consider the above two tables drama and song perform the following operations in relational algebra:
(a) Drama U Song
(b) Song- Drama
(c) Drama ∩ Song
3 Consider the following relation Item andWrite down the relation algebra statement for the following
questions:
Item code Item name Price
1 Milk 15.00

106
2 Bread 10.00
3 Cake 7.50
4 Biscuit 14.00
5 Ice cream 18.00
(a) Select the tuples having Item name=”Bread”.
(b) Select column Item name and Price where price is >=12.00
4 Consider the following relation Student and answer the following questions.

Roll Name Course Class Section


1 Punnet Computer 12 A
2 Rohit Electronics 12 B
3 Rahul Commerce 12 C
4 Rakesh Computer 12 A
5 Yatin Computer 12 A
6 Jish Civil 12 D
7 Vidhi Electronics 12 B
a) ∏ Roll, Name (Student)
5 b) ∏ Class, Section (σ Section =’A’ )(Student)
Consider the following relation and perform the relational operation:
Customer:
id Name Banker name Amount Balance

C001 Mohit Reva 21000 22000


C002 Ramesh Ajit 10000 25000
C003 Kalpana Ajit 5000 35000
C004 Sonali Reva 12000 22000
C005 Ajay Kamal 5000 13000
1) Find out the name of customer who has their amount more than 10000 from the relation Customer.
2) Find the name of customer with their Balance from the relation customer.
3) Find out the name and id of customer with the banker “Ajit”.

C. SQL Commands
1 Create a table Salesperson that stores following data:
name (not null), scode as primary key, city, commrate (not null)
Write SQL statements for the following operations in the table salesperson
(a) Insert a record (1, ram kumar, Mumbai, 0.20)
(b) Update the commrate by 0.25 of all Mumbai city salesperson.
(c) Add a new column phone
2 Write SQL commands for the following questions on the basis of table INTERIORS:
No Itemname Type St_Date Price Discount
1 Red rose Double bed 23/02/02 32000 15
2 Soft touch Baby cot 20/01/02 9000 10
3 Jerry’s home Baby cot 19/02/02 8500 10
4 Rough wood Office table 01/01/02 20000 20
5 Comfort zone Double bed 12/01/02 15000 20
6 Jerry look Baby cot 24/02/02 700 19
7 Lion king Office table 20/02/02 16000 20
8 Royal tiger Sofa 22/02/02 30000 25
9 Park sitting Sofa 13/12/01 9000 15
10 Dine paradise Dining table 19/02/02 11000 15
a) To show all information about the sofa from the given table, in order of Price.
b) Display Itemname and Price having Discount >=15.
c) Display sum of item Pricesin each Type group.
107
d) Update the table INTERIORS by replacing the Discount by 25 for the items having
Price >=20000.
e) Show all Baby cot Type items in the table.
Write a SQL create table command to create a table Children_home contains following information.
Takeappropriate data types and declare all the constraints.
3 child_id as primary key, name of child as not null, age, dob (date of birth) check dob <=01/01/2005,
father name as not null, address as not null, phone.
Write SQL commands for the following questions on the basis of the table Tourist.
4 Table: - Tourist
Tcode NAME Age Agency Package Amount Travel Date
101 Raghavendra 26 Cross Road 10000 23-Jan-2004
102 Hardeep 30 Go Places 12000 12-Dec-2003
103 Shazia 32 Cross Road 8000 14-Feb-2004
105 Lizza 35 Cross Road 9000 01-Jan-2004
108 Diena 28 Go Places 15000 19-Mar-2004
110 Harry 34 Go Places 22000 02-Feb-2003
111 Amit 31 Cross Road 13000 14-Apr-2004
112 Denniel 42 Go Places 9000 28-Jun-2004
a) Display Name and Age of all tourists with their Age in descending order.
b) Display Sum of Package Amount for each of the agency.
c) Display name age and Package amount of each tourists having age >=28 and <=35
and the name of agency is Go Places.
d) Count the Name of Tourist belongs to each agency.
Consider the following table Book_Record and write the following Queries in SQL.
5
Sno Title Author Type Pub Qty Price
1 Data structure Sahni DS Macgraw 4 377
2 Computer fundamental Rajaraman FND Tmh 5 300
3 Mastering c++ Kanetkar Prog Bpb 11 210
4 Programming in C++ E . bala Prog Bpb 20 175
5 Networking Tanenbaum n/w Tmh 14 270
6 Programming in C E . bala Prog Bpb 25 160
(a) Select all Prog type books published by Bpb.
(b) Select all books having Qty > 10, sort them by Price in descending order.
(c) Select minimum Price book of Prog type.
(d) Count the number of books published by each Pub (publisher).
(e) Display total number of books in Book_Record and Average Price of books.
(f) Select the Max. and Min. Price of each Pub.
Employees:
6 Empid Firstname Lastname Address City
010 Ravi Kumar Raj nagar GZB
105 Harry Waltor Gandhi nagar GZB
152 Sam Tones 33 Elm St. Paris
215 Sarah Ackerman 440 U.S. 110 Paris
244 Manila Sengupta 24 Friends street New Delhi
300 Robert Samuel 9 Fifth Cross Washington
335 Ritu Tondon Shastri Nagar GZB
400 Rachel Lee 121 Harrison St. New York
441 Peter Thompson 11 Red Road Paris

EmpSalary:
Empid Salary Benefits Designation
010 75000 15000 Manager
105 65000 15000 Manager
152 80000 25000 Director
215 75000 12500 Manager
108
244 50000 12000 Clerk
300 45000 10000 Clerk
335 40000 10000 Clerk
400 32000 7500 Salesman
441 28000 7500 Salesman
Write the SQL commands for the following (on the basis of above tables) :
(i) To show details of all employees living in Paris from table Employees.
(ii) To display the content of Employees table in descending order of Firstname.

(iii) To display the Firstname, Lastname and Total Salary of all Managers from the tables
Employee and EmpSalary, where Total Salary is calculated as Salary+Benefits.
(iv) To display the maximum Salary among Managers and clerks from the table EmpSalary.
(v) To display the Firstname, Salary and Designation of all employees.
Give the Output of following SQL commands:
(i) Select Firstname, City, Designation From Employees E1, EmpSalary E2 Where E2.Designation
= ‘Salesman’ and E1.Empid=E2.Empid;
(ii) Select count(distinct Designation) from EmpSalary;
(iii) Select Designation, sum(Salary) from EmpSalary group by Designation having count(*) >2;
(iv) Select sum(Benefits) from EmpSalary where Designation =’Clerk’;
Consider the following table GRADUATE and write the following Queries in SQL.
7 TABLE : GRADUATE
Sno Name Stipend Subject Average Div
1 KARAN 400 PHYSICS 68 I
2 DIWAKAR 450 COMP. Sc. 68 I
3 DIVYA 300 CHEMISTRY 62 I
4 REKHA 350 PHYSICS 63 I
5 ARJUN 500 MATHS 70 I
6 SABINA 400 CHEMISTRY 55 II
7 JOHN 250 PHYSICS 64 I
8 ROBERT 450 MATHS 68 I
9 RUBINA 500 COMP. Sc. 62 I
10 VIKAS 400 MATHS 57 II

(a) List the names of those students who have obtained Division II sorted by Name.
(b) Display a report, listing Name, Stipend, Subject and amount of stipend received in a
year assuming that the Stipend shown in table is paid for a month.
(c) To count the number of students, who are either PHYSICS or COMP. Sc. graduates.
(d) To insert a new row in the GRADUATE table:
11,”KAJOL”, 300, “COMP. Sc.”, 75, ‘I’
(e) Give the output of following sql statement based on table GRADUATE:
(i) Select MIN(AVERAGE) from GRADUATE where Subject=”PHYSICS”;
(ii) Select SUM(Stipend) from GRADUATE WHERE Div=’I’;
(iii) Select AVG(Stipend) from GRADUATE where Average>=65;
(iv) Select COUNT(distinct Subject) from GRADUATE;
Consider the following table SchoolBus and write the following Queries in SQL.
8 Table : SchoolBus
Rtno Area_Covered Capacity Noofstudents Distance Transporter Charges
1 Vasant kunj 100 120 10 Shivamtravels 100000
2 Hauz Khas 80 80 10 Anand travels 85000

109
3 Pitampura 60 55 30 Anand travels 60000
4 Rohini 100 90 35 Anand travels 100000
5 Yamuna Vihar 50 60 20 Bhalla Co. 55000
6 Krishna Nagar 70 80 30 Yadav Co. 80000
7 Vasundhara 100 110 20 Yadav Co. 100000
8 Paschim Vihar 40 40 20 Speed travels 55000
9 Saket 120 120 10 Speed travels 100000
10 Jank Puri 100 100 20 Kisan Tours 95000
(a) To show all information of School Bus where capacity is more than the no of student in order of
Rtno.
(b) To show Area_Covered for buses covering more than 20 km., but charges less then 80000.
(c) To show transporter wise total no. of students traveling.
(d) Display avg. Charges of all Transporters covers Distance >10.
(e) To show Rtno, Area_Covered and average cost per student for all routes, where average cost per
student is:Charges/Noofstudents.
Consider the following tables Consignor and Consignee. Write SQL commands for the statements (i)
9 to (iv) and give outputs for SQL queries (v) to (vii).
TABLE : CONSIGNOR
CnorlD CnorName CnorAddress City
ND01 R Singhal 24 ABC Enclave New Delhi
ND02 Amit Kumar 123, Palm Avenue New Delhi
MU15 R Kohli 5/A, South Street Mumbai
MU50 S Kaur 27-K, Westland Mumbai

TABLE : CONSIGNEE
CneelD CnorlD CneeName CneeAddress CneeCity
MU05 ND01 Rahul Kishore 5, Park Avenue Mumbai
ND08 ND02 P Dhingra 16/J, Moore Enclave New Delhi
KO19 MU15 A P Roy 2A, Central Avenue Kolkata
MU32 ND02 S Mittal P-245, AB Colony Mumbai
ND48 MU50 B P Jain 13, Block D, A Vihar New Delhi
(i) To display the names of all Consignors from Mumbai.’
(ii) To display consignee details in ascending order of CneeName.
(iii) Display the CnorNames and CneeNames
(iv) To display number of consignors from each city,
(v) SELECT DISTINCT CneeCity FROM CONSIGNEE;
(vi) SELECT CneeName, CneeAddress
FROM CONSIGNEE
WHERE CneeCity NOT IN (‘Mumbai’, ‘Kolkata’);
(vii) SELECT CneelD, CneeName
FROM CONSIGNEE
WHERE CnorID=’MU15' OR CnorID=’ND01';
Write the SQL commands for (i) to (v) and output for (vi) on the basis of the table HSOPITAL:
10 Table: HOSPITAL
No Name Age Department Dateofadm Charges Sex
1 Sandeep 65 Surgery 23/02/07 300 M
2 Ravina 24 Orthopedic 20/01/07 200 F
3 Karan 45 Orthopedic 19/02/07 200 M
4 Tarun 12 Surgery 01/01/07 300 M
5 Zubin 36 ENT 12/01/07 250 M
6 Ketaki 16 ENT 24/02/07 300 F
7 Ankita 29 Cardiology 20/02/07 800 F
8 Zareen Gynecology 22/02/07 300 F
110
9 Kush 19 Cardiology 13/01/07 800 M
10 Shailya 31 Nuclear 19/02/07 400 M
Medicine

i. To show all information about the patients of Cardiology department.


ii. To list names of all patients with their date of admission in ascending order.
iii. Update the record of Zareen and store the age as 61.
iv. To count the number of patients with age<=20.
v. Delete the record of Zubin.
vi. Give the output of following SQL statements:
a. Select Max(DISTINCT Charges) From HOSPITAL;
b. Select MIN(Age) From HOSPITAL Where Sex=’M’;
c. Select Name, Age From HOSPITAL Where Name Like “K%” ;
Consider the following tables Employee and salary. Write SQL commands for the statements (i) to (iv)
11 and give outputs for SQL queries (v) to (viii)
Table : Employee
Eid Name Deptid Qualification Sex
1 Deepali Gupta 101 MCA F
2 Rajat Tyagi 101 BCA M
3 Hari Mohan 102 B.A M
4 Harry 102 M.A M
5 Sumit Mittal 103 B.Tech M
6 Jyoti 101 M.Tech F
Table : Salary
Eid Basic DA HRA Bonus
1 6000 2000 2300 200
2 2000 300 300 30
3 1000 300 300 40
4 1500 390 490 30
5 8000 900 900 80
6 10000 300 490 89

(i) To show the name of employees in order of Deptid.


(ii) To list the names of employees, who hasBasic greater than 3000.
(iii) To print the Name & Net Salary of Employees where Net Salary is calculated as Basic + DA
+ HRA + Bonus
(iv) To increase the bonus of all employees with 200 having Qualification B.Tech or M.Tech..
(v) Select Name From Employee Where Eid=(Select Eid From Salary Where Basic= (Select
max(Basic) From Salary));
(vi) Select Avg(Basic) From Salary Where Bonus >40;
(vii) Select Count(*) From Employee Where Sex=’F’;
(viii) Select Name From Employee Where Qualification Like ‘%Tech’
Consider the following tables SCHOOL and ADMIN. Write SQL commands for the statements (i) to
12 (iv) and give outputs for SQL queries (v) to (vii).
Table: SCHOOL
Code Teacher Subject DoJoin Periods Experience
1001 Ravi Shankar English 12/03/2000 24 10
1009 Priya Rai Physics 03/09/1998 26 12
1203 Lisa Anand English 09/04/2000 27 5
1045 Yashraj Maths 24/08/2000 24 15
1123 Ganan Physics 16/07/1999 28 3
1167 Harish B Chemistry 19/10/1999 27 5
1215 Umesh Physics 11/05/1998 22 16
Table: ADMIN
Code Gender Designation
1001 Male Vice Principal
111
1009 Female Coordinator
1203 Female Coordinator
1045 Male Hod
1123 Male Senior Teacher
1167 Male Senior Teacher
1215 Male Hod

i) To Display Teacher and Periods of all teachers, whose Periods Less Than 25 and Experience is
less than 10.
ii) Display All From Table School From Where Periods are in range of 10 to 25.
iii) To Display Teacher, Code and Designation From TablesSchool And Admin For Female Teacher.
iv) To Display Code, Teacher And Subject of All Teachers Who Have Joined The School After
01/01/1999.
v) Select Max(Experience), Subject From School Group By Subject;
vi) Select Teacher, Gender From School, Admin Where Admin.Designation = ‘Coordinator’ And
School . Code = Admin . Code ;
vii) Select Designation, Count(*) From Admin
Group By Designation Having Count(*) =1;
Consider the following tables GAMES and PLAYER. Write SQL commands for the statements (i) to
(iv) and give outputs for SQL queries (v) to (viii)
13 Table: GAMES
GCode GameName Number PrizeMoney Date
101 CaromBoard 2 5000 23-Jan-2004
102 Badminton 2 12000 12-Dec-2003
103 TableTennis 4 8000 14-Feb-2004
104 Chess 2 9000 01-Jan-2004
105 LawnTennis 4 25000 19-Mar-2004
Table: PLAYER
PCode Name GCode
1 Arjun 101
2 Ravi 105
3 Jignesh 101
4 Nihir 103
5 Sohil 104
(i) To display the name of players who plays CaromBoard.
(ii) To display details of those games, where PrizeMoney more than 8000.
(iii) To display the details of those games whose name starts from character ‘B’.
(iv) To display Average PrizeMoney from GAME.
(v) Select COUNT(DISTINCT number) from GAMES;
(vi) Select MAX(date), MIN(Date) From GAMES;
Study the following tables FLIGHTS and FARES and write SQL commands for the questions (i) to
(iv) and give outputs for SQL queries (v) to (vi).
14 TABLE : FLIGHTS
FLNO STARTING ENDING NOofFLIGHTS NOofSTOPS

IC301 MUMBAI DELHI 8 0

IC799 BANGALORE DELHI 2 1

MC101 INDORE MUMBAI 3 0

IC302 DELHI MUMBAI 8 0

AM812 KANPUR BANGALORE 3 1

IC899 MUMBAI KOCHI 1 4


AM501 DELHI TRIVANDRUM 1 5

112
MU499 MUMBAI MADRAS 3 3

IC701 DELHI AHMEDABAD 4 0

TABLE : FARES
FLNO AIRLINES FARE TAX

1C701 Indian Airlines 6500 10

MU499 Sahara 9400 5

AM501 Jet Airways 13450 8

IC899 Indian Airlines 8300 4

1C302 Indian Airlines 4300 10

1C799 Indian Airlines 10500 10

MC101 Deccan Airlines 3500 4


i. Display FLNO and NOofFLIGHTS from “KANPUR” to “BANGALORE” from the table FLIGHTS.
ii. Display the contents of the table FLIGHTS in the ascending order of FL_NO.
iii. Display the FLNO and fare to be paid for the flights from DELHI to MUMBAI using the tables
FLIGHTS and FARES, where the fare to be paid = FARE +FARE*TAX%/100.
iv. Display the minimum fare offering by “Indian Airlines” in the table FARES.
v. Select FLNO, NOofFLIGHTS, AIRLINES From FLIGHTS, FARES Where STARTING=”DELHI”
And FLIGHTS.FLNO=FARES.FLNO.
vi. Select Count (Distinct ENDING) From FLIGHTS.
Write SQL commands for (a) to ( e) and write output for (f) on the basis of Teacher relation given
15 below:
No Name Age Department Date of Join Salary Sex
1. Jigar 34 Computer 10/01/97 12000 M
2. Sharmila 31 History 24/03/98 20000 F
3. Sandeep 32 Maths 12/12/96 30000 M
4. Sangeeta 35 History 01/07/99 40000 F
5. Rakesh 42 Maths 05/09/97 25000 M
6. Shyam 50 History 27/02/97 30000 M
7. Shiv Om 44 Computer 25/02/97 21000 M
8. Shalakha 33 Maths 31/07/97 25000 F
(a) To show all information about the teacher of history department in order of Salary.
(b) To list the names of female teachers who are in Maths department
(c) To count the number of teachers with age<35.
(d) Modify the record of teacher Rakesh by changing his dept. from Math to History.
(e) To count the number of teachers having salary >=12000, with each department.
(f)Give the output of following statement.
(i) Select COUNT(distinct department) from TEACHER;
(ii) Select name, MAX(Age) from Teacher where sex=”F”;
Write SQL command for (i) to (v) on the basis of the table VOTER.
16
VNO VNAME AGE ADDRESS PHONE
1 Diwaker 22 Sarojini Nagar 7045249
2 Rajiv 27 KK Nagar 2233456
3 Smith 40 Paschim Vihar 4190567
4 Arpit 30 Dev Nagar 3378567
5 Anand 27 Dev Nagar 2775690
6 Lisa 34 Sarojini Nagar 3343267
7 Umesh 21 KK Nagar 2234567

113
8 Yashraj 45 Paschim Vihar 4123587
9 Ganen 22 Babuji Nagar 6789012
10 Harish 27 Babuji Nagar 6700112
i) List VNO, VNAME, AGE for all voters. This information should be sorted on VNAME.
ii) Insert a new field ‘GENDER’ in the VOTER table.
iii) Display the name and age of the voters, who are in age group 18-25.
iv) Update the record of Yashraj by modifying his age to 67.
v) Display the name of minimum aged voter.
17 Consider the following database table and write the query statement for the following questions:
Table: Student
ID Name Stipend Stream Avgmark Grade Class
1 Karan 400 Medical 78.5 B 12
2 Divakar 450 Commerce 89.2 A 11
3 Divya 300 Commerce 68.6 C 12
4 Arun 350 Humanities 73.1 B 12
5 Sabina 500 Nonmedical 90.6 A 11
6 John 400 Medical 75.4 B 12
7 Robert 250 Humanities 64.4 C 11
8 Rubina 450 Nonmedical 88.5 A 12
9 Vikash 500 Nonmedical 92.0 A 1
10 Mohan 300 Commerce 67.5 C 12
q-1 Add one more column Section in the table.
q-2 List all names of those students who are in class 12 sorted by stipend.
q-3 Display a report listing name, stream and amount of stipend received in a year assuming that the
stipend mentioned in the table is per month.
q-4 Count the number of students with grade ‘A’ in the each stream mentioned in the table Student.
q-6 Assign a value of 350 for stipend for all Non medical students having grade ‘A’.
18 Study the following tables STAFF and SALARY and write SQL commands for the questions (i) to (iv).
Table: Staff
ID Name Dept Sex Experience
101 Siddharth Sales M 12
104 Raghav Finance M 5
107 Naman Research M 10
114 Nupur Sales F 3
109 Janvi Finance F 9
105 Rama Research M 10
117 James Sales F 3
111 Binoy Finance F 12
130 Samuel Sales M 15
Table: Salary
ID Basic Allowance Commission
101 12000 1000 3
104 23000 2300 5
107 32000 4000 5
114 12000 5200 10
109 42000 1700 20
105 18900 1690 3
130 21700 2600 30

114
i. Display Name of all staff who are in “Sales” having more than 10 years experience from the
table Staff.
ii. Display the average salary of all staff working in “Finance” department using the tables Staff
and Salary. Where Salary = Basic + Allowance.
iii. Display the minimum Allowance of female staff.
iv. Display the highest commission among all male staff.

Answers- Unit -5: Database & SQL


Total Marks= 08
QNo. Answers
A. Answer to theory Questions
1 Relation: Generally relation is a table, it arrange the data in rows and columns. The numbers of
columns are same in all rows and the columns are assigned distinct names called Attributes and they
must have data of attribute type only.
Tuple: one row of data is called a tuple.
Degree: the total number of attributes is called degree of a relation.
Cardinality: is the total number of rows in a relation.
Domain: it is a collection of data type from which the actual values appears in the given columns. It
is also called central pool of data values.
Attribute: is a column, which is of a specific type comes under domain.

2 A Primary Key is a set of attributes that can uniquely identify the tuples within the relation. It must
be unique in the relation. For example: a table of student’s record may have different type of
attributes but a rollno field can act as a primary key for that table, because it is unique for all
students.

3 SQL-DDL: is a Data Definition Language, which contains a set of commands used for defining the
database relation. It defines the type of data in database and also defines how they are created. It
also includes instruction to modify the structure or delete the structure of database. E. g. Create
Table, Alter Table, Drop Table etc.
SQL-DML: is a language that enables users to access or manipulate data as organized by the
appropriate data model. E.g. insert, select-from, update, delete etc.

4 Foreign Key: It is a non key attribute of a relation, which must be a primary key of one another
relation. It derives in this table by the relationship of both the tables.
Primary Key: is belongs to one relation only, which is used to identify the records of this table only.

5 Relation: Generally relation is a table, it arrange the data in rows and columns. The numbers of
columns are same in all rows. A tuple is a row and an attribute is column in a relation.

6 The main advantages of database are as follws:


1. It reduces the redundancy to a large extent in database.
2. It can control the data inconsistency by using propagating updates.
3. It provides the facility of data sharing in a controlled way.
4. The can ensure the data security and protection.
5. The database ensures that it follows the applicable standards.
The various level of database abstraction (Implementation) are as follows:
1. Internal Level: It is the Physical level of abstraction, which describe how data are actually
stored, without showing details to user’s end.
2. Coneptual Level: It is a logical level, which describe the logical relationships amoung data
and also describe what data are actually stored in database.
3. External Level: It is the user’s level, which defines what to show and where to show the
particular data and to a particular user.
7 A Key is a set of attributes, which are distinct and have some valuable properties in the table.
The various keys used in database are:
115
1. Super Key: it is a collection of all keys
2. Primary Key: one or more key attributes, which are uniquely identifying the record in the
table. Primary Key is a minimal set of Super Key.
3. Candidate Key: members of Super Key set, which can act as primary key
4. Alternet Key: The Candidate keys which are not acting as primary key.
5. Foreign Key: is may be a non key attribute of a relation, which must be a primary key of
one another relation.

8 a) Union ( U ) : It is binary operation requires two relations as its operands. It produced a third
relation that contains tuples from both relations and it deletes the duplicates. Both relations must
have same type and no. of attributes.

b) Set Difference (-): It is binary operation requires two relations as its operands. It produced a
third relation that contains tuples, which are not common. It contains uncommon of first relation.
Both relations must have same type and no. of attributes.
c) Intersection: It is binary operation requires two relations as its operands. It produced a third
relation that contains tuples, which are common in both relations. Both relations must have same
type and no. of attributes.
d) Cartesian Product: It is binary operation requires two relations as its operands. It produced a third
relation that has a degree equal to sum of the degree of both relations.
Examples: examples are given in further questions:

9 View is a virtual table created or derived from another table in database? Syntax:
CREATE VIEW <View Name>
AS SELECT <Column Names of Table>
FROM <TableName>
[WHERE <Conditions>…];

10 Relational data model: in this model data are organized in tables, called relations. It define a
collection of related tables can be linked together to show the relationship.
Network data model: in this model data are represented by a collection of records. The individual
recors can be linked together to show relationship. This very difficult to manage lot of individual
records but it provide ease of entering individual records.
B. Answer of Relational Algebra
1 a)σCity = ‘Delhi’(Customer)
b) ∏Supp-name, Status (σstatus is >=40) (Customer)
c) ∏Supp_Code, Supp-name(Customer)
2 (a) Drama U Song
Rollno Name age
1 r 14
2 p 13
3 x 14
5 y 15
7 z 15
8 m 14

(b) Song- Drama


Rollno Name age
5 y 15

(c) Drama ∩ Song

116
Rollno Name age
1 r 14
3 3 x 14
7 z 15
(a) σ Item name = ‘Bread’(Item)

(b) ∏Item name, Price (σ Price>=12.00) (Item)

4
a) ∏Roll, Name(Student):
Roll Name
1 Punnet
2 Rohit
3 Rahul
4 Rakesh
5 Yatin
6 Jish
7 Vidhi
b) ∏Class, Section(σSection =’A’ )(Student)
Class Section
12 A
12 A
5 12 A
(1) ∏Name, Amount(σAmount>10000 )(Customer)
(2) ∏Name, Balance (Customer)
(3) ∏Name, id(σBankar name = ‘Ajit’ )(Customer)

C. Answer: SQL Commands


1 Create Table Salesperson
( name char(20) not null, scode int not null primary key, city char(25), commrate numeric(5,2) not
null);
(a) Insert into Salesperson
Values(1, ‘ram kumar’, ‘Mumbai’, 0.20);
(b) Update Salesperson Set commrate =0.25 Where city = ‘Mumbai’;
(c) Alter Table Salesperson Add (phone numeric(10));

2 a) Select * From INTERIORS Where Type = ‘Sofa’ Order By Price;


b) Select Itemname, Price, Discount From INTERIORS Where Discount >=15;
c) Select Sum(Price), Type From INTERIORS Group By Type;
d) Update INTERIORS Set Discount = 25 Where Price>=20000;
e) Select Itemname From INTERIORS Where Type = ‘Baby cot’;
3 Create Table Children_home
(Child_id int Not NullPrimary Key, Name char(20) not null, Age int, Dob Date Check (Dob
<= ‘01/01/2005’), Address char(25) not null, Phone numeric(10) );

4 a) Select Name, Age From Tourist Order By Age Desc;


b) Select Sum(Package Amount), Agency From Tourist Group By Agency;
c) Select Name, Age, Package Amount From Tourist Where Age Between 28 and
35 and Agency = ‘Go Places’;
d) Select Count(Name), Agency From Tourist Group By Agency;

5 (a) Select Title From Book_Record Where Pub = ‘Bpb’ and Type = ‘Prog’;
(b) Select Title, Qty, Price From Book_Record Where Qty > 10 Order By Price Desc;
(c) Select Min(Price) From Book_Record Where Type = ‘Prog’;
(d) Select Count(*), Pub From Book_Record Group By Pub;
117
(e) Select Sum (Qty), Avg(Price) From Book_Record;
(f) Select Max(Price), Min(Price) , Pub From Book_Record Group By Pub;

6 (i) Select * From EmployeesWhereCity = ‘Peris’;


(ii) Select * From Employees Order By Firstname Desc;
(iii) Select Firstname, Lastname, Salary + Benefits ‘Total Salary’ From Employees E1 ,
EmpSalary E2 Where E1.Empid = E2.Empid and E2.Designation = ‘Manager’;
(iv) Select Max(Salary), Designation From EmpSalary Group By Designation Having
Designation IN (‘Manager’, ‘Clerk’);
(v) Select Firstname, Salary, Designation From Employees E1, EmpSalary E2 Where
E1.Empid = E2.Empid;
Output:
(i) Firstname City Designation
RachelNew York Salesman
PeterPeris Salesman
(ii) Count(Distinct Designation): 4
(iii) Designation Sum(Salary)
Manager 215000
Clerk 135000
(iv) Sum(Benefits) 32000

7 (a) Select Name From GRADUATE Where Div = ‘II’ Order By Name;
(b) Select Name, Stipend, Subject, Stipend*12‘Annual Stipend’ From GRADUATE;
(c) Select Count(*) From GRADUATE Where Subject = ‘PHYSICS’ or Subject = ‘COMP. Sc.’;
(d) Insert Into GRADUATE Values(11,’KAJOL’, 300, ‘COMP. Sc.’, 75, ‘I’);
(e) (i) 63 (ii) 3200 (iii) 450 (iv) 4
8 (a) Select * From SchoolBus Where Capacity>Noofstudents Order By Rtno;
(b) Select Area_Covered, Distance, Charges From SchoolBus Where Charges<80000 and
Distance > 20;
(c) Select Sum(Noofstudents), Transporter From SchoolBus Group By Transporter;
(d) Select Avg(Charges), Transporter From SchoolBus Where Distance > 10 Group By
Transporter;
(e) Select Rtno, Area_Covered, Charges/Noofstudent ‘Avg. Cost’ From SchoolBus;

9 (i) Select CnorName From CONSIGNORWhereCity = ‘Mumbai’;


(ii) Select * From CONSIGNEE Order By CneeName;
(iii) Select CnorName, CneeName From CONSIGNOR C1, CONSIGNEE C2 Where
C1.CnorID = C2.CnorID;
(iv) Select Count(*), City From CONSIGNOR Group By City
(v) Mumbai, New Delhi, Kolkata
(vi) P Dhingra 16/J, Moore Enclave
B P Jain 13, Block D, A Vihar
(vii) MU05 Rahul Kishore
KO19 A P Roy

10 (i) Select * From HOSPITAL Where Department = ‘Cardiology’;


(ii) Select Name, Dateofadm From HOSPITAL order By Dateofadm;
(iii) UpdateTableHOSPITAL Set Age = 61 Where Name = ‘Zareen’;
(iv) Select Count(*) From HOSPITAL Where Age <= 20;
(v) Delete From HOSPITAL Where Name = ‘Zubin’;
(vi) a. 800 b. 12
c. Ketaki 16
Kush 19
11 (i) Select Name, Deptid From Employee Order By Deptid;
(ii) Select Name, Basic From Employee E, Salary S Where S.Basic >3000 And E.Eid =
S.Eid;
(iii) Select Name, Basic + DA + HRA + Bonus ‘Net Salary’ From Employee E, Salary S

118
Where E.Eid = S.Eid;
(iv) Update Table Salary Set Bonus = Bonus + 200 Where Eid=(Select Eid From
Employee Where Qualification = ‘B.Tech’ Or Qualification = ‘M.Tech’);
(v) Jyoti (vi) 8000 (vii) 2 (viii) Sumit Mittal
Jyoti

12 (i) Select Teacher, Preiods, Experience From SCHOOL Where Periods<25 and
Experience <10;
(ii) Select * From SCHOOL Where Periods Between 10 and 25;
(iii) Select Code, Teacher, Designation, Gender From SCHOOL S, ADMIN A Where
S.Code = A.Code And A.Gender = ‘Female’;
(iv) Select Code, Teacher, Subject From SCHOOL Where DoJoin>”01/01/1999”;
(v) 10 English, 16 Physics, 15 Maths, 5 Chemistry
(vi) Priya Rai Female, Lisa Anand Female
(vii) Vice Principal 1
13 (i) Select Name, GameName From GAMES, PLAYER Where
GAMES.GameName = ‘CaromBoard’ AND GAMES . GCode = PLAYER .
GCode;
(ii) Select * From GAMES Where PrizeMoney>8000;
(iii) Select * From GAMES Where GameName Like “B%”;
(iv) Select Avg(PrizeMoney) From GAMES;
(v) 2
(vi) Max Date:19-Mar-2004 Min Date: 12-Dec-2003
14 (i) Select FLNO, NOofFLIGHTS From FLIGHTS Where STARTING = ‘KANPUR’
And ENDING = ‘BANGLORE’;
(ii) Select * From FLIGHTS Order By FLNO;
(iii) Select FLNO, FARE +FARE*TAX%/100 ‘Fair to Pay’ From FLIGHTS F1, FARES
F2 Where F1.FLNO = F2.FLNO;
(iv) Select Min(FARE) From FARES Where AIRLINE = ‘Indian Airlines’;
(v) IC 302 8 Indian Airlines
AM501 1 Jet Airways
IC701 4 Indian Airlines
(vi) 7
15 (a) Select * From Teacher Where Department = ‘History’ Order By Salary;
(b) Select Name From Teacher Where Sex = ‘F’ and Department = ‘Maths’;
(c) Select Count(Name) From Teacher Where Age <35;
(d) Update Table Teacher Set Department = ‘History’ Where Name = ‘ Rakesh’;
(e) Select Count(*), Department From Teacher Where Salary >=12000 Group By Department;
(f) (i) 3 (ii) Sangeeta 35

16 (i) Select VNO, VNAME, AGE From VOTER Order By VNAME;


(ii) Alter Table VOTER Add (GENDER Char(1));
(iii)Select VNAME, AGE From VOTER Where Age Between 18 And 25;
(iv) Update Table VOTER Set AGE = 67 Where VNAME=’Yashraj’;
(v) Select VNAME, AGE From VOTER Where AGE = (Select Min(AGE) From
VOTER );
17 q-1. Alter Table Student Add (Section Char(1));
q-2. Select Name, Class, Stipend From Student Where Class = 12 Order By Stipend Desc;
q-3. Select Name, Stream, Stipend*12, ‘Annual Stipend’ From Student;
q-4. Select Count(*), Stream From Student Where Grade = ‘A’ Group By Stream;
q-5. Update Table Student Set Stipend = 350 Where Grade = ‘A’ and Stream = ‘Nonmedical’;

18 (i) Select Name, Experience From Staff Where Dept = ‘Sales’ and Experience >10;
(ii) Select Avg(Basic+Allowance) ‘Avg. Salary’ From Staff S, Salary SL Where S.ID = SL.ID
and S.Dept = ‘Finance’;
(iii) Select Min (Salary. Allowance) From Salary, Staff Where Staff.Sex = ‘F’ and Staff.ID =
Salary.ID;

119
(iv) Select Max (Salary. Commission) From Salary, Staff Where Staff.Sex = ‘M’ and
Staff.ID = Salary.ID;

Unit 6 –Boolean Algebra


Total Marks=08
Q.N. Question
A. Boolean Theorems/Laws

1 State the following Theorems/Laws of Boolean Algebra and prove them by Truth Table or by
algebraically.
(a) De Morgan (b) Associative (c) Distributive
2 State the following Theorems:
(a) Indempotence (b) Absorption (c) Involution (d) Commutative (e) Complementrity Law

B. Prove the following statements algebraically


(a) x’ y’ z’+ x’ y’ z + x’ yz + x’ yz’ + xy’ z’ + xy’ z = x’ +y’
(b) X.Y’ .Z + X.Y’ .Z’ + X’ .Y’ .Z = X.Y’ +Y’ .Z
(c) X’ Y’ Z’ + X’ Y Z’ + XY’ Z’ + XYZ’ = Z’
(d) (X + YZ) =(X+Y) (X+Z)
(e) XY+YZ+YZ’=Y
(f) (A+B).(A’ +C).(B+C)=(A+B).(A’+ C)
C. Logic Gates:
1 Find out the output for the following logic circuit diagram

(a) a b c

(b) A

(c)

120
(d)

(e) (f)

(g)

(h)

2
(a) Practice the circuit design for the following problems.
Draw the simplified logic diagram using NAND gates only to implement the three input function F
denoted by the expression:
(b) F= ∑(0,1,6,7)

121
(c) Draw the logic diagram of expression AB’+B’C’+AC
(d) Draw the logic diagram of expression AB’C’+B’C, using NAND Gates.
(e) Represent the Boolean expression (X+Y)(Y+Z)(X+Z) with help of NOR gate only
(f) Represent the Boolean function F(X,Y,Z)= (X’+Y)(Y’+Z) with help of NOR gate only
(g) Design a circuit to realize the following : F(A,B,C) = AB + AC’ + B’A’C
(h) Show A(B’+C) using NOR gate only.
(i) Design a circuit to realize the following : F(A,B,C) = AC + AB’ + BA’C
Draw the Logical circuit of the following expression with the help of NAND gate only
(j) xz+yz+x’y’
(k) Draw the Circuit for Boolean expression (X+Y)(Y+Z)(X+Z) with help of NOR gate only.
Draw a logic circuit for the following Boolean function using NAND gates only.
F(X,Y)=X .Y + X’ . Y + X . Y’

D. Dual, Truth Table, SOP, POS and others


1 Write dual for the following Boolean Expressions:
(a) (x.y’.z)(x.y)
(b) (x+y’+z)(x+y)
(c) (X+Y).(X’+Z’).(Y+Z)
(d) (B’+C’).A
(e) A+B’C=1
(f) (B’ + C) + A
(g) (X+Y).(X’+Z’).(Y+Z)
(h) (B’ + C) + A’
(i) (X+Y).(X’+Z’).(Y+Z)
(j) (X+1). Y’
2 Write the principle of duality? Find the dual of the Boolean expression (B’+C’)+A(1+C)
3 Truth table problems:
(a) Write the Product of Sum form of the function H (U,V,W). Truth table representation of H is as
follows:
U V W H
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
(b) Given the following truth table, write the Sum of product form of the function F(x,y,z)

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

(c) Write the Sums of Product form of the function F(a , b , c), truth table representation of F is
given below:
a b c F

122
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1

(d) For the given truth table, give canonical sum-of-products(SOP) and canonical product-of- sum
(POS) expression.
X Y Z F
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 0
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 1

(e) Write the Shorthand SOP form of a Boolean Function F, which is represented by the following
Truth Table:

X Y Z F
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 0

(f) Write the Products of sum and SOP form in Shorthand form of the function G(U,V,W). Truth
table representation of G is as follows:

U V W G
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1

(g) A Boolean function F defined on three input variables A, B, C and it gives 1(one) o/p if and
only if the number of 0(zero) inputs is odd (e.g. F is 1(one) if A=0, B=1, C=1). Draw the truth table
for the above function and express it in canonical sum of product form.

(h) A Boolean function F defined on three input variables X, Y and Z and it gives 1 o/p (one) if and
only if the input is having even number of 1’s. Draw the truth table for the above function and
express it in canonical sum of product form.
123
(i) A Boolean function F defined on three input variables X, Y and Z and it gives 0 (zero) o/p if and
only if the X and Y input are same. Draw the truth table for the above function and express it in
canonical product of sum form.
4
POS and SOP Problems

(a) Write the equivalent Canonical Product of Sum Expression for the followingSum of Product
Expression:
F(X, Y, Z) = ∑ (0, 2, 4, 5)

(b) Convert the following expression into Canonical SOP form


x+yx+xz
(c) Express P’ + QR’ in canonical POS form.

(d) Write the equivalent POS expression of following SOP form


F (x,y,z)= ∑ (0,2,4,6)

(e) Convert the following 3 input function f denoted by the expression


F(a, b, c)= ∑ (0, 2, 3, 6) into its canonical SOP form.

(f) Minimize the following expression algebraically:


X’Y’Z’ + X’Y’Z +X’YZ + XY’Z

E. Karnaugh Map Problems


1 Minimise the following function using K- map and find out the expression
(i) F(x,y,z,w) = ∑ (0,2,4,6,8,10,12,13,14,15)
(ii) Y(a,b,c,d) = ∏ (0,1,3,5,7,12,13,15)
(iii) H(a,b,c,d)=Π(M2,M4,M6,M7)
(iv) F(A, B, C, D) = ∑ (5,6,7,8,9,12,13,14,15)
(v) F(x,y,z)=∑(2,3,5,7)
(vi) F (a,b,c,d) =  (1,4,5,8,9,12,13)
(vii) Simplify the following 4-var K-map and write down the simplified minterms expression.
ab \ cd
1 0 1 0
1 1 1 0
1 1 1 0
1 0 1 0

(viii) Obtain a simplified expression in the SOP form for the Boolean function
f(A,B,C), K-map shown below:

A BC
1 0 1 1
1 0 0 1

124
Answers- Unit -6: Boolean Algebra
Total Marks= 08
QNo. Answers
A. Answer to Theorems:
1.(a) De Morgan’s 1st Theorem: ( X + Y ) = X .Y
Proof: By using the complementary Law we can say that X + X = 1 and X . X = 0, so we can
write (X+Y)+ ( X + Y ) =1and (X+Y) ( X + Y ) =0 to prove the DeMorgan’s Theorem. Let us
prove the first part, i.e. (X+Y)+ ( X + Y ) =1
(X+Y)+( X.Y ) = 1
=(X+Y+ X ).(X+Y + Y ) = (1+ Y).(1+X) = 1.1=1, Hence proved.
Let us prove the Second Part: (X+Y) ( X + Y ) =0
(X+Y) . ( X.Y ) = 0
(X+Y) . ( X.Y ) = ( X Y X + X Y Y) = ( X .X. Y + X . Y .Y) = (0+0) = 0, Hence proved.
De Morgan’s 2nd Theorem: ( X .Y ) = X + Y
Proof: By using the complementary Law we can say that X + X = 1 and X . X = 0, so we can
write (XY)+ ( X .Y ) =1and (XY). ( X .Y ) =0 to prove the DeMorgan’s Theorem. Let us prove
the first part, i.e. (X.Y)+ ( X .Y ) =1
(X.Y)+ ( X + Y ) = 1
= ( X + Y +X) ( X + Y +Y) = ( X + X + Y ) ( X + Y +Y) =(1+ Y )( X
+1)=1
Hence proved.
Let us prove the Second part, i.e. (X.Y). ( X .Y ) =0
(X.Y). ( X + Y ) = 0
= ( X .Y . X) ( X.Y .Y) = (0.Y) (0.X) =0, Hence proved.
(b) Associative Theorem:
(i) X+(Y+Z) = (X+Y) +Z
(ii) X(YZ) = (XY)Z
Proof. By Truth Table:
X Y Z X+Y Y+Z XY YZ X+(Y+Z) (X+Y)+Z X(YZ) (XY)Z
0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 0 0 1 1 0 0
0 1 0 1 1 0 0 1 1 0 0
0 1 1 1 1 0 1 1 1 0 0
1 0 0 1 0 0 0 1 1 0 0
125
1 0 1 1 1 0 0 1 1 0 0
1 1 0 1 1 1 0 1 1 0 0
1 1 1 1 1 1 1 1 1 1 1
Compare the columns X+(Y+Z) and (X+Y)+Z, both are same, so first law proved. Compare the
columns X(YZ) and (XY)Z, both are same, so second law proved.

(c) Distributive Law:

(i) X (Y + Z) = XY +XZ
(ii) X + (YZ) = (X+Y)(X+Z)

Proof by Truth Table:

X Y Z XZ X+Y Y+Z X+Z XY YZ X(Y+Z) XY +XZ X+YZ (X+Y) (X+Z)


0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 1 1 0 0 0 0 0 0
0 1 0 0 1 1 0 0 0 0 0 0 0
0 1 1 0 1 1 1 0 1 0 0 1 1
1 0 0 0 1 0 1 0 0 0 0 1 1
1 0 1 1 1 1 1 0 0 1 1 1 1
1 1 0 0 1 1 1 1 0 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
Compare the columns X (Y + Z) and XY +XZ, both are same, so first law proved. Compare the
X + (YZ) and (X+Y)(X+Z), both are same, so second law proved.
The second law can be proved algebraically :
X + (YZ) = (X+Y)(X+Z)
Take R.H.S.= (X+Y)(X+Z) = XX +XZ+XY+YZ
= X+XZ+XY+YZ = X+XY+XZ+YZ = X(1+Y) + ZX+YZ = X+XZ+YZ
= X(1+Z)+YZ = X + YZ = L.H.S. Hence Prooved
2.(a) Indempotence Law: (i) X + X = X
(ii) X . X = X
(b) Absorption Law: (i) X + XY = X
(ii) X (X + Y) = X
(c) Involution Law: X =X
(d) Commutative Law: (i) X + Y = Y + X
(ii) X . Y = Y . X
(e) Complementrity Law: (i) X + X = 1
(ii) X . X = 0

B. Prove the following statements algebraically


(a) x’y’z’ + x’y’z + x’yz + x’yz’ + xy’z’ + xy’z = x’+y’
L.H.S. = x’y’(z’+z)+x’y(z+z’)+xy’(z’+z)
= x’y’+x’y+xy’ = x’(y’+y) + xy’ = x’+xy’ = (x’+y’)(x’+x) = (x’+y’)=R.H.S.
(b) X.Y’.Z + X.Y’.Z’ + X’.Y’.Z = X.Y’+Y’.Z
L.H.S. = XY’(Z+Z’)+X’Y’Z = XY’+X’Y’Z = Y’(X+X’Z) = Y’(X+X’)(X+Z)
= Y’(X+Z) = Y’X+Y’Z = R.H.S.

126
(c) X’Y’Z’ + X’YZ’+ XY’Z’ + XYZ’ = Z’
L.H.S. = X’Z’(Y’+Y) + XZ’(Y’+Y) = X’Z’+XZ’ = Z’(X’+X) = Z’= L.H.S.
(d) (X + YZ) =(X+Y) (X+Z)
R.H.S. = X.X+XZ+YX+YZ = X+XZ+XY+YZ = X(1+Z)+XY+YZ
= X+XY+YZ = X(1+Y)+YZ = X+YZ = L.H.S.
(e) XY+YZ+YZ’=Y
L.H.S. = XY+Y(Z+Z’) = XY+Y = Y(1+X) = Y = R.H.S
(f) (A+B).(A’+C).(B+C)=(A+B).(A’+ C)
R.H.S. = (A+B)(A’+C) = AA’+AC+A’B+BC = (A’B+BC)+AC
=(A+A’B+BC)(C+BC+A’B)=((A+B)(A+A’)+BC)(C(1+B)+A’B)
=(A+B+BC)(C+A’B) = ((A+B(1+C)) (C+A’)(C+B) = (A+B) (A’+C) (B+C) = L.H.S

C. Logic Gates:
1 Output for the logic circuit diagram:
(a) (a+b+c’)(a+b’+c’)(a’+b+c)
(b) (a+b)(c+d)
(c) AC+AB+BC
(d) AB’+C’D
(e) (A+C)(A+B)(B+C)
(f) (X+Y’)(X’+Y)(X’+Y’)
(g) WX’+Y’Z
(h) (A’+C’)+(A+B)+(B+C)
2 Draw the circuit diagrams for the given expression for practice.
D. Answer: Dual, Truth Table, SOP, Pos and others
1 a) (x+y’+z)+(x+y)
b) (x.y’.z)+(x.y)
c) (X.Y)+(X’.Z’)+(Y.Z)
d) (B’.C’)+A
e) A.B’+C=0
f) (B’ . C) . A
g) (X.Y)+(X’.Z’)+(Y.Z)
h) (B’.C).A
i) X.Y+X’.Z’+Y.Z
j) (X.0)+Y’
2 The principle of duality state that, if a Boolean expression proves a theorm than its dual also
proves that. A dual of an expression can formed by doing the following changes:
1. And (.) operator with OR (+)
2. OR (+) with And (.)
3. 0 by 1 and 1 by 0
Given expression = (B’ + C’ ) + A (1 + C)
Its Dual = (B’ . C’) . A+ (0 . C)
3 (a) for POS form take 0’s o/p from TT: H(U,V,W) = (U+V+W)(U+V+W’)(U+V’+W’)
(U’+V+W’)
(b)for SOP form take 1’s o/pfrom TT: F(x,y,z) = x’y’z+x’yz’+xy’z’+xyz
(c) F(a,b,c) = a’bc’+ab’c’+abc’+abc
(d) SOP Expression: X’Y’Z+XY’Z’+XY’Z+XYZ
POS Expression: (X+Y+Z) (X+Y’+Z) (X+Y’+Z’) (X’+Y’+Z)
(e) F(X,Y,Z) = X’Y’Z+X’YZ+XY’Z’+XYZ’
= 001 + 011 + 100 + 110 = m1 +m3 +m4 +m6
F(X,Y,Z)=∑(1, 3, 4, 6) Ans.
(f) SOP Form: G(U,V,W) = U’VW’+U’VW+UV’W’+UVW = 010+011+100+111
= m2+m3+m4+m7 = ∑(2, 3, 4, 7)
POS Form: G(U,V,W) = (U+V+W) (U+V+W’) (U’+V+W’) (U’+V’+W)
= M0+M1+M5+M6 = ∏(0,1,5,6)
(g) The truth table for the given problem is as follows:
A B C F
0 0 0 1

127
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
So the Boolean function is: 1 1 1 0
F(A,B,C) = A’B’C’+A’BC+AB’C+ABC’

(h) The truth table for the given problem is as follows:


X Y Z F
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
So the Boolean function is:
F(X,Y,Z) =X’YZ+XY’Z+XYZ’ 1 1 0 1
1 1 1 0
(i) The truth table for the given problem is as follows:
X Y Z F
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 1
So the Boolean function is:
4 F(X,Y,Z) = (X+Y+Z) (X+Y+Z’) (X’+Y’+Z) (X’+Y’+Z’) 1 1 0 0
1 1 1 0
Answer: POS and SOP Problems
(a) F(X, Y, Z) = ∑ (0, 2, 4, 5) = m 0+m2+m4+m5 = X’Y’Z’+X’YZ’+XY’Z’+XY’Z
To find the equivalent POS form, first Simplify it: X’Z’(Y’+Y) + XY’(Z’+Z) = X’Z’ + XY’
= (X’Z’+X) (X’Z’+Y’) = (X + Z’) (X’ + Y’) (Y’ + Z’)
For canonical form: (X + Z’ + YY’) ( X’ + Y’ + ZZ’) ( Y’ + Z’ + XX’)
= (X + Z’ + Y) (X + Z’ + Y’) (X’ + Y’ +Z) (X’ + Y’ +Z’) (X + Y’ +Z’)(X’ + Y’ + Z’)
= (X + Y + Z’) (X +Y’ + Z’) (X’ +Y’ +Z) (X’ + Y’ + Z’) Ans.

(b) Convert the following expression into Canonical SOP form: x+yx+xz
First simplify it: x(1 + y) + xz = x + xz = x(1 + z) = x
For canonical form: x (y+y’)(z+z’)
= xyz + xyz’+xy’z+xy’z’ = xyz+xyz’ +xy’z +xy’z’ Ans.

(c) P’ + QR’ = (P’+Q)(P’+R’) = (P’+Q+RR’) (P’+R’+QQ’)


= (P’+Q+R)(P’+Q+R’)(P’+R’+Q)(P’+R’+Q’) in canonical POS Form.

(d) F (x,y,z)= ∑ (0,2,4,6) = m0+m2+m4+m6 = x’y’z’+x’yz’+xy’z’+xyz’


For POS Form = x’z’(y’+y) + xz’(y+y’) = x’z’+xz’ = (x’z’+x)(x’z’+z’)= (x+z’)(x’+z’)(z’)
Ans.

(e) F= ∑ (0, 2, 3, 6) = m0+m2+m3+m6 = a’b’c’+a’bc’+a’bc+abc’

(f) X’Y’Z’ + X’Y’Z +X’YZ + XY’Z

128
For simplification = X’Y’(Z’+Z) + X’YZ + XY’Z = X’Y’ + X’YZ + XY’Z
= X’Y’ + XY’Z + X’YZ = Y’(X’+XZ) + X’YZ = Y’(X+X’)(X’+Z) + X’YZ =Y’(X’+Z)+X’YZ
= X’Y’+Y’Z+X’YZ= X’Y’+ X’YZ+Y’Z = X’(Y’+YZ) + Y’Z = X’(Y+Y’)(Y’+Z) + Y’Z
= X’(Y’+Z) + Y’Z = X’Y’+Y’Z+X’Z Ans.

E. Answer: K-Map Problems


(i) F(x,y,z,w) = ∑ (0,2, 4, 6,8,10,12,13,14,15)
The Karnaugh Map for the given Boolean function is:
xy\zw 00 01 11 10
00 1 0 0 1
01 1 0 0 1
11 1 1 1 1
10 1 QQ1
0 0 1
It gives one Octect and one quad:
The equation for the octet is: w’
The equation for the quad is: xy
So the final minimized expression for the F(x,y,z,w) = w’+xy

(ii) Y(a, b, c, d) = ∏ (0, 1, 3, 5, 7, 12, 13, 15)


The Karnaugh Map for the given Boolean function is:
ab\cd 00 01 11 10
00 0 0 0 1
01 1 0 0 1
11 0 0 0 1
10 1 1 1 1
It gives Two quad and two Pairs:
The equation for the Quad 1 is: a+d’
The equation for the Quad 2 is: b’+d’
The equation for the Pair 1 is: a+b+c
The equation for the Pair 2 is: a’+b’+c
So the final minimized expression for the Y(a,b,c,d) = (a+d’)( b’+d’)( a+b+c)( a’+b’+c)

(iii) H(a,b,c,d)=Π(M2,M4,M6,M7)
The Karnaugh Map for the given Boolean function is:
ab\cd 00 01 11 10
00 1 1 1 0
01 0 1 0 0
11 1 1 1 1
10 1 1 1 1
It gives Three Pairs:
The equation for the Pair 1 is: a+c’+d
The equation for the Pair 2 is: a+b’+c’
The equation for the Pair 3 is: a+b’+d

129
So the final minimized expression for the H(a,b,c,d) = (a+c’+d )( a+b’+c’)(a+b’+d)
(iv) F(A, B, C, D) = ∑ (5,6,7,8,9,12,13,14,15)
The Karnaugh Map for the given Boolean function is:
ab\cd 00 01 11 10
00 0 0 0 0
01 0 1 1 1
11 1 1 1 1
10 1 1 0 0
It gives Three quads :
The equation for the Quad 1 is: ac’
The equation for the Quad 2 is: bd
The equation for the Quad 3 is: bc
So the final minimized expression for the F(a,b,c,d) = ac’+bd+bc
(v) F(x, y, z)=∑(2, 3, 5, 7)
x\yz 00 01 11 10
0 0 0 1 1
1 0 1 1 0

It give two Pairs:


The equation for the Pair 1 is: xz
The equation for the Pair 2 is: x’y
So the final minimized expression for the F(a,b,c) = xz+x’y
(vi) F (a,b,c,d) =  (1,4,5,8,9,12,13)
The Karnaugh Map for the given Boolean function is:
ab\cd 00 01 11 10
00 0 1 0 0
01 1 1 0 0
11 1 1 0 0
10 1 1 0 0
It gives Three quads :
The equation for the Quad 1 is: c’d
The equation for the Quad 2 is: bc’
The equation for the Quad 3 is: ac’
So the final minimized expression for the F(a,b,c,d) = ac’+bc’+c’d
(vii) Simplify the following 4-var K-map and write down the simplified minterms
expression.
ab \ cd
1 0 1 0
1 1 1 0
1 1 1 0
1 0 1 0
It gives Three quads :
The equation for the Quad 1 is: cd
The equation for the Quad 2 is: c’d’
The equation for the Quad 3 is: bc’
So the final minimized expression for the F(a,b,c,d) = cd+c’d’+bc’
(viii) Obtain a simplified expression in the SOP form for the Boolean function
f(A,B,C), k-map shown below:

130
A BC 00 01 11 10
1 0 1 1

1 0 0 1
This will give 1 Quad and 1 pairs:
The equation for the pairs 1 is: A’B
The equation for the Quad 1 is: C’
So the final minimized expression for the F(A,B,C) = C’+A’B

Unit 7 –Communication & Networking


Total Marks=10
Q. N. Question
A. Theoretical

1 What is a computer network? State some advantages of computer network.


2 Differentiate between Message switching and Packet switching techniques?
3 Define the various communication mediums used in the networking, in brief.
4 What is the difference between optical fiber & coaxial transmission media?
5 Define the types of network? Differentiate between the LAN & WAN?
6 Define the various network topologies, give advantages and disadvantages?
7 Define the following networking devices:
MODEM, SWITCH, HUB, BRIDGE, ROUTER, REPEATER, GATEWAY, ETHERNET
8 Differentiate between switch and hub?
9 Explain the following communication protocols?
HTTP, FTP, TCP/IP
10 Define the following terms in mobile communication:
TDMA, SIM, SMS, GSM, CDMA, WLL, 3G, Voice mail
11 Define the following Internet terms:
WWW, HTML, DHTML, XML
12 Define the URL and explain some most common domains.
13 What is the significance of Cyber Law? Give classification of cyber crime.
14 Define the web hosting and explain type of web hosting?
15 What do you mean by network security? Define some network security protection methods.
16 Define the following terms:
Firewall, Hacker, Cracker, Cookies
17 What is a virus? Give examples. Write some steps to avoid the virus?
18 Define the term Bandwidth? Give the units to measure the communication speed.
19 Expand the following terms:

1. IP 2. TCP/IP 3. NSF
4. Mbps 5. ISP 6. HTTP
7. EDGE 8. SLIP/PPP 9. SIM
10. POP 11. DNS 12. XML
13. WLL 14. NIU 15. ARPANET
16. OSS 17. VGM 18. Mhz
19. URL 20. FTP 21. CDMA
22. GSM 23. SMS 24. HTML
25. DHTML 26. FSF 27. GNU

131
28. W3C

20 Define the open source software?


21 Compare the terms Free Software, Freeware, Shareware and Proprietary Software?
B. LAN Design

1 “Hindustan Connecting World Association” is planning to start their offices in four major cities in
India to provide regional IT infrastructure support in the field of Education & Culture. The company
has planned to set up their head office in New Delhi in three locations and have named their New
Delhi offices as “Sales Office”, ”Head Office” and “Tech Office”. The company’s regional offices
are located at ”Coimbatore”, “Kolkata” and “Ahmedabad”. A rough layout of the same is as follows :

New Delhi

Head
Sales

Tech

Ahmedabad

Coimbatore Kolkata

Approximate distances between these offices as per network survey team is as follows :

Place From Place to Distance


Head Office Sales Office 20 Mtrs
Head Office Tech Office 70 Mtrs
Head Office Kolkata Office 1291 KM
Head Office Ahmedabad Office 790 Km
Head Office Coimbatore Office 1952 KM

In continuation of the above, the company experts have planned to install the following number of
computers in each of their offices :

Head Office 100


Sales Office 20
Tech Office 50
Kolkata Office 50
Ahmedabad Office 50
Coimbatore Office 50

(i) Suggest network type (out of LAN, MAN, WAN) for connecting each of the following set of their
offices :
• Head Office and Tech Office
• Head Office and Coimbatore Office
(ii) Which device will you suggest to be procured by the company for connecting all thecomputers
within each of, their offices in New Delhi out of the following devices?
132
• Modem
• Telephone
• Switch/Hub
(iii) Which of the following communication media, will you suggest to be procured by the company
for connecting their local offices in New Delhi for very effective and fast communication?
• Ethernet Cable
• Optical Fiber
• Telephone Cable
(iv) Suggest a cable/wiring layout for connecting the company’s local offices located in New Delhi.
Also, suggest an effective method/technology for connecting the company’s regional offices at
“Kolkata”, “Coimbatore” and “Ahmedabad”.

2 “Bhartiya Shopping Networks” is planning to spread their offices in four major cities in India to
provide regional IT infrastructure support for online sales and purchase. The company has planned
to setup their head office in Mumbai in three locations and have named their Mumbai offices as
“Front Office”, “Back Office” and “Work Office”. The company has three more regional offices as
“South Office”, “East Office” and “North Office” located in other three major cities of India. A
rough layout of the same is as follows :

INDIA
Mumbai

Back
Front

Work

North Office
East
Office
South
Office

Approximate distances between these offices as per network survey team isas follows:

Place From Place to Distance


Back Office Front Office 25 Mtrs
Back Office Work Office 90 Mtrs
Back Office East Office 1200 KM
Back Office North Office 850 Km
Back Office South Office 1400 KM
In continuation of the above, the company experts have planned to install thefollowing number of
computers in each of their offices :
Back Office 150
Front Office 20
Work Office 60
East Office 50
North Office 40
South Office 30
(i) Suggest network type (out of LAN, MAN, WAN) for connecting each of the following set of their
offices :
• Back Office and Work Office
• Back Office and South Office
(ii) Which device you will suggest to be procured by the company for connecting all the computers
with in each of their offices out of the following devices? Justify your answer?
• Switch/Hub • Modem • Telephone
(iii) Which of the following communication medium, you will suggest to be procured by the company
for connecting their local offices in Mumbai for cheap and average communication?

133
• Twisted Pair Cable • Optical Fiber • Ethernet Cable
(iv) Suggest a cable/wiring layout for connecting the company’s local offices located in Mumbai.
Also, suggest an effective high speed & secure method/technology for connecting the company’s
regional offices-”East Office”, “West Office” and “South Office” with offices located in Mumbai.

3 The Reliance company has 4 wings of buildings in city Hyderabad as shown in the diagram:

W1 W2
W3 W4
Center to center distances between various Buildings:
W3 to W1 50m
W1 to W2 60m
W2 to W4 25m
W4 to W3 170m
W3 to W2 125m
W1 to w4 90m
Number of computers in each of the wing:
W1 150
W2 15
W3 15
W4 25
Computers in each wing are networked but wings are not networked. The company has now decided
to connect the wings also.
i) Suggest a most suitable cable layout of the connection between the wings.
ii) Suggest the most suitable wing to house the server of this company with a suitable reason.
iii) Suggest the placement of the following devices with justification:
1) Internet connecting device/modem
2) Switch / Hub
iv) The company is planning to link its head office situated in New Delhi with the n/w at Hyderabad.
Suggest an economic way to connect it; the company is ready to compromise on the speed of
connectivity. Justify your answer.

4 Haldiram Private Ltd. has decided to network all its offices spread in five buildings of Company
(Shown below). No. of computers given in square brackets [ ].

Building Building
2 [45] 3 [110]
Building
1 [40]
Building Building
5 [70] 4 [60]

The distance between buildings are given below:


Between 1 & 2 20 Mts
Between 2 & 3 50 Mts
Between 3 & 4 120 Mts
Between 4 & 5 30 Mts
Between 3 & 5 70 Mts
Between 1 & 5 65 Mts
Between 2 & 5 50 Mts
(i) Suggest cable layout(s) for connecting the buildings.
134
(ii) Suggest the most suitable building to install the server of this organization with a suitable reason,
with justification.
(iii) Building-3 is used for many critical operations. It is tried that PC gets maximum possible
bandwidth. Which network device should be used to connect these computers for this?
(iv) The company also has another office in the same city but at a distant location about 25-30 kms
away. How can link be established with this building? (i.e. suggest the transmission medium).

5 Laxmi Marketing Ltd. has four branches in Udaipur. Company wants to establish the networking
between all the four offices. A rough layout of the same is as follows:

UOffice JOffice

KOffice AOffice

Approximate distances between these offices as per network survey team are as follows:
Place From Place To Distance
UOffice JOffice 130 m
JOffice KOffice 24 m
KOffice AOffice 55 m
UOffice AOffice 15 m
JOffice AOffice 105 m
UOffice KOffice 60 m
In continuation of the above, the company experts have planned to install the following number of
computers in each of their offices:

UOffice 40
JOffice 80
KOffice 200
AOffice 60

i). Suggest cable layout(s) for connecting the offices.


ii). In each of the office the management wants that each LAN segments gets a dedicated
bandwidth i.e., bandwidth must not be shared. How can this be achieved?
iii). Where would you suggest the placement of server?
iv). The company wants to link its head office in UOffice to its office in London.
1. Which type of transmission medium is appropriate for such a link?
2. What type of network would this connection result into?

6 ABC SWITCHGEARS LTD in Srinagar is setting up the network between its different departments
located in different wings. There are 4 wings named as Manufacturing (M), Research (R),
Administration (A) and Personnel (P). Distances between various wings are given below:

Wing A to Wing M 100 m


Wing A to Wing R 200 m
Wing A to Wing P 400 m
Wing M to Wing R 300 m
Wing M to Wing P 100m

135
Wing R to Wing P 450 m
Number of Computers:
Wing M 15
Wing R 80
Wing A 50
Wing P 250
i. Suggest a suitable Topology for networking the computers of all wings.
ii. Suggest the placement of Repeater, with justification.
iii. Suggest the placement of Hub/Switch in the network.
iv. Mention an economic technology to provide Internet accessibility to all wings.

7 Standard Bank has set up its new center in Kolkata for its office and web based activities. It has five
buildings as shown in the diagram below:

A B C

D E

Distance between various buildings


A to B 50 Mtrs No of computers
B to C 30 Mtrs A 55
C to D 30 Mtrs B 180
D to E 35 Mtrs C 60
E to C 40 Mtrs D 55
E 70
E to B 60 Mtrs
D to B 45 Mtrs
E to B 65 Mtrs

i) Suggest a possible cable layout for connecting the buildings, where the bank wants least cable cost.
ii) Suggest the most suitable place to install the server of this organization with a suitable reason.
iii) Suggest the placement of the following devices with justification.
(1) Hub/Switch (2) Modem
iv) The company wants to link its head office in ‘A’ building to its another Office in Sydney
(1) Which type of transmission medium is appropriate for such a link? The Bank wants high
speed & security at any cost.
(2) What type of network this connection result into?

8 DAVPublic School in Kollam is setting up the network between its different wings. There are four wings
named as Seniors (S), Kids (K), Juniors (J) and Hostel (H). Distance between various buildings is
given below:

Wing K to S 100m
Wing K to J 200m
Wing K to H 400m
Wing S to J 300m
136
Wing S to H 100m
Wing J to H 450m Wing K 10 Computers
Wing J 100 Computers
Wing H 50 Computers
Wing S 200 Computers

(i) Suggest a valid economical cable layout and topology for networking the computer of all wings,
where the institute will compromise on speed and traffic load.
(ii) Suggest the type of cable to be used in n/w, very economical.
(iii)Suggest the placement of Hub, Switch and repeater in the network.
(iv) Suggest a most economical way to connect with the head office of school which is located at
New Delhi.
9

Indian Industries Ltd. has the following four buildings in Chennai. Distances between various wings
are given below: Number of Computers
building 1 to 3 70m building 1 35
building 1 to 2 20m building 2 25
building 1 to 4 115m building 3 80
building 3 to 4 30m building 4 60
building 2 to 3 25m
Building 2 to 4 40m

i. Suggest suitable cable layouts for these buildings, also suggest the type of cable to be used,
where as the Company has installed lots of machineries in all the wings.
ii. Name the wing where the repeater and Hub/Switch is to be installed. Justify your answer.
iii. What type of network this connection result into?
10 iv. Mention an economic technology to provide Internet accessibility to all wings.

JCT Industries has set up its new center at Chohal for its office and web based activities. The
company compound has 4 blocks as shown in the diagram below:

Block A Block C

Block B Block D

Center to center distances between various blocks is as follows:


Block A to Block B 50 m
Block B to Block C 130 m
Block C to Block D 70 m
Block A to Block D 180 m
Block B to Block D 160 m
Block A to Block C 80 m
Number of Computers in each of the blocks is as follows:
Block A -- 30 | Block B -- 60 | Block C -- 135 | Block D -- 15
1) Suggest a cable layout of connections between the blocks.
2) Suggest the most suitable place to house the server of this company with a suitable reason.
3) Suggest the placement of Repeater, with justification:
4) Mention the efficient method/technology to connect this network with the office in another city
11 like Mumbai in India. The company wants the communication should be very fast and effective at
any cost.
“Kanganalay Cosmetics” is planning to start their offices in four major cities in Uttar Pradesh to
provide cosmetic product support in its retail fields. The company has planned to set up their offices
137
in Lucknow at three different locations and have named them as “Head office”, “Sales office”, &
“Prod office”. The company’s regional offices are located at Varanasi, Kanpur&Saharanpur. A rough
layout of the same is as follows :

UP Lucknow

Head
Sales

Produc
tion

Saharanpur Kanpur
office Office
Varanasi
Approximate distances between these offices as per network survey team is as follows :
Office
Place from Place to Distance
Head office Sales office 150M
Head office Prod office 80M
Head office Varanasi Office 295 KM
Head office Kanpur Office 195 KM
Head office Saharanpur office 408 KM

Number of computers :
Head office 156
Sales office 25
Prod office 56
Varanasi Office 85
Kanpur Office 107
Saharanpur office 105

(i) Suggest the placement of the repeater with justification in Lucknow city network.
(ii) (a) Suggest the device to be procured by the company for connecting all the computers within
each of its offices out of the following devices :
• Modem
• Telephone
• Switch/Hub
(b) If we connect all offices in UP in a network, then which type of this network is called?
12 (iii) Suggest an economical way to connect all offices in UP.

Indus group has set up its new center at India for its office and web based activities. It has 5
buildings as shown in the diagram below:

A B C

D E

Center to center distance between various buildings No of computers


A to B 50 Mtrs A 55
B to C 30 Mtrs
B 180
C to D 30 Mtrs
C 60
D to E 35 Mtrs
E to C 40 Mtrs 138
D to A 120 Mtrs
D to B 45 Mtrs
E to B 65 Mtrs
D 55
E 70

i) Suggest a possible cable layout and topology for connecting the buildings. The company wants full
security and less n/w traffic.
ii) Suggest the most suitable place to house the server of this organization with a suitable reason.
iii) Suggest the placement of the following devices with justification.
(1) Hub/Switch (2) Modem
iv) The company wants to link its head office in ‘A’ building to another office in Oman.
(1) Which type of transmission medium/Tech is appropriate for such a link?
(2) What type of network this connection result into?
Answers- Unit -7: Communication and Networking
Total Marks= 10
Q. No. Answers
A. Theoretical-Answers

1 A computer network is interconnected computers, by which they are capable of exchanging


information and take the advantages of other network services like: remote accessing, resource
sharing etc. Advantages of computer network are as follows:
• Resource sharing – sharing of hardware and software resources among network
computers
• Remote accessibility- access of a remote system through network
• Communication- most friendly and effective use of network by which information can
be exchanged from one computer to others.

2 Message switching: A source computer sends data or message to another computer and the
whole message will transfer as a group from sender to first switching office and from that place
to the receiver’s switching office.
Packet Switching: In this technique the whole message will divided into smaller packets, where
each packet contains one header. The header kept the information of sender and receiver. All
the packets travel through network from sender to receiver. The advantage of this technique is,
less chance of loss of whole information and if any packet lost, then it can be easily
retransmitted.

3 There are 2 types of transmission mediums used in the networking:


• Guided Media: Twisted Pair Cable, Coaxial Cable, Fiber Optic Cable etc
• Unguided Media: Micro Wave, Radio Wave, Infrared, Laser, Satellite etc.
Guided Media are used for a short distance (local area), where as unguided media are used in
long distance transmission.
Twisted Pair Cable: A pair of wire twisted together, very light in weight, cheap, physically
flexible and easy to install and maintain. High attenuation effects, short length capacity, lower
bandwidth, low speed etc. (Max. range is upto 100 meters)
Two types: UTP (Unshielded Twisted Pair Cable ), STP (Shielded Twisted Pair Cable)
Coaxial Cable: single solid core conductor, surrounded with insulator and wire mesh with
outer shield, which gives mechanical strength and less attenuation effects. Generally used in TV
cable. Better performance- high bandwidth, less data errors, high speed and solid strength.
Costly than TP cable, not compatible with TP cables. (Max. Range is up to 500 Meters)
Fiber Optical Cable: It consists of thin strands of glass or glass like material, which can carry
light from one place to another. It uses light waves in place of emi wave as in other cables.
Central core made of fiber, covered by cladding (Highly reflective index material) and than a
PVC Sheath. These are fragile and special caring steps are required to install. Coupling and
soldering of two cables is very difficult. It is very costly but it gives very fast and secure
transmission.

139
It is immune to electrical and magnetic interference because it uses light as carrier. Very fast
and very high bandwidth, suitable for harsh industrial environment.
(Max. range is up to 2 km)

Type Range Bandwidth Cost Interferences


(max.) (Supported)
1. TP Cable 100 mtrs 100 – 500 Mbps cheapest High

2. Coaxial 185 to 10 – 500MBps cheap- moderate


500 mtrs moderate

3. Fiber 2km 100MBps-2GBps Expansive none

Difference between optical fiber & coaxial Cables:

Optical fiber Coaxial


1. HighRange upto 2 Km Low range, upto 500 mtrs

2. High Bandwidth in GB Low Bandwidth in MB

3. High Speed Low Speed

4. High Cost Low Cost

5. Zero Interferences Interferences may be created


4 The types of network are LAN, MAN and WAN.
LAN WAN
1. Small range 1. Unlimited range
2. High speed 2. Medium speed
3. Very low data error rate 3. Data error rate high
4. Managed and controlled by 4. By different groups
one person or unit. 5. No of computer are
5. Less no of computers unlimited
The various network topologies are Star, Bus, Ring, Tree, graph etc.
5 Star Topology:
Advantage Disadvantage
1. It provide easy access to node 1. Long cable length
2. Centralised control 2. Difficult to expand
3. Simple access protocols 3. Central node dependency
4. One device attached to one 4. Setup depends on area
5. Costly
Bus Topology:
Advantage Disadvantage
1. Short cable length 1. Fault diagnosis is difficult.
2. Simple architecture 2. Specific protocols required
3. Easy installation to manage traffic.
4. Easy to extend

Ring Topology:
Advantage Disadvantage

140
1. Short cable length 1. One node failure break
down the n/w
2. Suitable for optical fiber 2. Difficult to diagnosis
3. Easy installation 3. Reconfiguration is difficult
4. Separate server not 4. Node should be intelligent
require
Tree Topology:
required when a specific hierarchical structure of network is there. Easy to diagnose the error,
easier to extend and maintain. Costly and depends upon the circumstances and the area covered.
Graph Topology: computers are connected in an arbitrary fashion, so no such exact structure
defined for this. High cost and require specific protocols to manage. Ease of connectivity
between nodes in the network.
Fully connected: all computers are connected together by a separate path (cable).

6
MODEM: (Modulator Demodulator) It is a communication device, which is used with a
computer to convertthe outgoing signals into analog form and converting incoming signals into
digital form. Generally used in dial up network through telephone line.
SWITCH: It is network connecting device, by which a set of computer connect together in a
network. It is a network junction. It supports separate network path to all connected device and
allots dedicated bandwidth to all devices.
HUB: It is network connecting device, by which a set of computer connect together in a
network. It is a network junction. It uses broadcast method to connect all connected devices and
all devices shares a common bandwidth.
BRIDGE: It is a network device which connects two LAN segments, having same standard but
with different types of cables. It makes an intelligent physical connection between the nodes
and then provides the communication.
ROUTER: It is also called smarter bridge, it uses logical addressing, whereas the bridge uses
physical addressing. A Router can join two different LAN segments with different type of
cables and different protocols.
REPEATER: It is also called a Signal Repeater, which receives the poor signal and amplify
them and retransmit to the destination. An active repeater can eliminate the noise or
disturbances occurred in the signal and then retransmit with more power.
GATEWAY: It is a network device that can connect the completely different networks and
provide the communication. It provides the networking services (between LAN-LAN,
LAN - WAN) and also gives the security to different networks.
ETHERNET Card: Ethernet is a LAN architecture developed by Xerox in association with
DECand Intel. It used in Star or Bus Topology and provide network communication up to 10
Mbps. The Ethernet card is an interface unit, which can be inserted into computer’s
motherboard to connect it into a LAN. It consists of different type of connectors to support
7 different type of cables.
Switch Hub
• Connect a set of nodes. • Connect a set of nodes.
• Provides a separate dedicated path • It broadcast the i/p signal to all
to a node. nodes.
• All connected nodes have • All connected nodes share a
dedicated bandwidth. common bandwidth.
• Can amplify the incoming signal. • Can amplify the incoming signal.
8
HTTP: Hypertext Transfer Protocol is an application level protocol, which allows user to
open/read/close a webpage from a particular destination. It transfers the webpage from the web
servers to the user’s pc, containing the hypertext like information. It has been used by WWW
since 1990. It is also used as generic protocol with others like: FTP, SMTPetc.
FTP: File Transfer Protocol is a most important protocol, used for transferring files from one
system to another. It is an effective way to transfer files among geographically dispersed
groups.

141
TCP/IP: Transmission Control Protocol / Internet Protocol is a layered set of protocols used for
internet. It is used to control the information transmitted on internet and it keeps track of what is
sent and received. It manages the retransmission if any thing is missing during transmission and
manages the information to be reach at right destination.
9
TDMA: Time Division Multiple Access is a technology for delivering digital wireless service.
It divides a radio frequency into different time slots and then allocating slots to multiple calls,
by this a single frequency. It supports multiple simultaneous data channels. This technique used
by GSM communication.
SIM: Subscriber’s Identification Module is a small size integrated chip, which gives a cellular
phone a unique phone number and allows user to communicate with other phone user in any
network. It also has some memory to store the numbers of other user’s and call data.
GSM: Global System for Mobile communication, it is one of the leading mobile
communication technology. It allows the mobile phone users with SIM card to be connected
with other phone users in a particular of network. GSM works on TDMA technique, which
allows eight simultaneous calls at a time. GSM digitize and compress the voice data and then
send to other user. It also uses encrypted information system to make the phone call secure.
CDMA: Code Division Multiple Access is a digitalcellular technology, which uses spread
spectrum techniques. It encodes the individual conversations into a pseudo-random digital
sequence and which will spread over the entire bandwidth by a unique spreading code. At the
receiver end the same unique spreading code is used to decode/recover the signal. It provides
wide bandwidth and better accessibility in multiple calls.
WLL: Wireless in Local Loop is mobile communication technique, which is restricted to a
local area. It gives mobile communication in local range and outside the range of local area this
will not work. It is just like a landline phone without cord having range 1-25 Km.
3G: 3rd Generation Techniques for mobile communication. It gives very wide range of
bandwidth with enhanced data rate. It is a broadband packed base transmission which is capable
of transmitting voice signal with video, text and hypermedia at a high data rate more than
2Mbps. It can interface with other service also like GSM,CDMA etc. It uses a new interface to
meet the higher bandwidth with high data rate, called EDGE (Enhanced Data rates for Global
Evolution). EDGE is a radio based high speed mobile data standard, which gives a higher
transmission speed of 384 kbps in fully eight time slots at a working time.
SMS: Short Message Service is the transmission of short text message to and from a mobile
phone. It is managed by Short Message Service Centre of the mobile service provider agency.
The text limit is also provided by the provider.
VoiceMail: a type of email which support voice signal in transmission. By which we can send
the audio or voice based signal to any recipient.
10
WWW: World Wide Web is a set of protocols, which allows accessing any
document/information on the web (net). This is a web browser, which browse the information
from internet and provide to the individuals. It supports all type of information like: text, audio,
video, hypertext, hyperlinks etc. it accepts the user’s request through a naming system based on
URL and respond very fast.
HTML: Hypertext Markup Language is a document layoutand hyperlink specification
language, which is used to design the layout of the web pages. It includes a set of commands to
control the presentation of information on a web page, called Tags.
DHTML: Dynamic HTML it gives the layout of webpages dynamic in nature, which means
they will change the behaviour or style at run time or at presentation. It allows to add the scripts
written in some other languages (like VB, java, applets etc.) with the HTML layout, which
gives animation, Popups and other graphical interactivities.
XML: Extensible Mark up Language for documents containing structured information. It
defines a standard way to add mark up to documents. It provides the facility of user defined tags
and the structural relationships to create web documents.
11
URL: Uniform Resource locator is an address or path of web site/page, which tells the location
of web page of web document. All files of documents on internet must be known or accessed by
a unique location or path called, URL. An URL contains:

142
• type of server or protocol
• name or address of the web server
• location of the file on server
• domain
• zone
For example: http://www.yahoo.com, http: is the protocol server and name of web server is
yahoo and www is the web browser and com is the domain of the website. Sometime a zone
field also inserted at the end of url like: www.goidirectory.gov.in
Here .gov is the domain and .in is the zone, which specify for India.
Some most common domainsare as follows:
Com- commercial
Edu- educational
Gov- government
Net- network
12 The various zone are:au : Australia, ca- Canada, in- India, jp – Japan, us – United States etc.
CyberLaw refers to all legal and regulatory aspects of internet and the world wide web. It
defines the laws for accessing the internet, if any thing not attempted as per cyber law is called
cyber crime. The classification of cyber crime is as follows:
1. Tampering with computer source documents
2. Hacking any computer or internet website/location
3. Publishing of illegal information
4. Child Pornography
13 5. Accessing protected system
Web hosting is the process of loading the information or webdocuments on to a web server. The
web server can broadcast that information over internet. Type of web hosting are as follows:
(i) Free Hosting: hosting on web server is free of cost, such as gocities, tripod,
homestead etc.
(ii) Virtual or Shared Hosting: hosting on a web server, which also hosts other
websites.
(iii) Dedicated Hosting: one can take entire web server on rent for personal websites
storage only.
(iv) Co-location Hosting: is similar to dedicated hosting except that the server is
provided by the user’s company and all physical needs are provided by the web
hosting company.
14 Network security means only authorized user will access the network and there should be a
defined access rules. To maintain security, some mechanism have to use to stop cyber crime
and save the network resources called network security method or protection method, like:
1. Authorization
2. Authentication
3. Encrypted smart cards
4. Firewall
5. Biometric systems
15 Hackers Crackers

143
• Are more interested in gaining • Are malicious person or group who
knowledge about computers and breaks the secure system
possibly using this knowledge for • Someone who breaks into or otherwise
playful pranks violates the system integrity of remote
• Someone intensely interested the machines with malicious intent.
working of any computer operating • Can obtain unauthorized access, in which
system. they: Destroy vital data, Deny legitimate
• They probe the system, at both users service, real overall havoc for their
macro and microcosmic level, targets.
finding software’s holes and snag in • They don’t write their programs, they
logic. beg, borrow or steal tool from others, but
16
• They write programs to check the they are expert in using these programs.
integrity of other programs or
system.

Cookies: are messages that aweb server transmits to a web browser so that the web server can
keep track of the user’s activity on a specific website. Cookies are not used maliciously on
computer systems, they can not spread like virus and they are not relevant to user’s privacy
and anonymity on the internet.
17
Firewall: A system designed to prevent unauthorized access to or from a private network is
called, Firewall. It will scan all information passes by/to user and that can be prohibited for a
particular area.

A virus is a malicious program that is designed in such a way to destroy the system. Virus can
replicate itself in system at anywhere and can destroy anything. Examples: Trojan Horse,
Worm, spam etc. Some steps require to avoid the virus:
1. Don’t use any external media before scanning by an antivirus.
2. Always scan the downloaded files.
18
3. Use licensed software.
4. Password protect your computer.
5. Install and use the antivirus program.

A Bandwidth is the difference between the highest and lowest frequencies of a transmission
channel or the amount of digital information that can travel through a channel is the bandwidth.
The units to measure the communication speed are as follows:
bps: bits per second
Bps: Bytes per second
kbps: kilo bits per second
Kbps: Kilo bytes per second
Similarly mbps, Mbps and gbps also possible.

Expand the following terms:


1. IP : Internet Protocol
2. TCP/IP: Transmission Control Protocol / Internet Protocol
3. NSF: National Science Foundation
4. Mbps: Mega Byte per Second
5. ISP: Internet Service Provider
6. HTTP: Hypertext Transfer Protocol
7. EDGE: Enhanced Datarate for Global Evolution
8. SLIP/PPP: Serial Line Internet Protocol / Point to Point Protocol
9. SIM : Subscriber Identification Module
10. POP : Post Office Protocol
11. DNS: Domain Name Service
12. XML: Extensible Markup Language
13. WLL: Wireless in Local Loop
14. NIU: Network Interface Unit
15. ARPANET: Advance Research Project Agency Network
144
19 16. OSS: Open Source Software
17. VGM: Voice Grade Media
18. Mhz: Mega Hertz
19. URL: Uniform Resource Locator
20. FTP: File Transfer Protocol
21. CDMA: Code Division Multiple Access
22. GSM: Global System for Mobile Communication
23. SMS: Short Message Service
24. HTML: Hypertext Markup Language
25. DHTML: DynamicHTML
26. FSF: Free Software Foundation
27. GNU: GNU Not UNIX
28. W3C: World Wide Web Consortium
20
Open Source Software is the software, which does not need much restrictions or conditions.
That is, this software is for the users including source code and it can be modified without any
prior permission and also it can be freely redistributed to others. It does not free of cost, some
21
payment you have to pay to take the OSS.
The various features of open source software are as follows:
• Free redistribution
• No discrimination against persons or groups
• Source code is available
• Modification is possible
• License must not be specific to a product
There are two category of open source software:
1. OSS: Open Source Software
2. FLOSS: Free software as well as open source (Free livre and Open Source Software)
Free Software: is available free of cost and it can be freely used, changed, copied and
redistributed. Free software is not equal to freeware, because freeware does not allow
modifying. Example of Free Software: UNIX, Linux, Apache etc.
Freeware: are software’s available free of cost but its modification is not possible because
source code is not given. Its copies can be distributes freely and can use for long time.
Shareware: are the software, which can be available freely only for a limited period including
redistribution of its copies. But its source code is not available and it can not be modified.
Proprietary (Enterprise) software is specifically designed for an enterprise or organization,
which is not available freely. It should be legally purchased by the organization and it can be
customize in a restricted way and it should not be redistributed.
B. LAN Design: Answers

1 (i) • Head Office and Tech Office = LAN


• Head Office and Coimbatore Office = WAN
(ii) Switch/Hub
(iii) Optical Fibre
(iv) Layout 1: (Star Topology)

Total Cable Length: 90 mtrs Head


70
20

Sales Tech

Use Wireless communication medium (Satellite or Radio wave) to connect the company’s
regional offices at “Kolkata”, “Coimbatore” and “Ahmedabad” with the New Delhi office in
efficient way.

145
2 (i) • Back Office and Work Office = LAN
• Back Office and South Office = WAN
(ii) Switch/Hub, device used to connect a set of computers together in a LAN.
(iii) Twisted Pair Cable
(iv) Layout 1: (Star topology) Back
Total Cable Used: 115 mtrs Office
25 90
Front Work
Office Office

Use Satellite Communication to connect the company’s regional offices at “East Office”, “West
Office” and “South Office” with offices located in Mumbai with high speed and security.

3 i) Layout 1: (Star topology)

50 W1 60

90 W2

W3 W4
Total Cable Used: 200 Meter

(If W4 connects with W2 than one another also possible in this layout total cable used is less
that is: 135 Meters, but in that case Star topology will not work)
ii) The server should be place in the W1 Wing of the building, because this wing contains
number of computer are very large (150), as we compare with others. As per 80:20 rule of the
LAN design, the server should be placed in a block/building where the 80 % of the network
traffic should be local and this wing has the ratio of 150:55 of computer. So the network traffic
in this wind will be highest.
iii) 1) Internet connecting device/modem: this should be placed in wing W1 with server to
provide the internet services to all other wings.
2) Switch / Hub: Switch and Hub should be used in each wing to connect their computers and
other networking devices.
iv) The most economic way to connect in a wide area network is via a Radio Wave
Transmission method. That is an effective and very low in cost/speed as compare to Satellite
communication.

4 (i) Layout: 1
50 70
Building 3

Building 2 Building 5
20
30
Building 1 Building 4

Total Cable Used: 170 Meters (Bus Topology)

(ii) The server should be place in the Building 3, because this Building contains number of
computer are very large (110) as we compare with others. As per 80:20 rule of the LAN
design the server should be placed in a block where the 80 % of the network traffic should
be local. As per specified in the question that Building 3 is used for many critical

146
operations, so the network traffic in this wind will be highest.
(iii) Switch should be used in each building, because switch minimizes the traffic and gives
dedicated bandwidth.
(iv) Use Microwave/Radio Transmission

5 (i) Layout 1: UOffice JOffice

60
24
55
Aoffice KOffice
Star Topology used.
Total Cable used = 139 mtrs
(ii) Layout 2:
Linear Topology
Total Cable used: 94 mtrs. UOffice JOffice

15 24

Aoffice 55 KOffice

(ii) Switch should be used in these offices, because switch minimizes the traffic and gives
dedicated bandwidth in place of Hub. Bridge can also be inserted to join the segments.
(iii) The Server should be places in the KOffice, because this Office contains number of
computer are very large (200), as we compare with others. As per 80:20 rule of the LAN design
the server should be placed in a block where the 80 % of the network traffic should be local.
(iv) 1. Wireless (use radio/ Satellite transmission) Medium
2. WAN

6 (i) Linear Topology (Bus), because the distances between the wings are more so other
topologies are having high cable cost and difficult structure. Total cable Length = 400 mtrs.

200 100 100


R A M P

(ii) Repeater should be placed between each building, because of more distance among wings.
(iii) Hub/Switch should be installed in each wing to connect their computers.
(iv) Use broad band internet service/ Lease Line for getting good speed and connectivity and
share internet by server in all wings.

7
(i) Layout-1 50 30
A B
C
30
Linear Topology
Total Cable Length: 145 35 E
D

ii) The server should be placed in Building B (180 Computers), because it has more computers
and as per 80:20 rules the maximum traffic should be local.
iii) (1) Hub/Switch : to be used in every building to connect all subnet in to LAN
(2) Modem: Modem is required when they want the dial up network service. It should be

147
with the server.
iv) (1) Wireless (1. Satellite Transmission )
(2) WAN
8 (i) Layout-1
200 100 100
J K S H

Linear Bus Topology


Total Cable Length: 400 mtrs.
Linear topology with TP cable is suited as per requirement specified in question, because it is
economical and easy.
(ii) Use Twisted pair cable (UTP-Cat-4)
(iii) Hub/Switch : to be used in every building to connect all subnet in to LAN
Repeater : can be placed between J to K, K to S and S to H (Total 3 repeater)
(iv) The most economic way to connect it with a reasonable high speed would be to use Radio
wave transmission. As that is easy to install, can travel long distance and penetrate through
buildings easily.
9 (i) Layout-1
1 2 3 4
20 25 30

Linear Bus Topology


Total Cable Length: 75 mtrs.20 1 3
Layout-2 20 30
25
Ring Topology
2 4
Total Cable Length: 95 mtrs.

Type of cable suggested: Fiber Optical Cable (Harsh Industrial Environment)


Type of topology layout used: Layout-2 Ring Topology most suited by Fiber Optical Cable.
(ii) Hub/Switch : to be needed in every Wing to interconnect the group of cables from
different computers. Repeater is not required in n/w because the lengths among nodes are less.
(iii) LAN
(iv) Use Broad band internet service for getting good speed and connectivity, shared in all
Wings by server.

10 (i) Layout-1
50 80 70

B A C D

Linear Bus Topology


Total Cable Length = 200 mtrs.
(ii) The server should be placed in Block C (135 computers), because it has more computers
and as per 80:20 rules the maximum traffic should be local.
(iii) The placement of repeater will depends on the type of cable.
For Twisted pair cable: Repeater can be placed between Block A and Block C and Block C
and Block D.
(iv) Use satellite communication for fast and secure communication. The distance between the
given network and Mumbai city is not given, if it is around 100 Km than Microwave
Transmission is best.

11 (i) Repeater can be placed between Hoffice to Sales and Hoffice to Production Office, due to
distance is more than 80 km.

148
(ii) (a) Switch/Hub
(b) WAN
(iii) Microwave communication is best for all UP n/w, radio wave can also be used.

12 (i) Layout 1: Star Topology


50 30
A B C
45 65

D E
Total Cable Length: 190 mtrs.
Suggested Layout -1 for the n/w, for less traffic and security.
(ii) The server should be placed in Building B (180 computers), because it has more computers
and as per 80:20 rules the maximum traffic should be local.
(iii) Hub/Switch to be needed in every Building to interconnect the group of cables from
different computers.
Modem should be placed in Building B, with the server, to share the internet.
(iv) (1) Wireless Medium( Satellite/Radio)
(2) WAN

149
CBSE- All India Senior Secondary Certificate Examination-2013-14 (Out Side Delhi)
Subject: Computer Science (083)
Time Allowed: 3 Hours Max. Marks: 70
1. (a) What is the difference between call by reference and call by value with respect to memory 2
allocation? Givea suitable example to illustrate using C++ code.
(b) Observe the following C++ code and write the name(s) of the header file(s), which will be 1
essentially required to run it in a C++ compiler:
void main()
{ char CH, STR[20];
cin>>STR; CH=toupper(STR[0]);
cout<<STR<<" Starts with"<<CH<<endl;
}
(c) Rewrite the following C++ code after removing all the syntactical errors(s), if present in the 2
code. Make sure that you underline each correction done by you in the code.
Important Note:
1) Assume that all the required header files are already included, which are essential to run this code.
2) The corrections made by you do not change the logic of the program.
typedef char[80] STR;
void main()
{ Txt STR;
gets(Txt);
cout<<Txt[0]<<’\t<<Txt[2];
cout<<Txt<<endline;
}
(d) Obtain the output from the following C++program as expected to appear on the screen after its 2
execution. Important note:
- All the desired header files are already included in the code, which are required to run the code:
void main()
{ char *Text=”AJANTA”;
int *P, Num[ ] = {1, 5, 7, 9};
P=Num;
cout<<*P<<Text<<endl;
Text++; P++;
cout<<*P<<Text<<endl;
}
(e) Obtain the output from the following C++program, which will appear on the screen after its 3
execution. Important note:
- All the desired header files are already included in the code, which are required to run the code:
class game
{ int Level, Score;
char Type;
public:
Game(char GType = 'P')
{ Level =1; Score = 0;Type = GType; }
void Play (int GS);
void Change ();
void Show()
{ cout<<Type<<"@"<<Level<<endl;
cout<<Score<<endl;
}
};
void main()
{ Game A('G'), B;
B.Show();

150
A.Play(11);
A.Change();
B.Play(25);
A.Show();
B.Show();
}
void Game::Change()
{ Type=(Type=='P')? 'G' : 'P';
}
void Game::Play(int GS)
{ Score += GS;
if(Score>=30) Level = 3;
else if (Score>=20) Level = 2;
else
Level=1;
}
(f) Observe the following program and find out, which correct output(s) out of (i) to (iv) will be 2
expected from the program? What will be the minimum and the maximum value assigned to the
variable Taker?
void main()
{ int GuessMe[4]={100, 50, 200, 20};
int Taker = random(2) + 2;
for(int Chance = 0; Chance<Taker ; Chance++)
cout<<GuessMe[Chance]<<”#”;
}
(i) 100# (ii) 50#200#
(iii) 100#50#200# (iv) 100#50

2.(a) What is function overloading? Write an example using C++ to illustrate the concept of function 2
overloading.
(b) Answer the questions (i) and (ii) after going through the following class: 2
class Hospital
{ int Pno, Dno;
public:
Hospital(int PN); //Function 1
Hospital(); //Function 2
Hospital(Hospital &H); //Function 3
void In(); //Function 4
void Disp(); //Function 5
};
void main()
{ Hospital H(20); //Statement1
}
(i) Which of the functions out of Functions 1, 2, 3, 4 or 5 will get executed when the
statement 1 is executed in the above code?
(ii) Write a statement to declare a new object G with reference to already existing object H
using Function 3.

(c) Define a class Tourist in C++ with following description: 4


Data Members:
• CNo – to store Cab No
• Ctype – to store a character ‘A’, ‘B’, or ‘C’ as City Type
• PerKM – to store per Kilo Meter Charges
• Distance – to store Distance Travelled (in KM)

151
Member Functions:
• A constructor function to initialize CType as ‘A’ and CNo as ‘0000’.
• A function CityCharges() to assign PerKM as per the following table:
CType PerKM
A 20
B 18
C 15
• A function RegisterCab() to allow administrator to enter the values for CNo and
CType. Also, this function should call CityCharges() to assign PerKM Charges.
• A function Display() to allow user to enter the value of Distance and display CNo,
CType, PerKM, PerKM*Distance(as amount) on screen.
(d) Consider the following C++ code and answer the questions (i) to (iv): 4
class University
{ long Id;
char City[20];
protected:
char Country[20];
public:
University();
void Register();
void Display();
};
class Department : privateUniversity
{ char HOD[20];
longDCode[10];
protected:
double Budget;
public:
Department();
void Enter();
void Show();
};
class Student : publicDepartment
{ long RollNo;
char Name[20];
public:
Student();
void Enroll();
void View();
};
(i) Name the type of inheritance illustrated in the above C++ code;
(ii) Write the name of those member functions, which are directly accessible from the objects
of class Student.
(iii) Write the names of those data member, which can be directly accessible from the member
functions of class Student..
(iv) Is it possible to directly call function Display() of class University from an object of class
Department?

3.(a) Write code for a function void EvenOdd (intT [], int C) in C++, to add 1 in all the odd values 3
and 2 in all the even values of the array T.
For example: if the array contents are: 35, 12, 16, 69, 26
The content of array after modify are : 36, 14, 18, 70, 28

(b) An array A [20][30] is stored in the memory along the row with each of the elements occupying 3
4 bytes. If the base address of array A is 32000, Find out the memory location of A
[15][10].Also, find the total number of elements present in this array.

152
(c) Write a user defined function AddEnd2 (int A [] [4], int N, int M) in C++ to find and display the 2
sum of all the values, which are ending with 2(i.e. units place is 2).
For example if the content of array is: 22 16 12
19 5 2
The output should be: 36

(d) Evaluate the following Postfix notation. Show status of Stack after every step of evaluation( i.e. 2
after each operator): T, F, NOT, AND, T, OR, F, AND

(e) Write a function PUSHBOOK () in C++ to perform insert operation on a dynamic Stack, which 4
contains Book_no and Book_Title. Consider the following definition of NODE, while writing
your C++ code.
struct NODE
{ int Book_No;
char Book_Title[20];
NODE *Next;
};
4.(a) Observe the following program segment carefully and fill in the blanks marked as statement-1 1
and statement-2, with appropriate functions for the required task.
class Agency
{ int Ano; //Agent Code
char AName[20]; //Agent Name
char Mobile[12]; //Agent Mobile
public:
void Enter(); //Function to enter details of agent
void Disp(); //Function to display details of agent
intRAno() { return ANo; }
void UpdateMobile() //Function to update Mobile
{ cout<<”Updated Mobile:”;
gets(Mobile);
}
};
void AgentUpdate ()
{ fstream F;
F.open("AGENT.DAT", ios::binary|ios::in|ios::out);
int Updt=0;
int UAno;
cout<<”Ano (Agent NO – to update Mobile) :”;
cin>>UAno;
Agency A;
while (!Updt && F.read((char *) &A, sizeof(A)))
{
if(A.Rno() == UAno)
{ ___________________ //Statement-1:To Call the function to update mobile No.
____________________//Statement-2 to reposition file pointer to rewrite the
// updated object back in the file.
F.write((char *) &A, sizeof(A));
Updt++;
}
}
if(Updt)
cout<<"Mobile Updated for Agent”<<UAno<<endl;
else
cout<<"Agent not in the Agency”<<endl;
F.close();
}

153
(b) Write a function AECount() in C++, which should read each character of a text file 2
NOTES.TXT, should count and display the occurrence of alphabets A and E (including small
cases a and e too).
Example: if the file content is as follows:
CBSE enhanced its
CCE guidelines further.
The AECount() function should display the output as: A: 1
E: 7

(c) Assume the class TOYS as declared below, write a function in C++ to read the objects of TOYS 3
from binary file TOYS.DAT and display those details of those TOYS, which are meant for
children of AgeRange “5 to 8”.
class TOYS
{ int ToyCode;
char ToyName[10];
char AgeRange;
public:
void Enter()
{ cin>>ToyCode;
gets(ToyName);
gets(AgeRange);
}
void Display()
{ cout<<ToyCode<<”:”<<ToyName<<endl;
cout<<AgeRange<<endl;
}
char * WhatAge() { return AgeRange; }
};

5.(a) Explain the concept of Cartesian Product between two tables, with the help of appropriate 2
example.
Note: Answer the questions (b) and (c) on the basis of the following tables SHOPPE and
ACCESSORIES.
Table : SHOPPE(ID mentioned in Q. Paper are wrong and different in the both tables)
ID Sname Area
SO1 ABC Computronics CP
SO2 All Infotech Media GK II
SO3 Tech Shoppe CP
SO4 Geeks Tecno Soft Nehru Place
SO5 Hitech Tech Store Nehru Place
Table: ACCESSORIES
NO Name Price Id
A01 Mother Board 12000 SO1
A02 Hard Disk 5000 SO1
A03 Keyboard 500 SO2
A04 Mouse 300 SO1
A05 Mother Board 13000 SO2
A06 Boarkeyboardd
Keyboard 400 SO3
A07 LCD 6000 SO4
A08 LCD 5500 SO5
A09 Mouse 350 SO5
A10 Hard Disk 4500 SO3
(b) Write SQL commands for the following statements: 4
(i) To display Name and Price of all the Accessories in ascending order of their Price.
(ii) To display Id and SName of all Shoppe located in Nehru Place.
154
(iii) To display the Minimum and Maximum Price of each Name of Accessories.
(iv) To display Name, Price of all Accessories and their respective SName where they are
available.

(c) Give the output of the following SQL queries: 2


(i) SELECT DISTINCT NAME FROM ACCESSORIES WHERE PRICE>=5000;
(ii) SELECT AREA, COUNT(*) FROM SHOPPE GROUP BY AREA;
(iii) SELECT COUNT(DISTINCE AREA) FROM SHOPPE;
(iv) SELECT NAME, PRICE*0.05 DISCOUNT FROM ACCESSORIES
WHERE SNO IN (‘SO2’,’SO3);

6.(a) Name the law shown below and verify it using a truth table: 2
X + X’.Y = X + Y

(b) Obtain the equivalent Boolean expression for the following Logic Circuit: 2
A

F
C
D

(c) Write the POS form of a Boolean function F, which is represented in a truth table as follows: 1

X Y Z F
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1

(d) Reduce the following Boolean Expression using K-Map: 3


F(A, B, C, D) = ∑(1, 3, 4, 5, 6, 7, 12, 13)

7.(a) Write two characteristics of Wi-Fi. 1

(b) What is the difference between E-mail and Chat? 1

(c) Expand the terms: GSM, GPRS 1

(d) Which type of network (out of LAN, PAN and MAN) is formed, when you connect two mobiles 1
using Bluetooth to transfer a video?

(e) Tech Up Corporation (TUC) is a professional consultance company. The company is planning 4
to set up their new offices in India with its hub at Hyderabad. As a network adviser, you have to
understand their requirement and suggest to them the best available solutions. Their queries are
mentioned as (i) to (iv) below.

155
Physical Locations of the blocks of TUC

Human Resource Block


Conference Block

Finance Block

Distances between various Blocks:


HR to Conference 60 m
HR to Finance 120 m
Conference to Finance 80 m

Number of Computers:
Block HR 125
Block Finance 25 CBS
Block Conference 60 E-
Seni
(i) What will the most appropriate block, where TUC should plan to install their server?
(ii) Draw a block to block cable layout to connect all the building in the most appropriate or
manner for efficient communication. Seco
(iii) What will be the best possible connectivity out of the following, you will suggest to ndar
connect the new setup of offices in Banglore with its London based office? y
➢ Infrared, satellite link , Ethernet cable Certi
(iv) Which of the following devices will be suggested by you to connect each computer in each ficat
of the blocks?
e
E.g. Gateway, Switch, Modem
Exa
mina
(f) Write names of any two popular Open Source Software, which are used as Operating Systems. 1 tion-
2013
(g) Write any two important characteristics of cloud computing. 1 -14
Subj
ect: Computer Science (083)
Solution
QN Answers
1.(a) Call by Reference: Does not create separate space for formal arguments, it uses the same memory
space allotted for the actual arguments. It also saqve memory space while calling, it takes only
memory references of the actual arguments in place of values, hence it takes less memory space.
Call by value: It creates separate memory space for formal arguments and while calling the actual
arguments’ values are copied into memory and then stored in theformal arguments. Hence it consumes
more memory space as compare to call by reference.
example:
void Fx(int x, float y) //arguments copied in to x & y variable separatly in memory
{ --------
}
void main()
{ int a;
float b;
cin>>a>>b;
Fx(a,b); //function call by value

156
------
}
//cal by reference method
void Fx(int & x, float & y) //x & y arguments created as reference to original variable a & b
{ --------
}
void main()
{ int a;
float b;
cin>>a>>b;
Fx(a,b); //function call by reference
------
}
(b) #include<iostream.h>, #include<ctype.h>
(c) typedef char STR[80];
void main()
{ STR Txt;
cout<<Txt[0]<<”\t”<<Txt[2];
cout<<Txt<<endl;
}
(d) Output: 1 AJANTA
5JANTA
(e) Output: P@1
0
P@1
11
P@2
25

(f) (III) 100#50#200#, MAX. value for Taker: 4 and min. value= 2
2.(a) Function overloading: it is an implementation of Polymorphism, a concept of OOP, which state that
more than function can be defined by a common name. the function should have change in their
signature. For example:
class temp
{ int t;float x;

public:
void Test(int r); //Function 1 need 1 argument
void Test(); // Function doesnot require any argument
void Test(int a, float b);//Function 3 need two arguments
_________
}

(b) (i) The function-1 will be invoked, when the statement-1 will executed.
(ii) Hospital G=H;// it will call the function-3, that is an copy constructor.

(c) class Tourist


{ char CNo[5];
char CType;
float PerKM;
int Distance;
public:
Tourist() { CType='A'; strcpy(Cno,"0000"); }
void CityCharges()
{ if(CType=='A')
PerKM=20;

157
if(CType=='B')
PerKM=18;
if(CType=='C')
PerKM=15;
}
void RegisterCab()
{ cout<<"Enter value for CNo & CType: ";
cin>>CNo>>CType;
CityCharges();
}
void Display()
{ cout<<"Enter the Distance: ";
cin>>Distance;
cout<<"CNo="<<CNo<<endl;
cout<<"CType="<<CType<<endl;
cout<<"PerKM="<<PerKM<<endl;
cout<<"PerKM x Distance="<<PerKM * Distance<<endl;
}
};

(d) (i) Multilevel Inheritance


(ii) Student::Enroll(),Student::View(),Department::Enter(),Department::Show()
(iii) RollNo, Name, Budget, (By Inherited Functions:- Dcode, HOD, Country)
(iv) No, because the function will inherit into its private section, so it can not be directly
accessible its objects.

3.(a) void EvenOdd (int T[], int C)


{ for( int i=0 ; i<C ; i++)
{ if(T[i]%2==0)
T [i] +=2;
else
T [i] +=1;
}
cout<<”Array content after modification:”<<endl;
for(i = 0; i<C; i++)
cout <<T[i]<<” “;
} //end of Function

(b) For the given Row Major order Array: w= 4, R= 20, C=30, Lr= Lc = 0, BA = 32000
Address of A[15][10] => BA + 4 ( (15-0)30 + (10-0))

 32000-460= 30160
Total number of elements in the array A= 20x30= 600

(c) void AddEnd2(int A[][4], int N, int M)


{int sum=0;
for(int i=0;i<N;i++)
for(int j=0; j<M; j++)
if(A[i][j]%10 = = 2)
sum += A[i][j];
cout<<"Output="<<sum<<endl;
}
(d) The given postfix expression is: T, F, NOT, AND, T, OR, F, AND
To evaluate this postfix expression, we process symbole one by one, scan from left to right and use
stack to store the result of each operation.

SNo Symbol Action Stack Evaluation

158
Scanned Performed
1 T Push True $T
2 F Push False $ T, F
3 NOT Calc. NOT $ T, T POP F, NOT F=T
push T
4 AND Cal. - AND $T T AND T= push T
5 T Push T $ T, T
6 OR Cal. - OR $T T OR T = push T
7 F Push F $ T, F
8 AND Cal. - AND $F T AND F= push F
Pop F as result
Ans: FALSE

(e) void PUSHBOOK(NODE *TOP)


{ NODE *PTR=new NODE;
cout<<"Enter new node information- Book number and Title:";
cin>>PTR->BOOK_NO;
gets(PTR->Book_Title);
PTR->Next=NULL;
if(TOP==NULL)
{ TOP=PTR;
cout<<"Stack is empty!!!Element insert at first place";
}
else
{ PTR->Next = TOP;
TOP=PTR;
cout<<"Element insert at first place in Stack!!!";
}
}//FUNCTION ENDED
4.(a) Statement 1: A.UpdateMobile();
Statement 2: F.seekp(-sizeof(A), ios::cur);

(b) void AECount()


{ int c=0;
char ch;
ifstream fin("NOTES.TXT");
while(!fin.eof())
{ fin>>ch;
if(ch= = 'A'||ch= = 'a'|| ch= = 'E' || ch= = 'e')
{ cout<<ch<<endl;
c++;
}
}
fin.close();
}//end of function;

(c) void ToyRec()


{ ifstream file;
TOYS T; int ctr=0;
file.open("TOYS.dat”,ios::in|ios::binary);
cout<<”Toys Records having AgeRange 5 to 8:\n”;
while(file.read((char *) &T, size(T)))
{if(strcmp(T.WhatAge(), “5 to 8”) = = 0)
{ T.Display();
ctr++;

159
}
}
if(ctr!=0)
cout<<"Total Record Found:"<<ctr<<endl;
else
cout<<”No Records Found!!!\n”;
file.close();
}
5.(a) A Cartesian Product is the cross multiplication of two relations, produces n+m degree relation (n and
m are the degrees of the two table) and nxm cardinality.
For example:
Table: EMP
EmpId Ename Job
1001 Amit singh Manager
1002 C. Swati UDC
Table:EmpacDetail
Hiredate Salary PAN
27-Aug-2002 35000 AY31TC1
01-Sep-2002 22000 FT45CR3
So EMP x EmpacDetails:-
EmpId Ename Job Hiredate Salary PAN
1001 Amit singh Manager 27-Aug-2002 35000 AY31TC1
1002 C. Swati UDC 01-Sep-2002 22000 FT45CR3
1001 Amit singh Manager 01-Sep-2002 22000 FT45CR3
1002 C. Swati UDC 27-Aug-2002 35000 AY31TC1

(b) (i) SELECT Name, Price FROM ACCESSORIESORDER BY Price;


(ii) SELECT Id, SName FROM SHOPPE WHERE Area=’Nehru Place”;
(iii) SELECT MAX(Price),Min(Price) FROM ACCESSORIES Group By Name;
(iv) SELECT Name, Price, SName FROM ACCESSORIES C, SHOPPE S WHERE C.Id = S.Id;
(i) Mother Board
(c) Hard Disk
LCD
(ii) CP 2
GK II 1
Nehru Place 2
(iii) Count(Area): 03

(iv) NamePrice*0.05
Keyboard 25
Mother Board 650
Keyboard 20
Hard Disk 225
(Note: Question (iv) has given wrong specification for SNO, It should be Id and for ‘DISCOUNT’ as constatnt
message. In the table also Id in both table are different.)

6.(a) X + X’.Y = X+Y is a Distributive law.


Proof of the law by using the truth table:
X Y X’ X’.Y X+X’.Y X+Y
0 0 1 0 0 0
0 1 1 1 1 1
1 0 0 0 1 1
1 1 0 0 1 1
Hence X + X’.Y = X+Y, Proved.

(b) The equivalent Boolean Expression of the logic circuit is: F = A’B + C’D

160
(c) The POS form of a Boolean Function F(X,Y,Z)=(X+Y+Z’) (X+Y’+Z) (X’+Y+Z) (X’+Y+Z’)

(d) The Karnaugh Map for the given Boolean function is:
AB\CD
0 1 1 0
1 1 1 1
1 1 0 0
0 0 0 0
There are 3 quads groups possible in this combination.
The reduced equation for quad 1: A’B
The reduced equation for quad 2: BC’
The reduced equation for quad 3: A’C’
So the final minimized expression for the F(A,B,C,D): A’B + BC’ + A’C’

7.(a) Characteristics of Wi-Fi:


1. Wi-Fi allows cheaper deployment of local area networks (LANs).
2. Also spaces where cables cannot be run, such as outdoor areas and historical buildings, can
host wireless LANs.
3. less installation and maintenance cost
4. Standard Wi-Fi device will work anywhere in the world.

(b) Differences between E-mail and Chat:


1. Chat occurs in near real-time while Email doesn’t.
2. Chat is a type of software while Email is a protocol.
3. Chat requires the permission of both parties while Email does not.
4. Chat is typically software dependent while Email is not.
5. Chat needs accounts on the same provider while Email does not.
6. Chat is able to convey voice and audio while Email cannot.

(c) • GSM stands for Global System for Mobile Communications and is the network standard
for much of the world.
• General packet radio service (GPRS) is a packet oriented mobile data service on the 2G
and 3G cellular communication system's global system for mobile communications
(GSM).

(d) When we connect two mobiles using Blutooth is can a PAN (Personal Area Network).

(e) (i) The server should place at Human Resource Block, due to maximum number of systems.
(ii) For efficient communication among the block, they should prefer Star Topology:

Human Resource Block


Conference Block

Finance Block

Total cabel length required: 180 Mtrs.

(iii) To connect new setup offices in Banglore with London Office a Satellite Link required.
(iv) To connect the computers they require Switch in each of the buildings.

161
(f) Most popular Open Source Operating Systems are: Ubuntu, FreeBSD, and OpenSolaris.

(g) Cloud computing is the delivery of computing as a service rather than a product, whereby shared
resources, software, and information are provided to computers and other devices as a utility.
Cloud computing exhibits the following key characteristics:
• Agility: improves with users' ability to re-provision technological infrastructure resources.
• Application Programming interface (API): accessibility to software that enables machines to
interact with cloud software in the same way that a traditional user interface (e.g., a computer
desktop) facilitates interaction between humans and computers.
• Cost: cloud providers claim that computing costs reduce.
• Device and location independence: enable users to access systems using a web browser
regardless of their location or what device they use (e.g., PC, mobile phone).
• Easier maintenance of cloud computing applications because they do not need to be installed
on each user's computer and can be accessed from different places.
• Multitenancy: enables sharing of resources and costs across a large pool of users.
• Increased Productivity due to multiple users can work on the same data simultaneously,
rather than waiting for it to be saved and emailed.
• Reliability improves

CBSE- All India Senior Secondary Certificate Examination-2011-12 (Out Side Delhi)
Subject: Computer Science (083)
Time Allowed: 3 Hours Max. Marks: 70
1. (a) Give the difference between the type casting and automatic type conversion. Also, give a 2
suitable C++ code to illustrate both.
(b) Which C++ header file(s) are essentially required to be include to run the following C++ source 1
code ( Note: Do not include any header file, which is/are not required):
void main()
{ char TEXT [ ] = " Something" ;
cout<<" Remaining SMS Chars : "<< 160 - strlen(TEXT)<<endl;
}
(c) Rewrite the following program after removing the syntactical errors (if any). Underline each 2
correction.
#include< iostream.h >
Class Item
{ long IID, Qty;
public:
void Purchase { cin>>IID>>Qty ; }
void Sale()

162
{ cout<<setw(5)<<IId<<" Old: "<<Qty<<endl;
cout<<"New: "<< --Qty<<endl;
}
};
void main()
{ Item I;
Purchase();
I.Sale();
I.Sale()
}
(d) Find the output of the following program: 3
#include<iostream.h>
class Metro
{ int Mno, TripNo, PassengerCount;
public:
Metro( int Tmno=1) { Mno=Tmno; TripNo=0; PassengerCount=0; }
void Trip ( int PC=20) { TripNo++; PassengerCount +=PC; }
void StatusShow() { cout<<Mno<<":"<<TripNo<<":"<<PassengerCount<<endl; }
};
void main()
{ Metro M(5), T;
M.Trip();
T.Trip(50);
M.StatusShow();
M.Trip(30);
T.StatusShow();
M.StatusShow();
}
(e) Find the output of the following program: 2
#inculde<iostream.h>
#include<ctype.h>
typedef char Str80[80];
void main()
{ char *Notes;
Str80 Str="vR2GooD";
int L=6;
Notes=Str;
while(L>=3)
{ Str[L]= (isupper(Str[L]) ? tolower(Str[L]) : toupper(Str[L]));
cout<<Notes<<endl;
L--;
Notes++;
}
}
(f) Observe the following program and find out, which output(s) out of (i) to (iv) will not be 2
expected from the program? What will be the minimum and the maximum value assigned to the
variable Chance?
#include<iostream.h>
#include<stdlib.h>
void main()
{ randomize();
int Arr[ ] = {9,6}, N;
int Chance=random(2) +10;
for(int C=0; C<2; C++)
{ N=random(2);
cout<<Arr[N]+Chance<<"#"
}

163
}
(ii) 9#6# (ii) 19# 17#
(iii) 19# 16# (iv) 20# 16#

2.(a) What is the difference between the members in private visibility mode and the members 2
inprotected visibility mode inside a class? Also give a suitable C++ code to illustrate both.
(b) Answer the questions (i) and (ii) after going through the following class: 2
class Travel
{ int PlaceCode; char Place[20]; float Charges;
public:
Travel() //Function 1
{ PlaceCode=1; strcpy(Place,"DELHI"); Charges=1000; }
void TravelPlan(float C) //Function 2
{ cout<<PlaceCode<<":"<<Place<<":"<<Charges<<endl; }
~Travel() //Function 3
{ cout<<Travel Plan Cancelled"<<endl; }
Travel(int PC, char P[ ], float C) //Function 4
{ PlaceCode = PC; strcpy(Place,P); Charges=C; }
};
(iii) In Object Oriented Programming, what are Function 1 and Function 4 combined
together referred as?
(iv) In Object Oriented Programming, which concept is illustrated by Function 3? When is
this function called/invoked?
(c) Define a class RESTRA in C++ with following description: 4
Private Members:
• FoodCode of type int
• Food of type string
• FType of type string
• Sticker of type string
• A member function GetSticker() to assign the following values for Sticker as per the
given FType:
FType Sticker
Vegetarian GREEN
Contains Egg YELLOW
Non-Vegetarian RED

Public Members:
• A function GetFood() to allow user to enter values for FoodCode, Food, FType and
call function GetSticker() to assign Sticker. 4
• A function ShowFood() to allow user to view the content of all the data members.
(d) Answer the questions (i) to (iv) based on the following:
class COMPANY
{ char Location[20];
double Budget, Income;
protected:
void Accounts();
public:
COMPANY();
void Regicter();
void Show();
};
class FACTORY : public COMPANY
{ char Location[20];
int Workers;
protected:
double Salary;
164
void Computer();
public:
FACTORY();
void Enter();
void Show();
};
class SHOP : private COMPANY
{ char Location[20];
float Area;
double Sale;
public:
SHOP();
void Input();
void Output();
};
(v) Name the type of inheritance illustrated in the above C++ code;
(vi) Write the name of data members, which are accessible from member functions of class
SHOP.
(vii) Write the name of all the member functions, which are accessible from the objects
belonging to class FACTORY.
(viii) Write the names of all the members, which are accessible from objects of class SHOP.

3.(a) Write a function SWAP2BEST (int ARR[ ] , int size) in C++ to modify the content of the array 3
in such a way that elements, which are multiples of 10 swap with the value present in the very
next position in the array.
For example: if the array contents are: 90, 56, 45, 20, 34, 54
The content of array after modify are : 56, 90, 45, 34, 20, 54
(b) An array T[20][10] is stored in the memory along the column with each of the elements 3
occupying 2 bytes. Find out the memory location of T[10][5], if the element T[2][9] is stored at
the location 7600.
(c) Write a function in C++ to perform Insert operation in a static circular Queue containing Book’s 4
information (represented with the help of an array of structure BOOK).
struct BOOK
{ long Accno; //Book Accession Number
char Title[20]; //Book Title
};

(d) Write a function Alternate(int A[][3], int N, int M) in C++ to display all alternate elements from 2
2-D array A(starting from A[0][0]).
For example: if the array is containing:
23 54 76
37 19 28
62 13 19 The output will be: 23 76 19 62 19
(e) Evaluate the following Postfix notation. Show status of Stack after every step of evaluation( i.e. 2
after each operator): True, False, NOT, AND, False, True, OR, AND

4.(a) Observe the program segment given below carefully and the questions that follows: 1
class Stock
{ int Ino, Qty; char Item[20];
public:
void Enter() { cin>>Ino; gets(Item); cin>>Qty; }
void Issue(int Q) { Qty +=Q; }
void Purchase(int Q) { Qty -= Q; }
void GetIno() { return Ino; }
};
void PurchaseItem (int Pino, int PQty)
{ fstream File;

165
File.open("STOCK.DAT", ios::binary|ios::in|ios::out);
Stock S;
int Success=0;
while(Success ==0 && File.read((char *) &S,sizeof(S)))
{ if(Pino == S.GetIno())
{ S.Purchase(PQty);
---------------------------- //Statement 1
---------------------------- //Statement 2
Success++;
}
}
if(Success == 1)
cout<<"Purchase Updated"<<endl;
else
cout<<"Wrong Item No"<<endl;
File.close();
}
(i) Write statement 1 to position the file pointer to the appropriate place, so that the data
updation is done for the required item.
(ii) Write statement 2 to perform the write operation so that updation is done in the binary file.
(b) Write a function in C++ to read the content of a text file “DELHI.TXT” and display all those
lines on screen, which are either starting with ‘D’ or starting with ‘M’. 2
(c) Write a function in C++ to search for the details (Phoneno and Calls) of those Phones, which
have more than 800 calls from a binary file “phone.dat”. Assuming that this binary file contains 3
records/objects of class Phone, which is defined below.
class Phone
{ char Phoneno[10]; int Calls;
public:
void Get() { gets(Phoneno); cin>>Calls; }
void Billing() { cout<<Phoneno<<"#"<<Calls<<endl; }
int Getcalls() { return Calls; }
};
5.(a) Give a suitable example of a table with sample data and show Primary and Alternate Keys in it. 2
Consider the following tables CARDEN and CUSTOMER and answer (b) and (c) part of this
question:

Table : CARDEN
Ccode CarName Make Color Capacity Charges
501 A-Star Suzuki RED 3 14
503 Indigo Tata SILVER 3 12
502 Innova Toyota WHITE 7 15
509 SX4 Suzuki SILVER 4 14
510 C Class Mercedes RED 4 35
Table: CUSTOMER
CCode Cname Ccode
1001 Hemant Sahu 501
1002 Raj Lal 509
1003 Feroza Shah 503
1004 Ketan Dhal 502 4
(b) Write SQL commands for the following statements:
(v) To display the names of all the silver colored Cars.
(vi) To display name of car, make and capacity of cars in descending order of their sitting
capacity.
(vii) To display the highest charges at which a vehicle can be hired from CARDEN. 2

166
(viii) To display the customer name and the corresponding name of the cars hired by them.
(c) Give the output of the following SQL queries:
(v) SELECT COUNT(DISTINCT Make) FROM CARDEN;
(vi) SELECT MAX(Charges), min (Charges) FROM CARDEN;
(vii) SELECT COUNT(*), Make FROM CARDEN;
(viii) SELECT CarName FROM CARDEN WHERE Capacity=4;

6.(a) Verify the following using truth table: 2


(i) X.X’ = 0 (ii) X + 1 = 1

(b) Write the equivalent Boolean expression for the following Logic Circuit: 2
U

(c) Write the SOP form of a Boolean function F, which is represented in a truth table as follows: 1

X Y Z F
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1

(d) Reduce the following Boolean Expression using K-Map: 3


F(A, B, C, D) = ∑(2, 3, 4, 5, 6, 7, 8, 10, 11)

7.(a) What out of the following, will you use to have an audio-visual chat with an expert sitting in a 1
far-away place to fix-up a technical issue?
(i) VoIP (ii) email (iii) FTP
(b) Name one server side scripting language and one client side scripting language. 1

(c) Which out of the following comes under Cyber Crime? 1


(i) Operating someone’s Internet banking account, without his knowledge.
(ii) Stealing a keyboard from someone’s computer.
(iii) Working on someone’s computer with his/her permission.

(d) Write one advantage of Bus Topology of network. Also, illustrate how 4 computers can be 1
connected with each other using star topology of network.

(e) Workalot Consultants are setting up a secured network for their office campus at Gurgaon for 4
their day-to-day office and web-based activities. They are planning to have connectivity
between 3 buildings and the head office situated in Mumbai. Answer the questions (i) to (iv)
after going through the building positions in the campus and other details, which are given
below:

Head Office
Gurgaon Campus
“MUMBAI”
Building 167
“GREEN”
CBS
E-
Seni
Building or
Building “RED” Seco
“BLUE” ndar
y
Distances between various buildings:
Certi
Building “GREEN” to building “RED” 110 m ficat
Building “GREEN” to building “BLUE” 45 m e
Building “BLUE” to building “RED” 65 m Exa
Gurgaon Campus to Head Office 1760 KM mina
tion-
Number of Computers:
2011
Building “GREEN” 32 -12
Building “RED” 150 Subj
Building “BLUE” 45 ect:
Head Office 10 Com
pute
(i) Suggest the most suitable place (i.e. building) to house the server of this organization.
Also give a reason to justify your suggested location.
r
(ii) Suggest a cable layout of connection between the buildings inside the campus. Scie
(iii) Suggest the placement of the following devices with justification: nce
a. Switch b. Repeater (083)
(iv) The organization is planning to provide a high speed link with its head office situated in
MUMBAI using a wired connection. Which of the following cables will be most suitable S
for this job? olut
a. Optical Fiber
b. Co-axial Cable ion
c. Ethernet Cable
(f) 1
Give one suitable example of each URL and Domain Name.
(g) 1
Name two Proprietary Softwares along with their application.

QN Answers
1.(a) Type casting means changing the data type of an expressioninto another data type by using (type)
operator and automatic type conversion means, the conversion process is done by compiler itself. For
example:
A= (float) b/c; // The expression’s result will converted into float type, a Type Casting.
int m=4.5; // m stores only 4, this is automatic type conversion.
(b) #include<iostream.h>, #include<string.h>
(c) #include<iostream.h>
#include<iomanip.h>
class Item
{ long IID, Qty;
public:
void Purchase ( ){ cin>>IID>>Qty ; }
void Sale()
{ cout<<setw(5)<<IId<<" Old: "<<Qty<<endl;
cout<<"New: "<< --Qty<<endl;
}
};
void main()
{ Item I;
I.Purchase();

168
I.Sale();
I.Sale();
}

(d) Output: 5 : 1 : 20
1 : 1 : 50
5 : 2 : 50
(e) Output: vR2Good
R2GoOd
2GOOd
gOOd
(f) Not Possible Output is: 9 # 6#
2.(a) There is no difference in the private visibility mode members and protected visibility mode members
inside a class, they are accessible only within the class and by class members only. But in inheritance
the protected members are inherited into derived class and accessible there, whereas the private
members are not inherited into derived class and not accessible there.
class A
{ private:
int a;
protected:
int b;
public:
void GetD() { cin>>a>>b; } // a & b are accessible in the class not by object of class.
};
class B: public A
{ int x;
protected:
int m; //protected member of (A::b)class A inherited into protected of class B
public:

void disp()
{ cout<<b; //valid here
cout<<a; //invalid and not allowed by compiler
}
};
(b) (iii) The function-1 and 4 shows function-overloading conept of polymorphism in OOPS.
(iv) The function-3 shows a destructor, used to destroy the object of the class. It is called
automatically, when the program is going to end or when the object is going to be deleted.
(c) class Restra
{ int FoodCode; char Food[20], FType[15], Sticker[15];
void GetSticker()
{ if ( strcmp(FType, "Vegetarian")==0)
strcpy(Sticker,”GREEN);
else if(strcmp(FType, "Contains Egg") ==0)
strcpy(Sticker,”YELLOW);
else //if not a veg is treat as non-veg
strcpy(Sticker,”RED”);
}
public:
void GetFood()
{ cin>>FoodCode;
gets(Food);
gets(FType);
GetSticker(); // cal the function to assign the sticker
}
void ShowFood()
{cout<<"Food Code:”<<FoodCode<<"\t"<<”Food: ”<<Food

169
<<”\nFood Type:"<<FType<<”\t”<<Sticker<<endl;
}
};
(d) (v) Hierarchical Inheritance
(vi) SHOP::Location, SHOP::Area, SHOP::Sale
(vii) Enter(), FACTORY::Show(), Register(), COMPANY::Show()
(viii) Input(), Output()

3.(a) void SWAP2BEST(int ARR[], int size)


{ int k, t;
for( int i=0 ; i< size ; )
{ if(ARR[i]%10==0)
{ t = ARR [i];
ARR [i] = ARR [i+1];
ARR [i+1] = t;
i+=2;
}
else
++i;
}
cout<<”Array content after rearrangement:”<<endl;
for(k = 0; k < size; k++)
cout << ARR[k]<<” “;
} //end of Function
(b) For the given Column Major order problem: w= 2, R= 20, Lr= Lc = 0, BA = ?
Address of T[2][9] =>7600 = BA + 2 ( (2-0) + 20( 9-0))
B.A. = 7600- 220 = 7236
Address of X[10][5] = 7236 + 2 ( (10-0) +20 ( 5-0))
= 7456 Ans

(c) void Insert(BOOK BQ[], int size, int & F, int & R) //Insertion in a Circular Queue
{BOOK b;
cout<<"\nEnter Data for Circular Array Queue: ";
gets(b.Title); cin>>b.Accno;
if(R==size-1&&F==0||F==R+1)
{cout<<"\nQueue overflow!!!";
return;
}
else if(R==-1)
F=R=0;
else if(R==size-1)
R=0;
else
R++;
BQ[R]=b;
return;
}
(d) void ALTERNATE(int ARR[][3], int n,int m)
{ for( int i=0 ; i< n ; i++)
{
for(int j=0;j<m;j++)
if(i%2==0)
{ if(j%2==0)
cout<<ARR[i][j]<<" ";
}
else
if(j%2!=0)

170
cout<<ARR[i][j]<<" ";
}
} //end of Function
(e) The given postfix expression is: True, False, NOT, AND, False, True, OR, AND
To evaluate this postfix expression, we process symbole one by one, scan from left to right and use
stack to store the result of each operation.

SNo Symbol Action Stack Evaluation


Scanned Performed
1 True Push True $T
2 False Push False $ T, F
3 NOT Calc. NOT $ T, T NOT F=T push T
4 AND Cal. - AND $T T AND T= push T
5 False Push F $ T, F
6 True Push T $ T, F, T
7 OR Cal. - OR $ T, T F OR T = push T
8 AND Cal. - AND $T T AND T= push T
9 Pop T as result
Ans: True

4.(a) Statement 1: File.seekp(-sizeof(S),ios::cur);


Statement 2: File.write((char *) &S, sizeof(S));
(b) void DisplayFile()
{ ifstream afile("DELHI.TXT");
char ch[80];
int n = 0;
cout<<" The line in the file started with ‘D’ or ‘M: "<<endl;
while(afile.getline(ch,80))
{
if(isupper(ch[0]==’D’|| ch[0]==’M’))
cout<<ch<<endl;
}
afile.close();
}
(c) void PhoneRec()
{ ifstream file;
Phone P; int ctr=0;
file.open("phone.dat”,ios::in|ios::binary);
cout<<”Phone Records having more than 800 Calls:\n”;
while(file.read((char *) &P, size(P)))
{if(P.GetCalls()>800)
{ P.Billing();
ctr++;
}
}
if(ctr!=0)
cout<<"Total Record Found:"<<ctr<<endl;
else
cout<<”No Records Found!!!\n”;
file.close();}
5.(a) A sample table “EMP” with some data:
Table: EMP
EmpId Ename Job Hiredate Salary PAN
1001 Amit singh Manager 27-Aug-2002 35000 AY31TC1
1002 C. Swati UDC 01-Sep-2002 22000 FT45CR3
171
1003 S. Raja LDC 07-Sep-2002 19500 AB67MI4
Now here the possible primary key: {EmpId}
And the alternate key: {PAN}
(b) (i) SELECT CarName FROM CARDEN WHERE Color =’Silver’;
(ii) SELECT CarName, Make, Capacity FROM CARDENORDER BY Capacity Desc;
(iii) SELECT MAX(Charges) FROM CARDEN;
(iv) SELECT CarName, Cname FROM CARDEN C, CUSTOMER CS WHERE
C.Ccode=CS.Ccode;
(c) (i) 4
(ii) Max Charge Min Charge
35 12
(iii) Suzuki 2
Tata 1
Totota 1
Mercedes 1
Note: In the question given GROUP BY MAKE is also necessary to run the query.
(iv) CarName
SX 4
C Class
6.(a) (i) X . X’ = 0
(ii) X+1=1
Proof of (i) by using the truth table:
X X’ X.X’
1 0 0
0 1 0
Hence X.X’=0, Proved.
Proof of (ii) by using the truth table:
X 1 X+1
1 1 1
0 1 1
Hence X+1=1, Proved.
(b) The equivalent Boolean Expression of the logic circuit is: Y = UV’ + U’W’

(c) The SOP form of a Boolean Function F=X’Y’Z’ + X’YZ’ + XY’Z’ + XYZ
The Karnaugh Map for the given Boolean function is:
(d) AB\CD
0 0 1 1
1 1 1 1
0 0 0 0
1 0 1 1
There are 2 quads and 1 pair possible in this combination.
The reduced equation for quad 1: A’B
The reduced equation for quad 2: B’C
The reduced equation for pair 1: AB’D’
So the final minimized expression for the F(A,B,C,D): A’B + B’C + AB’D’

7.(a) (i) VoIP


(b) The Client side Script is: VB Script. Java Script, Hypertext Preprocessor (PHP)
The Server side Script is: ASP( Active Server Pages), JSP(Java Server Pages), Perl, PHP

(c) (i) Operating some one’s Internet Banking Account without his knowledge.
(d) Advantage of Bus Topology: it is very simple and easier to install.
Let 4 computers are:
A, B, C, D D
Connection in Star Topology:

A 172
B C

(e) (i) The server should be placed at Building RED, because this building contains more number of computers as
compare to others (150). So as per the 80:20 rule for network traffic, the local traffic load in a building should be
80% of the total traffic load, hence the building RED is appropriate to house the server.
(ii) Cable Layout (1) :
Green
45 m
Red
Blue 65 m

Bus Topology: Total Cable Length = 110 Meters.


Cable Layout (2):
Green

110 m
65 m
Blue Red

Star Topology: Total Cable Length = 175 Meters.


Note: To save the cable cost layout-1 is suitable OR to maintain good network traffic use layout-2.
(iii) (1) Switch: It is used in each building to connect all computers together.
(2) Repeater: If layout-1 is used then it is not required because length is less than 100m.
If layout-2 is used it should be placed between Green and Red buildings, because the
length is more than 100m.
(iv) Optical Fiber is most suitable to connect the head office with the organization with a high speed.
Example of URL is: http://www.apple.com/index.html
Example of Domain is: .com
(f) Proprietary Softwares:
i) Microsoft Windows: made by Microsoft as Operating system for PC. It is linseced to a
pertiicular user.
(g) ii) Adobe Photoshop: made by Adobe as application software for photo editing and processing.

CBSE- All India Senior Secondary Certificate Examination-2010-11 (Out Side Delhi)
Subject : Computer Science ( 083)
Time Allowed: 3 Hours Max. Marks: 70

1. (a) What is the difference between Type Casting and Automatic Type conversion? Also, give a 2
suitable C++ code to illustrate both.
(b) Write the names of the header files, which is/are essentially required to run/execute the 1
following C++ code:
void main()
{ char CH, Text [ ] = “+ve Attitude”;
for ( int I =0; Text [I] != ‘\0’ ; I++)
if ( Text [I] = = ‘ ’)
cout<<endl;
else
{ CH = toupper(Text [I] );
cout<<CH;
}
}
(c) Rewrite the following program after removing the syntactical errors (if any). Underline each 2
correction.
include <iostream.h>
typedef char [80] String;
void main()

173
{
String S = “Peace”;
int L = strlen(S);
cout<<S<< ‘ has ‘<< L <<’Characters ‘ <<endl;
}
(d) Find the output of the following program: 3
#include<iostream.h>
void SwitchOver ( int A [ ], int N, int Split )
{
for (int K = 0; K<N ; K ++)
if( K <Split )
A [K ] + = K;
else
A [ K ] * = K;
}
void Display( int A[ ], int N)
{
for ( int K =0 ; K < N ; K++)
(K%2 == 0) ? cout<<A[K] << “ % “ : cout<< A[K]<<endl;
}
void main()
{
int H[ ] = { 30, 40, 50, 20, 10, 5 };
SwitchOver (H, 6, 3 );
Display (H, 6 );
}
(e) Find the output of the following program: 2
#include<iostream.h>
void main()
{ int *Queen, Moves [ ] = { 11, 22, 33, 44 };
Queen = Moves;
Moves [2] + = 22;
cout<<” Queen @ “<< *Queen << endl;
*Queen - = 11;
Queen + = 2;
cout<< “Now @ “ << *Queen <<endl;
Queen ++;
cout<< “ Finally @ “ <<*Queen <<endl;
cout<< “ New Origin @ “<< Moves [0] << endl;
}

(f) Go through the C++ code shown below, and find out the possible output or outputs from the 2
suggested Output Options (i) to (iv). Also, write the minimum and maximum values, which can
be assigned to the variable MyNum.
#include<iostream.h>
#include<stdlib.h>
void main()
{ randomize();
int MyNum, Max = 5;
MyNum = 20 + random(Max);
for( int N = MyNum ; N < =25; N++)
cout<<N <<” *” ;
}
(i) 20*21*22*23*24*25
(ii) 22*23*24*25*
(iii) 23*24*
(iv) 21*22*23*24*25

174
2.(a) Differentiate between Constructor and Destructor function with respect to Object Oriented 2
Programming.
(b) Write the output of the following C++ code. Also, write the name of the feature of the object 2
Oriented Programming used in the following program jointly illustrated by the functions [I] to
[IV]:
#include<iostream.h>
void Line ( ) // Function [I]
{ for (int L = 1 ; L <= 80 ; L++)
cout<< “ – “;
cout<< endl;
}
void Line ( int N) // Function [II]
{ for ( int L =1 ; L < = N ; L ++)
cout<< “ * “;
cout<<endl;
}
void Line ( char C, int N) // Function [III]
{ for ( int L = 1; L <= N ; L ++)
cout<< C ;
cout<< endl;
}
void Line ( int M, int N) // Function [IV]
{ for ( int L = 1; L <= N ; L ++)
cout<<M * L;
cout<< endl;
}
void main()
{ int A= 9 , B= 4, C = 3;
char K = ‘#’ ;
Line ( K, B);
Line ( A, C );
}

(c) Define a class Applicant in C++, with following description:


Private Members:
• A data member ANo ( Admission Number) of type long
• A data member Name of type string
• A data member Agg ( Aggregate Marks) of type float
• A data member Grade of type char
• A member function GradeMe() to find the Grade as per the Aggregate Marks obtained by
a student. Equivalent Aggregate Marks range and the respective Grades are shown as
follows:
Aggregate Marks Grade
>=80 A
Less than 80 and >=65 B
Less than 65 and >=50 C
Less than 50 D
Public Members:
• A function ENTER() to allow user to enter values for ANo, Name, Agg and call function
GradeMe() to find the Grade.
• A function RESULT() to allow user to view the content of all the data members.

(d) Answer the questions (i) to (iv) based on the following:


class Student
{
int Rollno;
175
char SName [20];
float Marks;
protected:
void Result();
public:
Student();
void Enroll ();
void Display();
};
class Teacher
{
long TCode;
char TName[20];
protected:
float Salary;
public:
Teacher();
void Enter();
void Show();
};
class Course : public Student, private Teacher
{
long CCode [10] ; char CourseName [50];
char StartDate [8], EndDate [8];
public:
Course ();
void Commence ();
void CDetail ();
};
(i) Write the names of member functions, which are accessible from objects of class Course.
(ii) Write the names of all the data members, which is/are accessible from member function
Commence() of class Course.
(iii) Write names of all the members, which are accessible from the objects of class Teacher.
(iv) Which type of Inheritance is illustrated in the above C++ code?
3.(a) Write a Get2From1() function in C++ to transfer the content from one array ALL[] to two 3
different arrays Odd[] and Even []. The Odd[] array should contain the values from odd
positions (1,3,5…..) of ALL[] and Even [] array should contain the values from even positions
(0, 2, 4……) of ALL[].
Example:
If the ALL[] array contains: 12, 34, 56, 67, 89, 90
The Odd [] array should contain: 34, 67, 90
And the Even [] array should contain: 12, 56, 89

(b) An array G[50][20] is stored in the memory along the row with each of its elements occupying 8 3
bytes. Find out the location of G [10] [15], if G[0][0] is stored at 4200.

(c) Write a function in C++ to perform Delete operation on a dynamically allocated Queue 4
containing Members details as given in the following definition of NODE:
struct NODE
{ long Mno; //Member Number
char Mname[20]; //Member name
NODE *Link;
};

(d) Write a DSUM() function in C++ to find sum of Diagonal elements from a NxN Matrix. 2
(Assuming that the N is a odd number)
(e) Evaluate the following postfix notation of expression: 2

176
True, False, NOT, AND, True, True, AND, OR

4.(a) Observe the program segment given below carefully and fill the blanks marked as Statement 1 1
and Statement 2 using seekg(), seekp(), tellp() and tellg() functions for performing the required
task.
#include<fstream.h>
class ITEM
{ int Ino; char Iname[20]; float Price;
public:
.... .
void ModifyPrice (); // The function is to modify price of a particular ITEM
};
void ITEM ::ModifyPrice()
{fstream File;
File.open("ITEM.DAT", ios::binary | ios::in | ios::out);
int CIno;
cout<<"Item No to modify price: ";
cin>>CIno;
while( File.read((char *) this, sizeof(ITEM)))
{if(CIno = = Ino)
{ cout<<"Present Price : "<<Price<<endl;
cout<<"Changed Price : "; cin>>Price;
int FilePos = _________________; // Statement 1
_____________________________________; // Statement 2
File.write ((char *) this, sizeof(ITEM)); // Re-writing therecord
}
}
File.close();
}
(b) Write a function in C++ to count the number of “He” or “She” words present in a text file 2
“Story.txt”.
If the file “ Story.txt” content is as follows:
He is playing in the ground. She is playing with her dolls.
The output of the function should be:
Count of He/She in file: 2
(c) Write a function in C++ to search for a camera from a binary file “CAMERA.DAT” containing 3
the objects of class CAMERA (as defined below). The user should enter the Model No and the
function should search and display the details of the camera.
class CAMERA
{long ModelNo;
float MegaPixel;
int Zoom;
char Details[120];
public:
void Enter() { cin>>ModelNo>>MegaPixel>>Zoom;
gets(Details); }
void Display() {cout<<ModelNo<<MegaPixel<<Zoom<<Details<<endl;
}
long GetModelNo() { return ModelNo; }
};
5.(a) What do you understand by Selection & Projection operations in relational algebra? 2
Consider the following tables EMPLOYEE and SALGRADE and answer (b) and (c) parts of
this question:
Table: EMPLOYEE
ECODE NAME DESIG SGRADE DOJ DOB
101 Abdul Ahmed EXECUTIVE SO3 23-Mar-2003 13-Jan-1980
102 Ravi Chander HEAD-IT SO2 12-Feb-2010 22-Jul-1987
177
103 John Ken RECEPTIONIST SO3 24-Jun-2009 24-Feb-1983
105 Nazar Ameen GM SO2 11-Aug-2006 03-Mar-1984
108 Priyam Sen CEO SO1 29-Dec-2004 19-Jan-1982
Table: SALGRADE
SGRADE SALARY HRA
SO1 56000 18000
SO2 32000 12000
SO3 24000 8000
Write SQL commands for the following statements:
(b)
(i) To display the details of all employees in descending order of DOJ. 4
(ii) To display NAME and DESIG of those employees whose SALGRADE is either SO2 or
SO3.
(iii) To display the content of all the employees table, whose DOJ is in between ‘09-Feb-2006’
and ‘08-Aug-2009’.
(iv) To add a new row with the following:
109, ‘Harish Roy’, ‘HEAD-IT’, ‘SO2’, ‘09-Sep-2007’, ‘21-Apr-1983’
Give the output of the following SQL queries: 2
(c)
(i) SELECT COUNT(SGRADE), SGRADE FROM EMPLOYEE GROUP BY SGRADE;
(ii) SELECT MIN(DOB), MAX(DOJ) FROM EMPLOYEE;
(iii) SELECT NAME, SALARY FROM EMPLOYEE E, SALGRADE S
WHERE E.SGRADE = S.SGRADE AND E.ECODE <103;
(iv) SELECT SGRADE, SALARY+HRA FROM SALGRADE WHERE SGRADE = ‘SO2’;
6.(a) Verify the following using Truth Table: 2
X+Y.Z=(X+Y).(X+Z)
(b) Write the equivalent Boolean Expression for the following Logic Circuit: 2
P

(c) Write the SOP form of a Boolean Function F, which is represented in a truth table as follows:
U V W F 1
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
(d) Reduce the following Boolean Expression using K-Map:
F( A, B, C, D ) = ∑ ( 0, 1, 2, 4, 5, 6, 8, 10 )
3
7.(a) In networking, what is WAN? How is it different from LAN? 1
(b) Differentiate between XML and HTML. 1
(c) What is WEB2.0? 1
(d) Out of the following, identify client side script(s) and server side script(s). 1
(i) javascript (ii) ASP (iii) vbscript (iv) JSP
(e) GreatStudiesUniversity is setting up its Academic schools at Sunder Nagar and planning to set 4
up a network. The university has 3 academic schools and one administration center as shown in
the diagram below:

Business Technology
School School
178

Law School
Admin
Center

Center to center Distances between various buildings is as follows:


Law school to Business school 65 m
Law school to Technology school 90m
Law school to AdminCenter 115m
Business school to Technology school 40m
Business school to AdminCenter 45m
Technology school to AdminCenter 25 m
Number of Computersin each of the School/Center is follows:

Law school 25
Technology school 50
AdminCenter 125
Business school 35

i. Suggest the most suitable place (i.e. Schools/Center) to install the server of thisuniversity with a suitable reason.
ii. Suggest an ideal layout for connecting these schools/Center for a wired connectivity.
iii. Which device will you suggest to be placed/installed in each of these schools/center to efficiently connect all the
computers within these school/center?
iv. The university is planning to connect its admission office in the closest big city, which is more than 350 km from
the university. Which type of network out of LAN, MAN or WAN will be formed? Justify your answer .

(f) Compare Open Source Software and Proprietary Software. 1


(g) What are cookies? 1

CBSE- Senior Secondary Certificate Examination-2010-11


Subject: Computer Science (083)
Solution
1.(a) Type casting means changing the data type of an expressioninto another data type by using (type)
operator and automatic type conversion means, the conversion process is done by compiler itself. For
example:
A= (float) b/c; // The expression’s result will converted into float type, a Type Casting.
int m=4.5; // m stores only 4, this is automatic type conversion.

(b) (i) iostream.h> (ii) ctype.h


(c) #include<iostream.h>
#include<string.h>
typedef char String[80];
void main()
{
char S[ ]="Peace";
int L = strlen(S);
cout<<S <<"has "<< L << " characters "<<endl;
}
(d)
OutPut: 30 % 41
52 % 60
(e) 40 % 25
179
OutPut: Queen @ 11
Now @ 55
Finally @ 44
(f) New Origin @ 0
The possible OutPut is : (ii) 22*23*24*25*
The minimum value of MyNum is:20
The maximum value of MyNum is: 24

2.(a) A Constructor is required to initialise the data members for an object and there is no other ways to
initialise. A Destructor is used to de-initialise/destroy the object of class from memory.
A Constructor can be overloaded but a destructor can not.
A Constructor invoked automatically, when objects are created. A Destructor invoked automatically,
when objects will go out of scope or program ended.

(b) OutPut is: ####


91827
The functions [I] to [IV] shows Function Overloading feature (Polymorphism).
(c) class Applicant
{ long Ano;
char Name[25];
float Agg;
char Grade;
void GradeMe()
{ if(Agg>=80)
Grade='A';
else if (Agg >=65)
Grade = 'B';
else if ( Agg >=50 )
Grade = 'C';
else
Grade = 'D';
}

public:
void ENTER()
{cin>>Ano;
gets(Name);
cin>>Agg;
GradeMe();
}
void RESULT()
{ cout<<Ano<<"\t"<<Name<<"\t"<<Agg<<"\t"<<Grade;
}
};
(d) (i) Commence(), CDetail(), Enroll(), Display()
(ii) CCode, CourseName, StartDate, EndDate, Salary
(iii) Enter(), Show()
(iv) Multiple

3.(a) void Get2From( int All[], int size, int Even[], int s1, int Odd[], int s2)
{ int i,j=0, k=0;
for( i = 0 ; i < size ; i++ )
{if(All[i]%2 == 0)
Even[j++] = All[i];
else
Odd[k++] = All[i];
}

180
s1=j-1;
s2=k-1;
cout<<"Display All\n";
for(i = 0 ; i < size ; i++ )
cout<< All[i]<<"\t";
cout<< "\n";
cout<<"Display Even\n";
for(i = 0 ; i <= s1 ; i++ )
cout<< Even[i]<<"\t";
cout<< "\n";
cout<<"Display Odd\n";
for(i = 0 ; i < =s2 ; i++ )
cout<< Odd[i]<<"\t";
cout<< "\n";
}
(b) For the given problem: W= 8, R= 50, C = 20, Lr= 0, Lc = 0, BA ( G[0][0]) = 4200
In Row Major order: Address of G[10][15] = 4200 + 8 ( 20 (10 - 0) + ( 15 - 0))
= 5920 Ans.
(c) void Delete(NODE *F, NODE *R)
{ NODE *ptr;
if(F == NULL)
cout<<”Empty Queue!!!”;
else
{ ptr = F;
if(F == R)
F = R = NULL;
else
F = F ->LINK;
cout<< “Node Deleted: ”<<ptr->Mno<< “ “ <<ptr ->Mname;
delete ptr;
}
}

(d) void Diagonal(int a[3][3])


{ int j, sum = 0;
cout<<”Main Diagonal: ”;
for(j = 0; j<3; j++)
sum += a[j][j];
cout<<”\n Sum of Main Diagonal elements is: "<<sum;
}
(e) The questionTRUE, FALSE, NOT, AND, TRUE, TRUE , AND,OR
To evaluate the given postfix expression, we scan it from left to right one by one:
SNo Symbol Action Stack Evaluation
Scanned Performed ( $ means Stack Top)
1 TRUE Push TRUE $ TRUE
2 FALSE Push FALSE $ FALSE TRUE
3 NOT Calc. NOT $ TRUE TRUE POP FALSE, ! F = T, PUSH TRUE
4 AND Calc. AND $ TRUE TRUE AND TRUE=TRUE, PUSH TRUE
5 TRUE Push TRUE $ TRUE TRUE
6 TRUE Push TRUE $ TRUE TRUE TRUE
7 AND Calc. AND $ TRUE TRUE TRUE AND TRUE = TRUE, PUSH
TRUE
8 OR Calc. OR $ TRUE TRUE OR TRUE = TRUE, PUSH TRUE
Ans: TRUE
4.(a) Statement 1 : FilePos= File.tellp();
Statement 2: File.seekp(FilePos-sizeof(ITEM), ios::cur);
181
(b) void CountWord()
{ fstream afile("Story.txt", ios::in);
char ch[50];
int count=0;
while(!afile.eof())
{ afile>>ch;
if(strcmpi(ch, "He")==0 || strcmpi(ch, "She")==0)
count++;
}
afile.close();
cout<<"Count of He/She in File: = "<<count;
}

(c) void SearchCamera()


{ ifstream fin;
CAMERA S;
long Mno; int F =0;
cout<<”Enter the Model Number of Camera\n”;
cin>>Mno;
fin.open("CAMERA.DAT", ios::in);
while(fin.read((char *) &S, sizeof(CAMERA)))
{ if((S.GetModelNo() = = Mno)
{ cout<<”The Details of Camera are:\n”;
S.Display();
F=1;
break; }
}
if ( F= = 0) cout<<” Camera not Found !!!\n”;
fin.close();
}
5.(a) Selection is an operation in Relational Algebra, which is used to find a set of rows, which satisfy
a particular predicate (condition). It is indicated by σsign.
Projection is an operation in Relational Algebra, which is used to display a set of columns.
It is indicated by a ∏ sign.

(b) Select * From EMPLOYEE Order By DOJ;


(i) Select NAME, DESIG From EMPLOYEE Where SGRADE = ‘SO2’ OR SGRADE = ‘SO3’;
(ii) Select * From EMPLOYEE Where DOJ Between ‘09-Feb-2006’ And ‘08-Aug-2009’;
(iii) Insert Into EMPLOYEE Values(109, ‘Harish Roy’, ‘HEAD-IT’, ‘09-SEP-2007’, ‘21-APR-1983’);
(iv)
(c) Count(SGRADE) SGRADE
(i) 2 SO3
2 SO2
1 SO1

MIN (DOB) = 22-JUL-1987, MAX(DOJ) = 23-MAR-2003


(ii) Abdul Ahmed 24000
(iii) Ravi Chander 32000
SO2 44000
(iv)
6.(a) Verify by Truth Table:
X Y Z XZ X+Y X+Z YZ X+(Y.Z) (X+Y) (X+Z)
0 0 0 0 0 0 0 0 0
0 0 1 0 0 1 0 0 0

182
0 1 0 0 1 0 0 0 0
0 1 1 0 1 1 1 1 1
1 0 0 0 1 1 0 1 1
1 0 1 1 1 1 0 1 1
1 1 0 0 1 1 0 1 1
1 1 1 1 1 1 1 1 1

Hence the last two columns show they are equal, so it is verified.
(b)
F = PQ’ + QR’
(c)
F(U, V, W) = U’V’W’ + U’VW + UVW’ + UVW
(d)
F(A, B, C, D) = ∑ (0, 1, 2, 4, 5, 6, 8, 10)
The Karnaugh Map for the given Boolean function is:
AB\CD 00 01 11 10

00 1 1 0 1
01 1 1 0 1
11 0 0 0 0
10
1 0 0 1
This gives Three Quads:
The expression for Quad 1 : B’D’
The expression for Quad 2 : A’D’
The expression for Quad 3 : A’C’
So the final minimized expression for the F(A, B, C, D) = B’D’ + A’D’ + A’C’
7.(a) WAN is a Wide Area Network, which does not have a defined range. LAN is a Local Area Network,
which has a very short defined range (upto 2 Km.).

LAN WAN
1. Small range 6. Unlimited range
2. High speed 7. Medium speed
3. Very low data error rate 8. Data error rate high
4. Managed and controlled by 9. By different groups
one person or unit. 10. No of computer are
5. Less no of computers unlimited

(b) HTML: Hypertext Markup Language is a document layoutand hyperlink specification language, which
is used to design the layout of the web pages. It includes a set of commands to control the presentation
of information on a web page, called Tags.

XML: Extensible Mark up Language for documents containing structured information. It defines a
standard way to add mark up to documents. It provides the facility of using inbuilt tags and user defined
tags and the structural relationships to create web documents.
(c) The term Web 2.0 is associated with web applications that facilitate participatory information sharing,
interoperability, user-centered design,and collaboration on the World Wide Web. A Web 2.0 site allows
users to interact and collaborate with each other in a social media dialogue as creators (prosumers) of
user-generated content in a virtual community, in contrast to websites where users (consumers) are
limited to the passive viewing of content that was created for them. Examples of Web 2.0 include social
networking sites, blogs, wikis, video sharing sites etc.
(d) Client side scripts: JavaScript, VB Script
Server side scripts: ASP, JSP
(e)
(i) The Server should be places in the Admin Center, because this Center contains number of computer are

183
very large (125), as we compare with others. As per 80:20 rule of the LAN design the server should be
placed in a block/building where the 80 % of the network traffic should be local.

(ii) (a) Layout 1: Star Topology used.


Total Cable used = 185 mtrs

BusinessSc Technology
hool School

45

25 LawSchool

115 AdminCent
er

(iii) Switch/Hub, used in each building to connect all the computers.


(iv) WAN, because the distance between the university and the big city is more than 350 KM. LAN (upto 2
Km.) and MAN (upto 25 Km.) are restricted by a short range.

(f) Open Source Software is the software, which does not need much restrictions or conditions. That is,
this software is for the users including source code and it can be modified without any prior permission
and also it can be freely redistributed to others.
Proprietary (Enterprise) software is specifically designed for an enterprise or organization, which is not
available freely. It should be legally purchased by the organization and it can be customize in a
restricted way and it should not be redistributed to any other.

(g) Cookies: are messages that a web server transmits to a web browser so that the web server can keep
track of the user’s activities on a specific website. Cookies are not used maliciously on computer
systems, they can not spread like virus and they are not relevant to user’s privacy and anonymity on the
internet.
CBSE- All India Senior Secondary Certificate Examination-2009-10 (Out Side Delhi)
Subject : Computer Science ( 083)
Time Allowed: 3 Hours Max. Marks: 70

1. (a) What is the difference between call by value and call by reference? Also, give a suitable C++ 2
code to illustrate both.
(b) Write C++ header file(s) will be needed to be included to run/execute for the following code: 1
void main()
{ int Rno=24; char Name [ ] = “ Amen Singhania”;
cout<<setw(10)<<Rno<<setw(20)<<Name<<endl;
}
(c) Rewrite the following C++ program after removing the syntax error(s) (if any). Underline each 2
correction.
include <iostream.h>
class FLIGHT
{ long FlightCode;
char Description[25];
public
void AddInfo()
{ cin>>FlightCode; gets(Description);
}
void ShowInfo()
{ cout<<FlightCode<< “ : ”<<Description<<endl;
}
};
void main()
184
{ FLIGHT F;
AddInfo.F(); ShowInfo . F();
}
(d) Find the out put of the following program: 3
#include<iostream.h>
struct THREE_D
{ int X, Y, Z; };
void MoveIn (THREE_D & T , int Step = 1)
{ T.X += Step;
T.Y −= Step;
T.Z + = Step;
}
void MoveOut (THREE_D &T, int Step=1)
{ T.X −= Step;
T.Y += Step;
T.Z −= Step;
}
void main()
{ THREE_D T1 = {10, 20, 5}, T2 = {30, 10, 40};
MoveIn (T1);
MoveOut (T2, 5);
cout<<T1.X<<" , "<<T1.Y<<" , "<<T1.Z<<endl;
cout<<T2.X<<" , "<<T2.Y<<" , "<<T2.Z<<endl;
MoveIn(T2, 10);
cout<<T2.X<<" , "<<T2.Y<<" , "<<T2.Z<<endl;
}
(e) Find the output of the following program: 2
#include<iostream.h>
#include<ctype.h>
void MyCode (char Msg [ ], char CH)
{
for(int Cnt = 0; Msg[Cnt] != '\0' ; Cnt++)
{
if (Msg[Cnt] >= 'B' && Msg[Cnt] <= 'G' )
Msg[Cnt] = tolower (Msg[Cnt] );
else if (Msg[Cnt] == 'A' || Msg [Cnt] =='a')
Msg[Cnt] = CH;
else if (Cnt %2 ==0)
Msg[Cnt] = toupper (Msg[Cnt] );
else
Msg[Cnt] = Msg[Cnt-1];
}
}
void main()
{char MyText[] = "ApEACeDriVE";
MyCode (MyText, '@');
cout<<"NEW TEXT: "<< MyText <<endl;
}
(f) The following code is from a game, which generates a set of 4 random numbers. Praful is 2
playing this game, help him to identify the correct option(s) out of the four choices given below
as the possible set of such numbers generated from the program code so that he wins the game.
Justify your answer.
#include <iostream.h>
#include <stdlib.h>
const int LOW = 25;
void main()
{

185
randomize();
int POINT = 5, Number;
for(int I=1; I<=4; I++)
{
Number = LOW + random(POINT);
cout<<Number<<” : “;
POINT--;
}
}
(i) 29:26:25:28:
(ii) 24:28:25:26:
(iii) 29:26:24:28:
(iv) 29:26:25:26:

2.(a) What do you understand by Data Encapsulation and Data Hiding? Also give an example in C++ 2
to illustrate both.
(b) Answer the questions (i) and (ii) after going through the following class: 2
class Exam
{ int Rno, MaxMarks, MinMarks, Marks;
public:
Exam() // Module 1
{ Rno = 101; MaxMarks = 100; MinMarks = 40; Marks = 75;
}
Exam(int Prno, int Pmarks) // Module 2
{ Rno = Prno; MaxMarks = 100; MinMarks = 40; Marks = Pmarks;
}
~Exam() //Module 3
{ cout<<”Exam Over”<<endl;
}
void Show() //Module 4
{ cout<<Rno<<" : "<<MaxMarks<<" : ”<<MinMarks<<endl;
cout<<"[Marks Got]"<<Marks<<endl;
}
};
(i) As per Object Oriented Programming, which concept is illustrated by Module 1 and
Module 2 together?
(ii) What is Module 3 referred as? When do you think, Module 3 will be invoked/called?
(c) Define a class STOCK in c++ with the following descriptions: 4
Private Members:
• ICode of type integer (Item Code)
• Item of type String (ItemName)
• Price of Type float (Price of each item)
• Qty of type integer (Quantity in Stock)
• Discount of type float (Discount percentage on the item)
• A member function FindDisc() to calculate discount as per the following rule:
If Qty<=50 Discount = 0
If 50 < Qty <= 100 Discount = 5
If Qty > 100 Discount = 10
Public Members:
• A function Buy () to allow user to enter values for Icode, Name, Price, Qty and call
function FindDisc () to calculate discount.
• A function ShowAll () to allow user to view the content of all the data members.
(d) Answer the questions (i) to (iv) based on the following code:
4
class Director
{ long DID; // Director identification number
char Name[20];
protected:
186
char Description[40];
void Allocate ();
public:
Director ( );
void Assign ( );
void Show ( );
};
class Factory : public Director
{ int FID; // Factory ID
char Address [20];
protected:
int NOE; // No. of employees
public:
Factory ();
void Input ( );
void Output ( );
};
class ShowRoom : private Factory
{ int SID; // Show Room ID
char City[20];
public:
ShowRoom();
void Enter ();
void Display();
};
(i) Which type of inheritance out of the following is illustrated in the above C++ code?
(a) Single Level Inheritance
(b) Multi Level Inheritance
(c) Multiple Inheritance
(ii) Write the names of data members, which are accessible by the objects of class ShowRoom.
(iii) Write the names of all member functions, which are accessible by the objects of class ShowRoom.
(iv) Write the names of all members, which are accessible from member functions of class Factory.
3.(a) Write a function REASSIGN () in C++, which accepts an array of integers and its size as 3
parameters and divide all those array elements by 5 which are divisible by 5 and multiply other
array elements by 2.
Sample Input Data of the Array:
A[0] A[1] A[2] A[3] A[4]
20 12 15 60 32
Content of the array after calling REASSIGN () function
A[0] A[1] A[2] A[3] A[4]
4 24 3 12 64

(b) An array T[90][100] is stored in the memory along the column with each element occupying 4 3
bytes. Find out the address of the location T[10][40], if the base address of the array is 7200.

(c) Write a complete program in C++ to implement dynamically allocated Queue containing names 4
of cities.

(d) Write a function int ALTERSUM ( int B[] [5], int N, int M ) in C++ to find and return the sum 2
of elements from all alternate elements of a two dimensional array starting from B[0][0].
If the following is the content of the array:

B[0][0] B[0][1] B[0][2]


4 5 1
B[1][0] B[1][1] B[1][2]
2 8 7

187
B[2][0] B[2][1] B[2][2]
9 6 3
The function should add elements B[0][0], B[0][2], B[1][1], B[2][0] and B[2][2].

(e) Evaluate the following postfix notations of expression (Show status of stack after execution of 2
each operation) :
True, False, NOT, OR, False, True, OR, AND
4.(a) Observe the program segment given below carefully and fill in the blanks marked as Statement 1
1 and Statement 2 using tellg() and seekp() functions for performing the required task.
#include<fstream.h>
class Customer
{ long Cno; char Name[20], Mobile[12];
public:
void Enter(); // Function to allow user to enter the Cno, Name, Mobile
void Modify(); // Function to allow user to enter (modify) Mobile number
void GetCno() { return Cno; } // Function to return the value of Cno
};
void ChangeMobile()
{ Customer C;
fstream F;
F.open("CONTACT.DAT", ios::binary | ios::in | ios::out);
long Cnoc; // Customer no. whose mobile no. needs to be changed
cin>>Cnoc;
while(F.read((char *) &C, sizeof(C)))
{ if (Cnoc = = C.Getno())
{ C.Modify();
int Pos = ______________// Statement 1- To find the current position of
//file pointer
______________________// Statement 2- To move the file pointer to
//write the modified record back onto the file
// for the desired Cnoc
F.write((char *) &C, sizeof(C));
}
}
F.close();
}
(b) Write a function in C++ to count the words “to and “the” present in a text file "POEM.TXT". 2
(Note: the Words “ to” and “the” are complete words)
(c) Write a function in C++ to search and display details of all trains, whose destination is “Delhi” 3
from a binary file “TRAIN.DAT”. Assuming the binary file is containing the objects of the
following class.
class TRAIN
{ int Tno; // Train Number
char From[20]; // Train Starting Point
char To[20]; // Train Ending Point (Destination)
public:
char * GetFrom() { return From; }
char * GetTo() { return To; }
void Input() { cin>>Tno; gets(From); gets(To); }
void Show() { cout<<Tno<<” : “<< From <<” : “<<To<<endl; }
};
5.(a) What do you understand by Primary Key? Give a suitable example of Primary Key from a table 2
containing some meaningful data.
(b) Consider the following tables STOCK and DEALERS and answer (b1) and (b2) parts of this 6
question :
Table: STOCK
ItemNo Item Dcode Qty UnitPrice StockDate
188
5005 Ball Pen 0.5 102 100 16 31-Mar-10
5003 Ball Pen 0.25 102 150 20 01-Jan-10
5002 Gel Pen Premium 101 125 14 14-Feb-10
5006 Gel Pen Classic 101 200 22 01-Jan-09
5001 Eraser Small 102 210 5 19-Mar-09
5004 Eraser Big 102 60 10 12-Dec-09
5009 Sharpener Classic 103 160 8 23-Jan-09

Table: DEALERS
Dcode Dname
101 Reliable Stationers
103 Classic Plastics
102 Clear Deals

(b1) Write SQL commands for the following statements:


To Display the Details of all Items in the Stock Table in ascending order of StockDate. 4
(i)
(ii) To Display ItemNo and Item Name of those Items from Stock Table whose Unit Price is more
than Rupees 10.
(iii) To Display the details of those items whose dealer code (Dcode) is 102 or Quantity in stock
(Qty) is more than 100 from Stock Table.
(iv) To display Maximum Unit Price of items for each dealer individually as per Dcode from the
table Stock.
(b2) Give the out put of the following SQL queries:
SELECTCOUNT(DISTINCT Dcode) FROM Stock; 2
(i)
(ii) SELECT Qty*UnitPrice FROM Stock WHERE ItemNo = 5006;
(iii) SELECT Item, DName FROM Stock S, Dealers D WHERE S.Dcode = D.Dcode AND
ItemNo = 5004;
(iv) SELECT MIN (StockDate) FROM Stock;

6.(a) Verify the following algebraically: 2


X’.Y + X.Y’ = (X’ + Y’) . (X + Y)
(b) Write the equivalent Boolean Expression for the following Logic Circuit: 2

(c) Write the SOP form of a Boolean Function G, which is represented in a truth table as follows: 1

P Q R G
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1

(d) Reduce the following Boolean Expression using K-Map: 3


F(A,B,C,D) = ∑(3,4,5, 6, 7, 13, 15)
189
7.(a) What was the role of ARPANET in the Computer Network? 1

(b) Which of the following is not a unit for data transfer rate? 1
(i) mbps (ii) kbps (iii) sbps (iv) gbps

(c) What is the difference between Virus and Worms in the computers? 1

(d) What term do we use for a software/hardware device, which is used to block unauthorized 1
access while permitting authorized communications? This term is also used for a device or set
of devices configured to permit, deny, encrypt, decrypt or proxy all (in or out) computer traffic
between different security domains based upon a set of rules and other criteria.

(e) “Vidya fo All” is an educational NGO. It is setting up its new campus at Jaipur for its web- 4
based activities. The campus has four building as shown in the diagram below:

MainBuil Resource
ding Building

Training Accounts
Building Building

Center to center distances between these buildings is as follows:

From To Distance
MainBuilding ResourceBuilding 120 mtrs
MainBuilding TrainingBuilding 40mtrs
MainBuilding AccountsBuilding 135mtrs
ResourceBuilding TrainingBuilding 125mtrs
ResourceBuilding AccountsBuilding 45mtrs
TrainingBuilding AccountsBuilding 110 mtrs

Expected number of computers in each Building is as follows:

MainBuilding 15
ResourceBuilding 25
TrainingBuilding 250
AccountsBuilding 10
(e1) Suggest a cable layout of connection between the buildings.
(e2) Suggest the most suitable place (i.e. building) to house the server for this NGO. Also, provide a
suitable reason for your suggestion.
(e3) Suggest the placement of the following devices with justification:
(i) Repeater
(ii) Hub/Switch
(e4)
The NGO is planning to connect its International office situated in Delhi. Which out of the
following wired communication links, will you suggest for very high speed connectivity?

190
(i) Telephone Analog Line (ii) Optical Fiber (iii)Ethernet Cable
(f)
Write the full forms of the following: 1
(f1) FTP (f2) FSF
(g)
Name any two common Web browsers. 1

191
CBSE- All India Senior Secondary Certificate Examination-2009-10
Subject: Computer Science (083)
Solution
QN Answers
1.(a) When a function is called with arguments and only the values of actual arguments are being passed
to formal arguments and there is no link between actual and formal arguments, is called, call by
value method. In call by reference method only the memory reference of actual arguments is being
passed to formal arguments. The actual and formal arguments are linked together in this method,
means if any changes made in formal argument, will also make the changes in actual argument.
For e.g.
void f1(int x) // function call by value
{ x=40;
}
void f2(int & y) // function call by reference
{ y = 50;
}
void main()
{ int a=10;
f1(a); // Call to f1(), and no change in a parameter
f2(a); // Call to f2(), and will change in a parameter value by 50
…….}
(b) (1) iostream.h (2) iomanip.h
(c) #include<iostream.h>
#include<stdio.h>
class FLIGHT
{ long FlightCode;
char Description[25];
public:
void AddInfo()
{ cin>>FlightCode; gets(Description);
}
void ShowInfo()
{ cout<<FlightCode<< “ : ”<<Description<<endl;
}
};
void main()
{ FLIGHT F;
F.AddInfo (); F.ShowInfo ();
}
(d) 11, 19, 6
25, 15, 35
35, 5, 45
(e) @@e@ccddIIe
(f) (iv) 29:26:25:26:

2.(a) Wrapping the data and their associated function together in a closed boundary/unit, which can not
move freely outside the unit, is called Data Encapsulation. The data define in the class are hidden
from the outside of class is called data hiding and they are accessible only by the functions of that
class. Class is a best example of encapsulation and data hiding, because it hide the internal data
from out side the class and it bind the data and its related function together into a closed boundary.
For e.g.
class Temp
{ int a; // private data member, hidden from outside the class
public:
void getdata() // member function
{ cin>>a;

192
}
…….
}; // class encapsulate the data and the functions together
(b) (i) The Module 1 and Module 2 are showing function overloading (Polymorphism) concept of
oops.
(ii) The Module 3 referred as Destructor. It will be invoked when the object of the class goes out
of scope or when the program ends.
(c) class STOCK
{
int ICode;
char Item[25];
float Price;
int Qty;
float Disc;
void FindDisc()
{ if (Qty>100)
Disc = 10;
else if(Qty>50)
Disc = 5;
else
Disc= 0;
}
public:
void Buy ()
{
cin>>Icode;
gets(Item);
cin>>Price>>Qty;
FindDisc();
}
void ShowAll ()
{ cout<<Icode<<”\t”<<Item<<”\t”<<Price<<”\t”<<Qty<<”\t”<<Disc<<endl;
}
};
(d) (i) (c) Multi Level Inheritance
(ii) Nil, because there is no public data member in class ShowRoom.
(iii) ShowRoom::Enter(), ShowRoom::Display()
(iv) Factory::FID, Factory::Address, Factory::NOE, Director::Description, Director::Allocate(),
Director::Assign(), Director::Show()
3.(a) void REASSIGN (int a[], int size) //see ref. unit-3 q.no. B.9
{ for( int i=0 ; i< size ; i++)
{ if(a[i]%5 = = 0)
a[i] / = 5;
else
a[i] * = 2;
}
cout<<”Show array after rearrangement:”<<endl;
for(i = 0; i < size; i++)
cout << a[i]<<” “;
}
(b) Formula for the Column Major order 2- D Array:
Address of [ i , j ]th element = B.A. + W( (i – Lr ) + R(j - Lc ))
For the given Column Major order problem: w= 4, R= 90, Lr= Lc = 0, BA = 7200
Address of T[10][40] = 7200 + 4 ( (10-0) +90 ( 40-0))
=21640 Ans.
(c) #include<conio.h>
#include<stdio.h>
#include<iostream.h>
193
#include<string.h>
struct Node
{ char city[25];
Node *next;
}*ptr,*newptr;
class Queue
{Node *F,*R;
public:
Queue() { F=NULL; R=NULL; }
void Insert();
void Del();
void display();
};
void Queue::Insert()
{char *p;
cout<<"\nEnter a city: ";
(c) gets(p);
newptr=new Node;
strcpy(newptr->city,p);
newptr->next=NULL;
if(R==NULL)
F=R=newptr;
else
{
R->next=newptr;
R=newptr;
}
}
void Queue::Del()
{ char *p;
if(F==NULL)
cout<<"\nQueue underflow!!!!!";
else
{strcpy(p,F->city);
ptr=F;
if(F==R)
F=R=NULL;
else
F=F->next;
delete ptr;
cout<<"Element Deleted= "<<p<<endl;
}
}
void Queue::display()
{if(F==NULL)
cout<<"\nQueue underflow!!!!";
else
{ptr=F;
while(ptr!=NULL)
{cout<<ptr->city<<"-->";
ptr=ptr->next;
}
}
}
void main()
{clrscr();
Queue q1;

194
char ch='y';
while(ch=='y')
{ q1.Insert();
cout<<"Queue contains: \n";
q1.display();
cout<<"\nDo you want to enter more data in Queue....enter y or n?\n";
ch=getche();
}
cout<<"\nDo you want to delete elements..enter y or n\n";
ch=getche();
cout<<endl;
while(ch=='y')
{q1.Del();
q1.display();
cout<<" do u wana more del enter y or n \n";
ch=getche();
}
getch();
}
(d) int ALTERSUM ( int B[] [5], int N, int M )
{ int i, j, sum=0,k;
for(i=0, k=0 ; i<N ; i++)
{ for(j=0 ; j<M ; j++,k++)
{ cout<<B[i][j]<<" ";
if(k%2==0)
sum += B[i][j];
}
cout<<"\n";
}
cout<< "Sum of Alternate Elements: "<<sum<<endl;
}

(e) The given Postfix notation is: True, False, NOT, OR, False, True, OR, AND
SNo Symbol Action Stack Evaluation
Scanned Performed
1 True Push True $ True
2 False Push False $ True False
3 NOT Calc. NOT $ True True Not False = True
4 OR Calc. OR $ True True OR True = True
5 False Push False $ True False
6 True Push True $ True False True
7 OR Calc. OR $ True True False OR True = True
8 AND Calc. AND $ True True ANDTrue= True
Ans: True

4.(a Statement 1=> Pos=F.tellg();


) Statement 2 => F.seekp(Pos-sizeof(C));
// reference: Unit 4- Q.No. C-9
(b) void Count_to_the()
{ fstream afile("POEM.TXT", ios::in);
char ch[50];
int count=0;
while(!afile.eof())
{ afile>>ch;
if(strcmpi(ch, "the")==0 || strcmpi(ch, “to”) == 0)
count++;
195
}
afile.close();
cout<<"Total number of \”to\” and \”the\” in the File are = "<<count;
}
// reference: Unit 4- Q.No. C-21
void Display()
(c) { ifstream file(“TRAIN.DAT”, ios::binary | ios::in);
TRAIN T;
while(file.read((char *) &T, sizeof(T)))
{ if(strcmpi(T.GetTo(), “Delhi”) ==0)
T.Show();
}
file.close();
}
5.(a) A Primary Key is a set of attributes that can uniquely identify the tuples within the relation. It must
be unique in the relation. For example: a table of student’s record may have different type of
attribute but a rollno field can act as a primary key for that table, because it is unique for all
students.
For example: Table Item
ItemCode Item Qty UnitPrice
5005 Ball Pen 0.5 100 16
5003 Ball Pen 0.25 150 20
5002 Gel Pen Premium 125 14
5006 Gel Pen Classic 200 22
The ItemNo is uniquely assigned to each item, so it can act as primary.
(b)
(b1)
(i) SELECT * FROM STOCK ORDER BY StockDate;
(ii) SELECT ItemNo, Item, UnitPrice FROM Stock WHERE UnitPrice >10;
(iii) SELECT * FROM STOCK WHERE Dcode = 102 OR Qty>100;
(iv) SELECT MAX(UnitPrice), Dcode FROM STOCK GROUP BY Dcode;
(b2)
(i) COUNT(DISTINCT Dcode)= 3
(ii) Qty*UnitPrice
4400
(iii) ItemDName
Eraser Big Clear Deals
(iv) MIN (StockDate)
01-Jan-09
6.(a) X’.Y + X.Y’ = (X’ + Y’) . (X + Y)
Take R.H.S. (X’ + Y’) . (X + Y) = X’.X + X’.Y + Y’.X + Y’.Y
= 0 + X’.Y + Y’.X + 0 = X’.Y + X.Y’ = L.H.S Hence Prooved.
(b) (U’ +V) (V’ + W)
(c) To get the SOP form for the given Boolean Function G, find the Minterms from the given Truth
Table:
(d) P’.Q.R’ + P’.Q.R + P.Q’.R’ + P.Q.R’ + P.Q.R is the required SOP form.
The given function is: F (A,B,C,D) =  (3,4,5, 6, 7,13,15)
The Karnaugh Map for the given Boolean function is:
AB\CD 00 01 11 10
00 0 0 1 0
01 1 1 1 1
11 0 1 1 0
10 0 0 0 0
It gives Two quads and one pair :
The equation for the Quad 1 is: A’B

196
The equation for the Quad 2 is: BD
The equation for the pair is: A’CD
So the final minimized expression for the F(A,B,C,D) = A’B + BD + A’CD
7.a The ARPANET was the first Computer Network in the world, developed by the Depatment of
Defence in 1969 in USA. Its full name is Advanced Research Projects Ajency Network. It provides
the path and the idea of a computer network, which explores the utilsation and advantages of a
computer network. After this in mid 80’s one another n/w created, called NSF Net, on the basis of
ARPANET, which was high capacity and faster n/w.
(b) (iii) sbps
(c) A computer virus is a small program written to alter the way a computer operates, without the
permission or knowledge of the user.A computer virus attaches itself to a program or file enabling it
to spread from one computer to another, leaving infections as it travels.
A worm is similar to a virus by design and is considered to be a sub-class of a virus. Worms spread
from computer to computer, but unlike a virus, it has the capability to travel without any human
action. A worm takes advantage of file or information transport features on your system, which is
what allows it to travel unaided. The biggest danger with a worm is its capability to replicate itself
on your system, so rather than your computersending out a single worm, it could send out hundreds
or thousands of copies of itself, creating a huge devastating effect.
(d) Firewall is used for the given purpose.
(e) (e1) Layout 1: 120
MainBuil Resource
ding Building

40 45

Training Accounts
Building Building

Total Cable Length: 205 Meters, in Bus Topology

Layout 2: MainBuil Resource


ding Building
125

40

Training Accounts
Building 110 Building

Total Cable Length: 275 Meters, in Star Topology


In terms of cable length, the first layout is the best, if high speed & control is required, then Layout
2 can be used.
(e2) To house the server, Training Building is the best place as per the 80:20 rules. This building has
more number of computers as compare to the others, so the server should be placed in the building
where the internal traffic is highest.
(e3) (i) Repeater: it is can be placed between Main to Resource buildings, because the distance is
more, as in layout 1. if they use layout 2 than it require in between Training to Resource and
Training to Accounts building.
(ii) Hub/Switch: they require in each building to connect the computers together.
(e4) (ii) Optical Fiber is to be used for high speed connectivity.
(f) (1) FTP: File Transfer Protocol (2) FSF: Free Software Foundation
(g) Examples of Web Browsers are:
1) FireFox and Internet Explorer for Windows.
2) Amaya and Emacs for Linux.
3) Comino and Opera 10.10 for Mac OS X.

197
CBSE- All India Senior Secondary Certificate Examination-2008-09 (Out Side Delhi)
Subject : Computer Science ( 083)
Time Allowed: 3 Hours Max. Marks: 70

1. (a) What is the purpose of using a typedef command in c++. Explain with suitable example. 2
Name the header files that shall be needed for the following code:
(b) void main() 1
{
char Word[] = “Exam”;
cout<<setw(20)<<Word;
}
(c) Rewrite the following program after removing the syntax error(s) , if any. Underline each correction. 2
#include<iostream.h>
void main()
{
One = 10, Two = 20;
Callme(One; Two);
Callme(Two);
}
void Callme(int Arg1, int Arg2 = 20)
{
Arg1 = Arg1 + Arg2;
Cout<<Arg1 >> Arg2;
}
(d) Find the out put of the following program: 3
#include<iostream.h>
#include<ctype.h>
void main()
{
char Mystring [ ] = “ What@OUTPUT!”;
for ( int I = 0; Mystring [I] ! = ‘\0’ ; I++)
{ if (!isalpha(Mystring [I]))
Mystring [I] = ‘*’ ;
else if ( isupper (Mystring [I]) )
Mystring [ I ] = Mystring [ I ] + 1;
else
Mystring [ I ] = Mystring [ I + 1 ];
}
cout<< Mystring;
}
(e) Find the output of the following program: 2
#include<iostream.h>
void main()
{ int a= 5, b =10;
for(int i =1; i<2 ; i++)
{ cout<< “ Line 1 = “<<a++ <<” & “<< b-2 <<endl;
cout<< “ Line 2 = “<<++b <<” & “<< a+3 <<endl;
}}
(f) In the following program, find the correct possible output(s) from the options: 2
#include<iostream.h>
void main()
{ randomize();
char Area [] [10] = { “NORTH”, “SOUTH”, “EAST”, “WEST”};
int togo;
for ( int i = 0; i<3 ; i++)
{ togo = random (2) + 1;
cout<< Area[togo] << “ : “;
198
}
}
Outputs:
(i) SOUTH:EAST:SOUTH:
(ii) NORTH:SOUTH:EAST:
(iii) SOUTH:EAST:WEST:
(iv) SOUTH:EAST:EAST:
2.(a) Differentiate between private and protected visibility modes in context of object oriented 2
programming giving a suitable example illustrating each.
(b) Answer the questions (i) and (ii) after going through the following program: 2
#include<iostream.h>
#include<string.h>
class Retail
{ char Category[20];
char Item[20];
int Qty;
float Price;
Retail() //Function 1
{
strcpy(Category, "Cereal");
strcpy(Item, "Rice");
Qty=100;
Price=25;
}
public:
void Show() //Function 2
{ cout<<Category<<" _ "<<Item<<" : :”<<Qty<<"@"<<Price<<endl;
}
};
void main()
{ Retail R; //Statement 1
R.Show(); //Statement 2
}

(i) Will Statement 1 initialize all the data members for the object R with the values given in the Function
1? (Yes or No). Justify your answer suggesting the correction(s) to be made in the above code.
(ii) What shall be the possible output when the program gets executed? (Assuming, if required- the
suggested correction(s) are made in the program)
(c) Define a class Clothing in c++ with the following descriptions: 4
Private Member:
Code of type string
Type of type string
Size of type integer
Material of type string
Price of type float
A function Calc_Price() which calculates and assign the value of Price as follows:
for the value of Material as "COTTON":
Type Price(Rs.)
TROUSER 1500
SHIRT 1200
For Material other than "COTTON" the above mentioned Price gets reduced by 25%.
Public Members:
• A constructor to assign initial values of Code, Type and Material with the word "NOT
ASSIGNED" and Size and Price with 0.
• A function Enter() to input the values of the data members Code, Type, Size and Material and
invoke the Calc_Price() function.
• A function Show() which display the content of all the data members for a Clothing.

199
(d) Answer the questions (i) to (iv) based on the following code: 4
class Toys
{ char TCode;
protected:
float Price;
void Assign(float);
public:
Toys( );
void TEntry ( );
void TDisplay( );
};
class SoftToys : public Toys
{ char STName[20];
float Weight;
public:
SoftToys();
void STEntry ( );
void STDisplay ( );
};
class ElectronicToys : public Toys
{ char ETName[20];
int no_of_Batteries;
public:
void ETEntry ();
void ETDisplay();
};
(i) Which type of inheritance is shown in the above example?
(ii) How many bytes will be required by an object of the class SoftToys?
(iii) Write name of the entire data member, which are accessible from member functions of the class
SoftToys.
(iv) Write name of all the member functions, which are accessible from an object of the class
ElectronicToys.
3.(a) Write a function in C++, which accepts an integer array and its size as arguments and swap the 4
elements of every even locations with its following odd location.
example: if an array of nine elements initially contains the elements as:
2, 4, 1, 6, 5, 7, 9, 23, 10
then the function should rearrange the array as:
4, 2, 6, 1, 7, 5, 23, 9, 10
(b) An array Arr[50][100] is stored in the memory along the row with each element occupying 2 bytes. 4
Find out the address of the location Arr[20][50], if the location Arr[10][25] is stored at the address
10000.
(c) Write a function in C++ to Delete an element from a dynamically allocated Queue where each node 4
contains a real number as data.
Assume the following definition of MYNODE for the same:
struct MYNODE
{ float NUM;
MYNODE *Link;
};
(d) Write a function in c++ to print the product of each row of a two dimensional integer array as the 2
argument for the function.Example: if the 2-D array contains:
20 40 10
40 50 30
60 30 20
40 20 30
Then the output should appear as:
Product of Row 1 = 8000
Product of Row 2 = 6000
Product of Row 3 = 3600
200
Product of Row 4 = 2400
(e) Evaluate the following postfix notations of expression (Show status of stack after execution of each 2
operation) :
5, 20, 15, -, *, 25, 2, *, +
4.(a) Observe the program segment given below carefully, and answer the question that follows: 1
class Candidate
{ long CId; //Candidate's ID
char CName[20]; //Candidate's Name
float Marks; //Candidate's Marks
public:
void Enter();
void Display();
void MarksChange();
long R_CId() { Return CId;}
};
void MarksUpdate(long Id) //Function to change marks
{ fstream File;
File.open("CANDIDATE.DAT",ios::binary|ios::in|ios::out);
Candidate C;
int Record=0, Found=0;
while(!Found && File.read((char *) & C, sizeof(C)))
{if(Id==C.R_CId())
{cout<<"Enter new marks:";
C.MarksChange();
_________________ //Statement 1
_________________ //Statement 2
Found = 1;
}
Record++;
}
if(Found==1)
cout<<"Record Updated!";
File.close();
}
Write the statement 1 to position the File pointer at the beginning of the record for which the
candidate's Id matches with the argument passed and Statement 2 to write the updated record at the
position.

(b) Write a function in C++ to count the number of uppercase alphabets present in a text file 2
"ARTICLE.TxT".
(c) Given a binary file "TELEPHON.DAT". containing records of the following class Directory: 3
class Directory
{char Name[20];
char Address[30];
char AreaCode[5];
char Phone_No[15];
public:
void Register();
void Show();
int CheckCode(char AC[])
{ return strcmp(AreaCode, AC);
}
};
Write a function COPYABC() in C++, that would copy only those records having AreaCode as "123"
from TELEPHON.DAT to a new file "TELEBACK.DAT".

201
5.(a) Differentiate between Candidate Key and AlterNet Key in context of RDBMS. 2
(b) Consider the following tables Item and Customer. Write SQL commands for the statements (i) to (iv) 6
and give outputs for SQL queries (v) to (viii).
Table: Item
I_ID ItemName Manufacturer Price
PC01 Personal Computer ABC 35000
LC05 Laptop ABC 55000
PC03 Personal Computer XYZ 32000
PC06 Personal Computer COMP 37000
LC03 Laptop PQR 57000

Table: Customer
C_ID CustomerName City I_ID
01 N Roy Delhi LC03
06 H Singh Mumbai PC03
12 R Pandey Delhi PC06
15 C Sharma Delhi LC03
16 K Agarwal Banglore Pc01

(i) To Display the Details of those Customers, whose City is Delhi.


(ii) To Display the details of Items, whose Price is in the range of 35000 to 55000 (Both values included).
(iii) To Display the CustomerName, City from table Customer and ItemName and Price from table Item,
with their corresponding matching I_Id.
(iv) To increase the Price of all Items by 1000 in the table Item.
(v) SELECT DISTINCT City FROM Customer;
(vi) SELECT ItemName, MAX(Price), Count(*) FROM Item GROUP BY ItemName;
(vii) SELECT CustomerName, Manufacturer FROM Item, Customer WHERE Item.I_Id =
Customer.I_ID;
(viii) SELECT ItemName, Price*100 FROM Item WHERE Manufacturer = ‘ABC’;
6.(a) State and verify Absorption law in Boolean Algebra. 2

(b) Draw a Logical Circuit Diagram for the following Boolean Expression: 1
A . (B + C`)

(c) Convert the following Boolean expression into its equivalent Canonical Product of Sum Form(POS): 2
A . B` . C + A` . B . C +A` . B . C`

(d) Reduce the following Boolean Expression using K-Map: 3


F(A,B,C,D) = ∑(0,1,2,4,5,8,9,10,11)

7.(a) What is Modem? 1

(b) Expand the following terms with respect to Networking: 2


(i) PPP (ii) GSM (iii) XML (iv) HTTP

(c) How is a Hacker different from a Cracker? 1

(d) “China Middleton Fashion” is planning to expand their network in India, starting with two cities in 4
India to provide infrastructure for distribution of their products. The company has planned to set up
their main office units in Chennai at three different locations and have named their offices as
“Production Unit”, “Finance Unit” and “Media Unit”. The company has its corporate unit in Delhi.

202
The layoutof the same is as below:

New Delhi Chennai

Corporate
Office Finance
Production
Delhi

Media

Approximate distance between these units is as follows:

From To Distance

Production Unit Finance Unit 70 mtrs


Production Unit Media Unit 15mtrs
Production Unit Corporate Unit 2112 km
Finance Unit Media Unit 15km

The no. of computers planned to install in these units are as follows:

Production Unit 150


Finance Unit 35
Media Unit 10
Corporate Unit 30

(i) Suggest the kind of network required for connecting each of the following units:
(1) Production Unit and Media Unit (2) Production Unit and Finance Unit
(ii) Which one of the following devices will you suggest for connecting all the computers within each of
their office units?
(1) Switch/Hub (2) Modem (3) Telephone
(iii) Which of the following communication media, will you suggest to be procured by the company for
connecting their local office units in Chennai for very effective (High Speed) communication?
(1) Telephone Cable (2) Optical Fiber (3) Ethernet Cable
(iv) Suggest a cable/wiring layout for connecting the company’s local office units locatedin Chennai. Also
Suggest an effective method/technology for connecting the company’s office unit located in Delhi.

203
CBSE- Senior Secondary Certificate Examination-2008-09
Subject: Computer Science (083)
Solution
QN Answers
1.(a) typedef is a user defined data type, which is used to declare a variable as a data type definer and it can
be used later on to declare the other same data type variables. For e. g.
typedef int Integer; //Integer is an int type variable
Integer m; // m is act as a int variable
(b) #include<iostream.h>, #include<iomanip.h>
(c) #include<iostream.h>
void Callme(int Arg1, int Arg2 = 20)
{ Arg1 = Arg1 + Arg2;
cout<<Arg1 << Arg2;
}
void main()
{ int One = 10, Two = 20;
Callme(one, Two);
Callme(Two);
}
(d) Output: Xat@*PVUQVU*
(e) Output: Line 1 = 5 & 8
Line 2 = 11 & 9
(f) Possible Output:
(v) SOUTH:EAST:SOUTH:
(iii) SOUTH:EAST:WEST:
(iv) SOUTH:EAST:EAST:

2.(a) Visibility modes in Inheritance define the inheritable members of base class into derived class. The
comparison is as follows:
Base class Members/ Visibility modes: PrivateProtectedPubic
Private Not Inheritable in all modes
Protected Private Protected Protected
Public Private Protected Public
(b)
(i) No, becauses the constructor is in private section and which is not accessible outside. It
should be in public.
(ii) Cereal _ Rice : : 100@ 25

(c) class Clothing


{ char Code[10], Type[15], Material[15];
int Size;
float Price;
void Calc_Price()
{ if ( strcmp(Material, "COTTON")==0)
{ if(strcmp(Type, "TROUSER") ==0)
Price=1500;
else if(strcmp(Type, "SHIRT")
Price=1200;
else
cout<<”There are only Trouser and Shirt type items!!!!\n”;
}
else
{ if(strcmp(Type, "TROUSER")
Price=1500 - 1500 * 0.25;
else if(strcmp(Type, "SHIRT")
Price=1200 - 1200 * 0.25 ;

204
else
cout<<”There are only Trouser and Shirt type items!!!!\n”;
}
}
public:
Clothing()
{ strcpy(Code,"NOT ASSIGNED");
strcpy(Type,"NOT ASSIGNED");
strcpy(Material,"NOT ASSIGNED");
Size = 0;
Price = 0;
}
void Enter()
{ gets(Code);
gets(Type);
gets(Material);
cin>>Size;
Calc_Price();
}
void Show()
{cout<<"Code: <<Code<<"\t"<<"Type:"<<Type<<\t"<<"Material:”<<
Material <<endl;
cout<<"Size:<<Size<<"\t"<<"Price:"<<Price<<endl;
}
};
(d) (i) Hierarchical Inheritance
(ii) 29
(iii) STName, Weight
(iv) ET_Entry(), ETDisplay(), TEntry(), TDisplay()
3.(a) void Rearrange(int a[], int size)
{ int k, t;
for( int i=0 ; i< size-1 ; i+=2)
{ t = a[i];
a[i] = a[i+1];
a[i+1] = t;
}
cout<<”Show array after rearrangement:”<<endl;
for(k = 0; k < size; k++)
cout << a[k]<<” “;
}
(b) For the given Row Major order problem: w= 2, C= 100, Lr= Lc = 0, BA = ?
Address of ARR[10][25] => 10000 = BA + 2 ( 100 (10-0) + ( 25-0))
B.A. = 10000- 2050 = 7950 Ans
Address of X[20][50] = 7950 + 2 ( 100 (20-0) + ( 50-0))
= 12050 Ans
(c) void Delete(MYNode *Front, MYNode *Rear)
{ MYNode *ptr;
if(Front == NULL)
cout<<”Empty Queue!!!”;
else
{ ptr = Front;
if(Front == Rear)
Front = Rear = NULL;
else
Front = Front ->next;
cout<< “Node Deleted: ”<<ptr->NUM;
delete ptr;

205
}}
(d) void Sum(int a[3][3]) // for example the 2-D array is of 3 x 3 size
{ int i, j, Product;
for(i=0 ; i<3 ; i++)
{ Product = 1;
for(j=0 ; j<3 ; j++)
{ cout<<a[i][j]<<” “;
Product *= a[i][j];
}
cout<< “Product of Row: “<<i+1<<” = “<<Product<<endl;
}}
(e) 5, 20, 15, -, *, 25, 2, *, +
SNo Symbol Action Stack Evaluation
Scanned Performed
1 5 Push 5 $5
2 20 Push 20 $ 5 20
3 15 Push 15 $ 5 20 15
4 - Cal. - $55 20 - 15 = push 5
5 * Calc. * $ 25 5 * 5 = push 25
6 25 Push 25 $ 25 25
7 2 Push 2 $ 25 25 2
8 * Calc. * $ 25 50 25 * 2 = push 50
9 + Calc. + $ 75 25 + 50 = push 75
Ans: 75
4.(a) Statement 1: File.seekp(Record * sizeof(C));
Statement 2: File.write((char *) & C, sizeof(C));
(b) void CountUpper()
{ ifstream afile;
afile.open("ARTICLE.TXT");
char ch;
int n = 0;
while(afile.get(ch))
{ if(isupper(ch))
n++;
}
cout<<" Total number of alphabets in upper case are: "<<n;
afile.close();
}
(c) void COPYABC()
{fstream afile,bfile;
Directory DR;
int ctr;
afile.open("TELEPHON.DAT",ios::in);
bfile.open("TELEBACK.DAT",ios::out);
while(afile.read((char *) &DR, size(DR)))
{
ctr=DR.CheckCode("123");
if(ctr==0)
{ cout<<"Record Found";
bfile.write((char *) & DR, sizeof(DR));
}
}
afile.close();
bfile.close();
}

206
5.(a) Candidate Key &Alternet Key are member of Super Key set. Candidate Key is a key, which is eligible
for Primary Key. Alternet Key is a key, which is eligible for Primary Key but not acting as a Primary
Key.
Candidate Key – Primary Key = Alternet Key. All Candidate Keys, which are not primary key are
calles Alternet Key.
(b) (i) SELECT * FROM CUSTOMER WHERE City =’Delhi’;
(ii) SELECT * FROM ITEM WHERE Price BETWEEN 35000 AND 55000;
(iii) SELECT ItemName, City, Price FROM CUSTOMER c, ITEM I WHERE C.I_ID
= I.I_ID
(iv) UPDATE ITEM SET Price= Price+1000;
(v) Banglore
Delhi
Mumbai
(vi) Laptop 57000 2
Personal Computer 37000 3
(vii) N Roy PQR
C Sharma PQR
K Agarwal ABC
H Singh XYZ
R Pandey COMP
(viii) Personal Computer 3500000
Laptop 5500000
6.(a) Absorption Law: (i) X + XY = X
(ii) X (X + Y) = X
Proof: (i) Take L.H.S. X + XY = X(1+Y) = X.1 = X = R.H.S. Hence Prooved
(ii) Take L.H.S. X.(X+Y) = X.X +X.Y = X + X.Y = X( 1 + Y) = X = R.H.S, Prooved

(b) B
C ANDF= A.(B+C’)
A

(c) The given expression is: A . B’ . C + A’ . B . C +A’ . B . C’


AB’C + A’B(C+C’) = AB’C +A’B = (AB’C+A’)(AB’C+B) = (A’+AB’C)(B+AB’C) =
= (A’+AB’)(A’+C) (B+AB’)(B+C) = (A’+B’)(A’+C)(A+B)(B+C)
For Canonical Form: (A’+B’+CC’)(A’+C+BB’)(A+B+CC’)(B+C+AA’)
=(A’+B’+C)(A’+B’+C’)(A’+B+C)(A’+B’+C)(A+B+C)(A+B+C’)(A+B+C)(A’+B+C)
= (A’+B’+C)(A’+B’+C’)(A’+B+C)(A+B+C’)(A+B+C) (removing the duplicate terms)
= (A+B+C)(A’+B+C)(A+B+C’)(A’+B’+C)(A’+B’+C’), is in canocial POS form.

(d) The Karnaugh Map for the given Boolean function is:
AB\CD
1 1 0 1
1 1 0 0
0 0 0 0
1 1 1 1
It gives Two quad and one Pairs:
The equation for the Quad 1 is: AB’
The equation for the Quad 2 is: A’C’
The equation for the Pair 1 is: A’B’D’
So the final minimized expression for the F(A,B,C,D) = AB’+A’C’+A’B’D’

7.(a) MODEM: (Modulator Demodulator) It is a communication device which provide the service of
converting the outgoing signals into analog form and converting incoming signals into digital form.
Generally used in dial up network through telephone line.

207
(b) (i) PPP : Point to Point Protocol (ii) GSM: Global System for Mobile Communication
(iii) XML: Extensible Markup Language (iv) HTTP: Hypertext Transfer Protocol

(c) Hackers Crackers


• Are more interested in gaining • Are malicious programmers who
knowledge about computers and breaks the secure system
possibly using this knowledge • Someone who breaks into or
for playful pranks otherwise violates the system
• Someone intensely interested integrity of remote machines with
the working of any computer malicious intent.
operating system. • Can obtain unauthorized access, in
• They probe the system, at both which they: Destroy vital data, Deny
macro and microcosmic level, legitimate users service, real overall
finding softwares holes and snag havoc for their targets.
in logic. • They donot write their programs, they
• They write programs to check beg, borrow or steal tool from others,
the integrity of other programs but they are expert in using these
or system. programs.

(d) (i) Production Unit and Media Unit = LAN


Production Unit and Finance Unit = LAN
(ii) Switch/Hub
(iii) Optical Fiber
(iv) An effective method/technology for connecting the company’s office unit located in Delhi, but
using Radio Communication / Satellite.

Cable Layout (1) :


Produ
70 ction
15
Finance
Media

Star Topology: Total Cable Length = 85 Meters.


Cable Layout (2):
Produ
ction

Media Finance

Linear Topology: Total Cable Length = 30 Meters.

208
CBSE- All IndiaSenior Secondary Certificate Examination-2007-08 (Out Side Delhi)
Subject : Computer Science ( 083)
Time Allowed: 3 Hours Max. Marks : 70
1. (a) What is the Difference between Actual Parameter and Formal Parameter? Give an example in C++ to 2
illustrate both types of parameters.
(b) Write the Name the header files to which the following belong: 1
(i) setw() (ii) sqrt()
(c) Rewrite the following program after removing the syntax error(s), if any. Underline each correction. 2
#include<iostream.h>
#include<stdio.h>
class MyStudent
{ int StudentID = 1001;
char Name[20];
public
Mystudent() { }
void Register() { cin>>StudentID; gets(Name); }
void Display() { cout<<StudentID<<”: “<<Name<<endl; }
};
void main()
{MyStudent MS;
Register.MS();
MS.Display();
}
(d) Find the out put of the following program: 3
#include<iostream.h>
void main()
{ int A[ ] = { 10, 15, 20, 25, 30 };
int *p = A;
while(*p<30)
{ if(*p%3 != 0)
*p = *p + 2;
else
*p = *p + 1;
p++;
}
for( int j = 0; j <= 4 ; j++)
{ cout<<A[j]<<” * “;
if(j%3 == 0)
cout<<endl;
}
cout<<A[4] * 3 <<endl;
}
(e) Find the output of the following program: 2
#include<iostream.h>
#include<ctype.h>
void Secret(char Msg[], int n);
void main()
{ char SMS[] = "rEPorTmE";
Secret(SMS, 2);
cout<<SMS <<endl;
}
void Secret (char Msg[], int n)
{ for(int c = 0; Msg[c] !='\0' ; c++)
if(c%2==0)
Msg[c]= Msg[c]+n;
else if (isupper(Msg[c]))
Msg[c] = tolower(Msg[c]);
209
else
Msg[c] = Msg[c] - n;
}
(f) Study the following program and select the possible output(s) from it: 2
#include<iostream.h>
#include<stdlib.h>
const int MAX =3;
void main()
{randomize();
int Number;
Number = 50 + random(MAX);
for(int P=Number ; P>=50 ; P--)
cout<<P<<"#";
cout<<endl;
}
(i) 53#52#51#50#
(ii) 50#51#52#
(iii) 50#51#
(iv) 51#50#
2.(a) What is function overloading? Give an example in C++ to illustrate function overloading. 2
(b) Answer the question (i) and (ii) after going through the following class: 2
class Job
{int JobID; char JobType;
public:
~Job() //Function 1
{ cout<<”Resigned”<<endl; }
Job() //Function 2
{ JobID = 10; JobType = ‘T’; }
void TellMe ()
{ cout<<JobID<<” : “<<JobType<<endl; } //Function 3
Job(Job & J) //Function 4
{ JobID = JobID+10; JobType = J.JobType +1;
}
};
(i) Which member function out of Function 1, Function 2, Function 3 and Function 4 shown in the
above definition of class Job is called automatically, when the scope of an object get over? Is it
known as constructor or Destructor or Overloaded Function or Copy Constructor?
(ii) Job P; //Line 1
Job Q(P); //Line 2
Which member function out of all 4 defined above in the class Job will be called on execution of
statement written as Line 2? What is this function specifically known as out of Destructor or Copy
Constructor or Default Constructor?

(c) Define a class HOTEL in C++ with the following description: 4


Private Members:
• Rno //Data member to store room no
• Name //to store customer name
• Tariff //to store per day charge
• NOD //to store number of days of stay
• CALC() //Function to calculate and return Amount as NOD*Tariff and if
// the value of NOD * Tariff is more than //10000 then as //1.05*NOD*Tariff
Public Members:
• Checkin() //function to enter the content Rno, Name, tariffand NOD
• Checkout() //Function to display Rno, Name, Tariff, NOD
//and Amount(call CALC() to get the Amount)

210
(d) Answer the questions (i) to (iv) based on the following: 4
class Regular
{ char SchoolCode[10];
public:
void InRegular();
void OutRegular();
};
class Distance
{ char StudyCentreCode[5];
public:
void InDistance();
void OutDistance();
};
class Course : public Regular, private Distance
{char Code[5];
float Fees;
int Duration;
public:
void Incourse();
void OutCourse();
};
(i) Which type of Inheritance is shown in the above example?
(ii) Write name of all the member functions accessible from OutCouse function of class Course.
(iii) Write name of all the members accessible through an object of class Course.
(iv) Is the function Inregular() accessible inside the function InDistance()? Justify your answer.

3.(a) Write a function SORTSCORE() in C++ to sort an array of structure Examinee in the descending order 3
of Score using Bubble Sort Method. (Note: Assume the following definition of structure Examinee)
struct Examinee
{ long RollNo;
char Name[20];
float Score;
};
(b) An Array T[50][20] is stored in the memory along the column with each of the element occupying 4 4
bytes. Find out the base address and address of element T[30][15], if an element T[25][10] is stored at
the memory location 9800.
(c) Write a function QUEDEL() in C++ to display and delete an element from a dynamically allocated 4
Queue containing nodes of the following given structure:
struct NODE
{ int Itemno;
char Itemname[20];
NODE *Link;
};
(d) Define a function SWAPPARR() in C++ to swap (interchange) the first row elements with the last row 3
elements, for a 2-D integer array passed as the argument of the function. Example: if the 2 d array
contains:
5 6 3 2
1 2 4 9
2 5 8 1
9 7 5 8

After swapping of the content of first row and last row, it should be as follows:

9 7 5 8
1 2 4 9
2 5 8 1
5 6 3 2

211
(e) Convert the following infix expression to its equivalent postfix expression showing stack contents for 2
the conversion: A + B * ( C – D ) / E

4.(a) Observe the program segment given below carefully and fill the blanks marked as Line 1 and Line 2 1
using functions for performing the required task.
#include<fstream.h>
class Library
{ long Ano; //Ano – Accession Number of the Book
char Title[20]; //Title of the Book
int Qty; // Number of Books in Library
public:
void Enter(int); // Function to enter the content
void Display(); // Function to display the content
void Buy(int Tqty) // Function to increment in Qty
{ Qty += Tqty; }
long GetAno() { return Ano; }
};
void BuyBook(long BAno, int BQty) // BAno – Ano of books purchased
{ // BQty – Number of books purchased
fstream File;
File.open("STOCK.DAT", ios::binary | ios::in | ios::out);
int Position = -1;
Library L;
while(Position == -1 && File.read((char *) & L, sizeof(L)))
if(L.GetAno() = = BAno)
{ L.Buy(BQty); // to update the number of books
Position = File.tellg() - sizeof(L);
____________________; // Line 1–to place the pointer to the required position
____________________; // Line 2 – write the updated record to the file
}
if(Position = -1)
cout<<"No updation done as required Ano is not found...";
File.close();
}
(b) Write a function COUNTTO() in C++ to count the presence of a word ‘to’ in a text file “NOTES.TXT”. 2
Example: if the content of the file is as follows:
It is very important to know that
Smoking is injurious to health.
Let us take initiative to stop it.
The function will display the following message:
Count of –to- in file: 3
Note: In the above example, ‘to’ occurring as a part of word stop is not considered.

(c) Write a function in C++ to read and display the detail of all the members whose membership type is’L’ 3
or ‘M’ from a binary file “CLUB.DAT”. Assume the binary file contains object of class CLUB, which
is defined as follows:
class CLUB
{int Mno; //Member number
char Mname[20]; //name
char Type; //Member Type:- L for Life time Member, M for //Monthly, G- Guest
public:
void Register(); // Function to enter data
void Display(); // Function to display content
char WhatType() { return Type; }
};

212
5.(a) What is the purpose of a Key in a table? Give an example of a key in a table. 2
(b) Consider the following tables DRESS and MATERIAL. Write SQL commands for thestatements (i) to 6
(iv) and give outputs for SQL queries (v) to (viii).
Table: DRESS
DCODE DESCRIPTION PRICE MCODE LAUNCHDATE
10001 FORMAL SHIRT 1250 M001 12-JAN-08
10020 FROCK 750 M004 09-SEP-07
10012 INFORMAL SHIRT 1450 M002 06-JUN-08
10019 EVENING GOWN 850 M003 06-JUN-08
10090 TULIP SKIRT 850 M002 31-MAR-07
10023 PENCIL SKIRT 1250 M003 19-DEC-08
10089 SLACKS 850 M003 20-OCT-08
1007 FORMAL PANT 1450 M001 09-MAR-08
10009 INFORMAL PANT 1400 M002 20-OCT-08
10024 BABY TOP 650 M003 07-APR-07
Table: MATERIAL
MCODE TYPE
M001 TERELENE
M002 COTTON
M224 POLYSTER
M003 SILK

(i) To display DCODE and DESCRIPTION of each dress in ascending order of DCODE.
(ii) To display the details of all the dresses which have LAUNCHDATE in between 05-DEC-07 and 20-
JUN-08.(inclusive both dates)
(iii) To display the average PRICE of all the dresses which are made up of material with MCODE as M003.
To display Material wise highest and lowest price of dresses from DRESS table. (Display MCODE of each
(iv) dress along with highest and lowest price)
(v) (a) Select SUM(PRICE) From DRESS Where MCODE = ‘M001’;
(b) Select DESCRIPTION, TYPE From DRESS, MATERIAL Where DRESS.PRICE >= 1250
And DRESS.MCODE = MATERIAL.MCODE;
(c) Select Max(MCODE) From MATERIAL;
(d) Select Count(Distinct PRICE) From DRESS;
6.(a) State and verify the absorption law using truth table. 2
(b) Write the equivalent Boolean Expression for the following Logic Circuit: 2

(c) Write the POS Form of a Boolean Function G, which is represented by a truth table as follows: 1

U V W G
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 0
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 1

213
(d) Reduce the following Boolean Expression using K-Map: 3
F(x,y,z,w) = ∑ (0, 1, 4, 5, 6, 7, 11, 12, 13, 14, 15)
7.(a) What is different between LAN and WAN? 1

(b) Expand the following abbreviations: 1


(i) HTTP (ii) ARPANET
(c) What is protocol? Which protocol is used to copy a file from/to a remotely located server? 1

(d) Name two switching techniques used to transfer data between two terminals. 1

(e) “EdumindsUniversity” of India is starting its first campus in a small town Parampur of Central India 4
with its center admission office at Delhi. The university has a 3 major building comprising of
AdminBuilding, AcademicBuilding and ResearchBuilding in the 5 KM area campus. As a network
expert, you need to suggest the network plan as per (E1) to (E4) to the authorities keeping in mind that
distances and other given parameters.

EdumindsUniversity
Parampur Campus
Delhi Acedemic Research
Admission
Office

Admin

Expected wire distances between various location:


From To Distance
ResearchBuilding AdminBuilding 90 mtrs
ResearchBuilding AcademicBuilding 80 mtrs
AcademicBuilding AdminBuilding 15 m
Delhi Adm. Office Parampur Campus 1450 km
Expected number of computers to be installed at various locations:
Research Buildin 20
AcademicBuilding 150
AdminBuilding 35
Delhi Adm. Office 5

(E1) Suggest to the authorities, the cable layout amongst various building inside the university campus for
connecting the buildings.
(E2) Suggest the most suitable place (i.e. building) to house the server of this organization, with a suitable
reason.
(E3) Suggest an efficient device from the following to be installed in each of the buildings to connect all the
computers:
(i) GATWAY (ii) MODEM (iii) SWITCH
(E4) Suggest the most suitable (very high speed) service to provide data connectivity between
AdmissionBuilding located in Delhi and the campus located in Parampur from the following options:
(1) Telephone Line (2) Fixed Line Dial-up connection (3) Co-axial Cable Network
(4) GSM (5) Satellite Connection

214
CBSE- Senior Secondary Certificate Examination-2007-08
Subject: Computer Science ( 083)
Solution
1. (a) The Actual Parameter are the data members of calling function, which are likely to transfer into called function
and Formal Parameters are the members of called function, which are used to receive the values/ references of
actual parameters of calling function.
void main() //calling function
{ int a;
cin>>a;
void fun(int );
fun(a); // passing value of a to fun(), here a is actual parameter
…….
}
void fun(int b) // called function, b is formal parameter, receive value of a
{
………
}

(b) (i) setw():- iomanip.h (ii) sqrt():- math.h

(c) Rewrite the following program after removing the syntax error(s), if any. Underline each correction.
#include<iostream.h>
#include<stdio.h>
class MyStudent
{ int StudentID;
char Name[20];
public:
MyStudent() {}
void Register() { cin>>StudentID; gets(Name); }
void Display() { cout<<StudentID<<”: “<<Name<<endl; }
};
void main()
{
MyStudent MS;
MS.Register();
MS.Display();
}

(d) 12*16*22*27*
30*90

(e) teRmttoe

(f) (i) 53#52#51#50#


(iv) 51#50#
2.(a) Functional overloading is the ability of function to be processed in more than one form. One function can
represent in more than one ways or a function name having several definitions which are having different
argument types or return types.
e.g.
void square(int a, int b)
{ return (a*b);
}
void square(int x, float y)
{ return ( x*y);
}

215
(b) (i) Function 1, it is known as destructor.
(ii) Function 4, it is known as copy constructor.

(c) class HOTEL


{ int Rno, Tariff, NOD;
char Name[25];
int CALC()
{ if(NOD*Tariff >10000)
return (1.05*NOD*Tariff);
else
return(NOD*Tariff);
}
public:
void Checkin()
{ cin>>Rno;
gets(Name);
cin>>Tariff>>NOD; }
void Checkout()
{ int Amount = CALC();
cout<<Rno<<": " <<Name<<":"<<Tariff<<":"<<NOD<<":"<<"Amount="<<Amount;
}
};

(d) (i) Multiple Inheritance


(ii) InCourse(), InDistance(), OutDistance(), InRegular(), OutRegular()
(iii) InCourse(), OutCourse, InDistance(), OutDistance(), InRegular(), OutRegular()
(iv) No, because there is no relationship between the classes Regular and Distance. So Distance class
member can not access members of class Regular.

3.(a) void StructSort(Examinee emp[], int size)


{ employee temp;
for(int i =0; i<size-1 ; i++)
{ for(int j=0; j< size -1 – i ; j++)
{ if(emp[j].Score < emp[j+1].Score)
{ temp = emp[j];
emp[j] = emp[j+1];
emp[j+1] = temp;
}
}
}
cout<<”Show Employee Records after Sorting”<<endl;
for(i = 0; i < size; i++)
{ cout<<”Employee : “<<i+1<<endl;
cout << emp[i].Rollno<<”\t “<< emp[i].Name<<”\t “<< emp[i].Score<<”\n “;
}
return;
}
(b) For the given Column Major order problem: w= 4, R= 50, Lr = Lc = 0
Address of T[25][10] => 9800 = BA + 4 ( (25-0) +50 ( 10-0))
B.A.= 9800 – 2100 = 7700 Ans.

Address of T[30][15] = 7700 + 4 ( (30-0) +50 ( 15-0))


= 10820 Ans.
(c) void QUEDEL(NODE * Front, NODE * Rear)
{ Node *ptr;
if(Front = = NULL)

216
cout<<"Queue Empty !!!";
else
{ ptr= Front;
if(Front == Rear)
Front = Rear = NULL;
else
Front = Front ->Link;
cout<<"NODE Deleted :"<<ptr->Itemno<<" " <<ptr->Itemname<<endl;
delete ptr;
}
}
(d) void SWAPPARR(int a[4][4])
{ int t, j=3, k=0;
for(int i = 0; i<=3; i++)
{ t = a[k][i];
a[k][i] = a[j][i];
a[j][i] = t;
}
cout<<”2-d array after modification :\n ”;
for(int i = 0; i<=3; i++)
{ for(int j = 0; j<=3; j++)
cout<< a[i][j] <<” “;
cout<<"\n";
}
}

(e) To convert this infix into postfix, first enclose the given expression into ( ). We take use a stack to solve the
problem:(A + B * ( C – D ) / E)

SNo Symbol Action Stack Output


Scanned Performed Expression
1 ( Push ( $(
2 A o/p $( A
3 + Push + $(+ A
4 B o/p $(+ AB
5 * Push * $(+* AB
6 ( Push ( $(+*( AB
7 C o/p $(+*( ABC
8 - Push - $(+*(- ABC
9 D o/p $(+*(- ABCD
10 ) Pop -, ( $(+* ABCD-
11 / Pop *,Push / $(+/ ABCD-*
12 E o/p $(+/ ABCD-*E
13 ) Pop * - $(+/ ABCD-*E/+
So the final out put postfix expression is: ABCD-*E/+

4.(a) Line 1: File.seekp(Position);


Line 2: File.write((char *) & L, sizeof(L));

(b) void COUNTTO()


{ fstream afile("STORY.TXT", ios::in);
char ch[50];
int count=0;
while(!afile.eof())

217
{ afile>>ch;
if(strcmpi(ch, "to")==0)
count++;
}
afile.close();
cout<<"Total number of to’s and the’s in the file = "<<count;
}

(c) void MemberDetails()


{ ifstream fin;
CLUS S;
fin.open("CLUB.DAT", ios::in);
while(fin.read((char *) &S, sizeof(S)))
{ if((S.WhatType() ==’L’ || S.WhatType() ==’M’ )
S.display();
}
fin.close();
}
5.(a) A Key is a set of attributes, which are distinct and have some valuable properties in the table. Keys are used in
database for various operations and relationship.The various keys used in database are: Super Key, Primary
Key, Candidate Key, Alternet Key eyc.

(b)(i) Select DCODE, DESCRIPTION From DRESS Order By DCODE;


(ii) Select * From DRESS Where LAUNCHDATE>=”05-DEC-07” And LAUNCHDATE<=”20-JUN-08”;
Select AVG(PRICE) From DRESS Where MCODE=’M003’;
(iii) Select MAX(PRICE), MIN (PRICE), MCODE From DRESS Group By MCODE;
(iv) Output:
(v) (a) 2700
(b) FORMAL SHIRT TERELENE
INFORMAL SHIRT COTTON
PENCIL SKIRT SILK
FORMAL PANT TERELENE
INFORMAL PANT COTTON
(c) // please read the note
No output (note: max() always use to find out the maximum value in a range of numbers, but here max is given to find maximum
MCODE, where MCODE is of character type than we can find the max string alphabetically. (by ascii value)
(d) 1250 750 1450 850 1400 650

6.(a) Absorption Law: (i) X + XY = X


(ii) X (X + Y) = X
Proof: (i) Take L.H.S. X + XY = X(1+Y) = X.1 = X = R.H.S. Hence Prooved
(ii) Take L.H.S. X.(X+Y) = X.X +X.Y = X + X.Y = X( 1 + Y) = X = R.H.S, Prooved

(b) AB’ + C’D

(c) G(U, V, W) = (U + V’ + W) (U + V’ + W’) (U’ + V’ + W)

(d) F(x,y,z,w) = ∑ (0, 1, 4, 5, 6, 7, 11, 12, 13, 14, 15)


The Karnaugh Map for the given Boolean function is:
xy\zw 00 01 11 10

00 1 1 0 0
01 1 1 1 1
11 1 1 1 1
10 QQ1
0 0 1 0
This gives one Octect, one Quad and one Pair:
The expression for Octet : y
218
The expression for Quad : x’z’
The expression for Pair : xzw
So the final minimized expression for the F(x,y,z,w) = y+x’z’+xzw

7.(a) The different between LAN and WAN is:


LAN WAN
1. Small range 11. Unlimited range
2. High speed 12. Medium speed
3. Very low data error rate 13. Data error rate high
4. Managed and controlled by 14. none
one person or unit. 15. No of computer are
5. Less no of computers unlimited

(b) (i) HTTP: Hypetext Transfer Protocol


(ii) ARPANET: Advance Research Project Agency Network

(c) Protocol is a set of rules or instructions, designed to solve the network problem or to accomplish the goal of
communication. FTP (File Transfer Protocol) is used to transfer the file from one system to another, over a
network.

(d) Message switching: A source computer sends data or message to another computer and the whole message will
transfer as a group from sender to first switching office and from that place to the receiver’s switching office.
Packet Switching: In this technique the whole message will divided into smaller packets, where each packet
contains one header. The header kept the information of sender and receiver. All the packets travel through
network from sender to receiver. The advantage of this technique is, less chance of loss of whole information
and if any packet lost, then it can be easily retransmitted.

(e) Layout for the cable network: Star Topology


(E1)
80
Acedemic Research
15

Total Cable Length: 95 Meter


Admin

(E2) The server should be place in the AcedemicBuilding, because this wing contains number of computer are very
large (150) as we compare with others. As per 80 : 20 rule of the LAN design the server should be placed in a
block where the 80 % of the network traffic should be local and this wing has the ratio of 150:55 of computer.
So the network traffic in this wind will be highest.

(E3) SWITCH

(E4) Satellite Communication

219

You might also like