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

Class XII

Computer Science
CHAPTER WISE
HOTS (High Order Thinking Skill
!"ESTIO#S WITH A#SWER
$ASE%
O#
C$SE PATTER#
Prepared by: PGTs (Computer Science)
1. REVISIO TO!R C""# POITERS $ %rs. Vais&a'i# (V o.1 )e'&i
Cantt.
*. C'asses + Ob,ects# Constructor and )estructor# In&eritance# %r. Pradeep#
(V C&a-'a
.. )ata Structure $ /in0 /ist# Stac0s and 1ueues# arsi /a'# (V 2GCR
3. )ata 4i'e &and'in5 in c"" 6 %s %anpreet (aur# (V 2ndre-s5an,
7. )8%S + S1/ $ %r. 2s&o0# (V 8a-ana
9. 8oo'ean 2'5ebra $ :ar'een (aur# (V Vi5yanVi&ar
;. Communication and et-or0 Concepts $ San,ay (umar ama# (V <!
6 * 6
WHERE IS WHAT&
C&ap 1. Pro5rammin5 in c"" Structure OOP=s Concepts Pointers ( 3 $ 7 )
C&ap *. C'ass and Ob,ects# Constructor 2nd )estructor 2nd In&eritance ( 9 $ 1> )
C&ap . 2rrays /in0ed /ist + Stac0 1ueues ( 11 $ *1 )
C&ap 3 )2T2 4I/E :2)/IG I C"" ( ** $ *3 )
C&ap 7 )2T282SE COCEPTS + S1/ ( *7 $ *? )
C&ap 9 8OO/E2 2/GE8R2 ( .> $ .* )
C&ap ; CO%%!IC2TIO + CO%P!TER ET@OR(S (.. $ .3 )
6 . 6
!uestion '( RE)ISIO# TO"R C**+ OOPs Concepts , POI#TERS
1 1 @:2T @II/ 8E O!TP!T O4 4O//O@IG PROGR2%A 1
#include<iostream.h>
# include <conio.h>
void main()
{
clrscr();
int sum(int(*)(int),int);
int square(int);
int cube(int);
cout<<sum(square,4)<<endl;
cout<<sum(cube,4)<<endl;
getch();
}
int sum(int(*tr)(int !),int n)
{
int s"#;
$or(int i"%;i<"n;i&&)
{
s&"(*tr)(i);
}
return s;
}
int square(int !)
{ int sq;
sq"!*!;
return !*!;
}
int cube(int !)
{
return !*!*!;
}
2S 1B O!TP!T @I// 8E
.>
1>>
1*B:o- many times -i'' t&e Co''o-in5 pro5ram -i'' print DeEaminationFA 1
#include<iostream.h>
void main( )
{
'hile(%)
{
cout<<(e)amination(
}
}
2S *B!n'ess GC is pressed #pro5ram -i'' print DeEaminationF inCinite'y.
6 3 6
1 .B @i'' t&e Co''o-in5 pro5rams produce same outputA *
Program '
# include<iostream.h>
# include<conio.h>
void main()
{
int ),*"%;
i$(()"*)+"#)
cout<<)<<, ,<<*;
getch();
}
Program 2
# include<iostream.h>
# include <conio.h>
void main()
{
int ),*"#;
i$(()"*"%)""%)
cout<<)<<, ,<<*;
getch();
}
13B@&at -ou'5Hd be contents oC Co''o-in5 aCter array initia'iIationA 1
int 2J7KLM.#N #?O
2ns 3B
2
. N ? > >
17BSu55est stora5e c'ass Cor Co''o-in5 Pariab'es Q eac&
1. a norma' Pariab'e.
*. Pery &eaPi'y used Pariab'e.
.. a Pariab'e t&at s&ou'd retain its Pa'ue aCter Cunction is oPer.
3. a Pariab'e t&at spanes mu'tip'e Ci'es.
7. a Pariab'e 5'oba' in one + not aPai'ab'e in anot&er Ci'e.
2ns 7B
1. auto
*. re5ister
.. static
3. eEtern
7. static 5'oba'
1 9B DPointers a'-ays contain inte5ers D Comment. 1
2ns 9B
Pointer Pariab'e a'-ays store address oC a Pariab'e -&ic& is a'-ays an inte5er.
So pointers a'-ays store inte5ers.
6 7 6
Classes , O-.ects+ Constructor and %estructor+ Inheritance

1.1 @&at is t&e diCCerence bet-een t&e constructor and norma' CunctionA
2ns.
Constructor orma' 4unction
1. Constructor &as same name as c'ass name. 1. 2 norma' Cunction can &aPe any 'e5a' name but
not c'ass name.
*. Constructor can not &aPe any return type Pa'ue
not ePen Poid.
*. 2 Cunction s&ou'd &aPe any return type Pa'ue.
.. Constructor is automatica''y ca''ed. .. 2 Cunction is eEp'icit'y ca''ed.
3. Constructor can not be static. 3. 2 4unction can be static.
1.* @&at is t&e simi'arity bet-een c'ass and t&e constructorA (:OTS)R8ri5&t Student
2ns.: T&e on'y simi'arity bet-een constructor and is t&at constructor &as same name as c'ass name.
1.. 4ind t&e output oC t&e Co''o-in5 pro5ramA
#include<iostream.h>
#include<conio.h>
#include<string.h>
class state
{ char *statename;
int si-e;
ublic.
state(){si-e"#;statename"ne' char/si-e&%0;}
state (char *s)
{ si-e"strlen(s);statename"ne' char/si-e&%0;
strc*(statename,s);
}
void disla*()
{ cout<<statename<<endl;}
void relace(state1a, state 1b)
{si-e"a.si-e&b.si-e;
delete statename;
statename"ne' char/si-e&%0;
strc*(statename, a.statename);
strcat(statename,b.statename);
}
};
void main()
{ clrscr();
char *tem",2elhi,;
state state%(tem), state3(,4umbai,), state5(,6agur,), s%,s3;
s%.relace(state%,state3);
s3.relace(s%,state5);
s%.disla*();
s3.disla*();
getch();
}
2ns.: )e'&i%umbai
)e'&i%umbaia5pur
6 9 6
1.. 4ind out errors in t&e Co''o-in5 pro5ram:6
class number
{
int )"%#;
$loat *;
number(){ )"*"%#;}
ublic.
number(number t)
{
)"t.); *"t.*;
}
7 (){ cout<<,8b9ect destro*ed ,;}
}
main()
{
number a%, a3(a%);
}
2ns.: error: int EL1>S RR c'ass member can not be initia'iIed in t&e c'ass.
Constructor s&ou'd be dec'ared in pub'ic section oC c'ass.
ReCerence operator is missin5 in t&e deCinition oC copy constructor
In destructor c'ass name is missin5.
Semico'on is missed aCter t&e deCinition oC c'ass.
1.3 @&at is t&e diCCerence bet-een nestin5 or containers&ip and in&eritanceA EEp'ain -it& eEamp'eA
2ns.: Containers&ip or estin5: @&en a c'ass contains ob,ect oC ot&er c'ass type as its data member is 0no-n as
containers&ip or nestin5.
In&eritance: In&eritance is t&e process oC creatin5 ne- c'ass by reusin5 t&e properties oC an eEistin5 c'ass
by accessin5 t&em dependin5 on diCCerent Pisibi'ity mode. T&e ne- c'ass is ca''ed deriPed and eEistin5 c'ass is
ca''ed base c'ass.
1.7 @&at -i'' be t&e output oC t&e pro5ramA
#include<iostream.h>
class base
{ ublic.
void disla*()
{
cout<<,:t is a base class ,<<endl;
}
};
class derived. ublic base
{
ublic.
void disla*()
{ cout<<,:t is a derived class ,<<endl;}
};
main()
{
derived ob%;
ob%.disla*();
}
2ns:6 T&e output -i'' be:
It is a deri/ed class(
6 ; 6
1.9 )eCine a c'ass named Tour in C"" -it& Co''o-in5 descriptionA 3
PriPate members:
tcode inte5er (Ran5es 9 6 1>)
adu'ts# c&i'dren# distance inte5er
tota'Care C'oat
2ssi5n4are( ) 2 Cunction -&ic& ca'cu'ates and assi5n t&e Pa'ue to data member
tota'Care as Co''o-s:6
0 1or adults 4are )istance
Rs. 7>> BL17>>
2nd Care 5et reduced by *7T iC distance is U 17>>.
0 1or Children
4or ePery c&i'd a CiEed Rs. 7> is c&ar5ed as Care.
Pub'ic members:
2 constructor -&ic& initia'iIed initia'iIe a'' data members -it& >
4unction EnterTour() to input t&e Pa'ues oC t&e data members tcode# adu'ts# c&i'dren and ca'' to 2ssi5n4are
Cunction.
4unction S&o-Tour() to print a'' t&e detai's oC ob,ect oC TraPe' type.
Ans(
class tour
{
int tcode,adults,children,distance;
$loat total$are;
void assign$are()
{ $loat c$are";#, a$are"%;##;
i$(distance<%;##)
a$are"a$are<(a$are*3;=%##);
total$are"(children*c$are)&(adults*a$are);
}
ublic.
travel()
{ tcode"adults"children"distance"total$are"#; }
void entertour()
{
do
{ cout<<,>nter tcode bet'een ?<%# ,;
cin>>tcode;
i$ (tcode<? @@ tcode>%#)
cout<<,:nvalid tcode ,<<endl;
}'hile(tcode<? @@ tcode>%#);
cout<<,>nter children, adults, distance,;
cin>>children>>adults>>distance;
assign$are();
}
void sho'tour()
{ cout<<,tcode.,<<tcode<<endl;
cout<<,children.,<<children<<endl;
cout<<,adults .,<<adults<<endl;
cout<<,distance.,<<distance<<endl;
cout<<,total $are.,<<total$are<<endl;
}
};
6 N 6
1.;. )eCine a c'ass named 2dmission in C"" -it& Co''o-in5 descriptionA 3
Pri/ate mem-ers:
admno inte5er (Ran5es 1>617>>)
name strin5 oC *> c&aracters
c's inte5er
Cees C'oat
Pu-lic mem-ers:
2 constructor -&ic& initia'iIed admno -it& 1># name -it& D!//F# c's -it& > + Cees -it& >
4unction 5etdata() to read t&e ob,ect oC 2dmission type.
4unction putdata() to print t&e detai's oC ob,ect oC admission type.
4unction dra-Vnos() to 5enerate t&e admission no. random'y to matc& -it& admno and disp'ay t&e detai' oC
ob,ect.
Ans(2 class admission
{ int admno;
char name/3#0;
int cls;
$loat $ees;
ublic.
admission()
{ admno"%#;
strc*(name,,6ABB,);
cls"#;
$ees"#;
}
void getdata()
{
do
{ cout<<,>nter admno bet'een %#<%;## ,;
cin>>admn
i$ (admno<%# @@ admno>%;##)
cout<<,:nvalid admission no +,<<endl;
}'hile(admno<%# @@admno>%;##);
cout<<,>nter name ,;
gets(name);
cout<<,>nter class and $ees ,;
cin>>cls>>$ees;
}
void utdata()
{ cout<<,Cdmno .,<<admno<<endl;
cout<<,6ame .,<<name<<endl;
cout<<,Dlass .,<<cls<<endl;
cout<<,Eees .,<<$ees<<endl;
}
void dra'Fnos()
{ int num;
randomi-e();
num"random(%4G%)&%#;
i$ (num""admno)
utdata();
}
};
6 ? 6
1.N
Dlass testmeout
{ int rollno;
ublic.
7testmeout() ==Eunction %
{ cout<<rollno<<( is Beaving e)amination hall(<<endl;
}
testmeout() ==Eunction 3
{ rollno"%;
cout<<rollno<<( is aearing $or e)amination H<<endl;
}
testmeout(int n, char name/0) ==Eunction 5
{ rollno"n;
cout<<name<<( is in e)amination hall(<<endl;
}
testmeout(testmeout 1 t);==$unction 4
void m*'or!() ==Eunction ;
{ cout<<rollno<<( is attemting questions H<<endl;
}
};
i) In ob,ect oriented pro5rammin5# -&at is 4unction 1 reCerred as and -&en does it 5et inPo0edA
ii) In ob,ect oriented pro5rammin5# -&at is 4unction * reCerred as and -&en does it 5et inPo0edA
iii) In ob,ect oriented pro5rammin5# -&at is 4unction . reCerred as and -&en does it 5et inPo0edA
iP) @rite a statement so t&at Cunction . 5ets eEecutedA
Comp'ete t&e deCinition oC Cunction 3
P) @&at -i'' be t&e output oC t&e aboPe code iC its main Cunction deCinition is as 5iPen be'o- (assumed t&e
deCinition oC 4unction 3 is comp'eted ) :
main()
Mtestmeout ob1S
ob1.my-or0()S
O
Pi) @&ic& Ceature oC ob,ect oriented pro5rammin5 is demonstrated usin5 4unction *# 4unction . and 4unction 3
in t&e aboPe c'ass testmeoutA
Pii) @&at is t&e scope oC data member (ro''no) oC c'ass testmeoutA @&at does t&e scope oC data members depend
uponA
2ns:6
i) It is reCerred as destructor. It is automatica''y inPo0ed -&en an ob,ect oC concerned c'ass 5oes out oC scope.
ii) It is reCerred as constructor. It is automatica''y inPo0ed -&en an ob,ect oC concerned c'ass is dec'ared R
created.
iii) It is parameteriIed constructor and 5ets inPo0ed -&en an ob,ect oC concerned c'ass is created R dec'ared -it&
t&e matc&ed parameters.
iP) testmeout ob1(17# DVic0yF)S
testmeout (testmeout + t) M ro''noLt.ro''noSO
P) output -i'' be :
1 is appearin5 Cor eEamination
1 is attemptin5 Wuestions
1 is /eaPin5 eEamination &a''
Pi) It is constructor oPer'oadin5. It s&o-s Po'ymorp&ism Ceature oC t&e OOP.
Pii) T&e ro''no member oC ob,ect can on'y be used by t&e concerned ob,ect -&ere t&at ob,ect is dec'ared. Its
scope basica''y depends upon t&e concerned ob,ect.
6 1> 6
%ata Structure 3 Arra4+ link 5ist+ Stack , !ueue
1. 1 GiPen t-o arrays oC inte5ers 2 and 8 oC siIes % and respectiPe'y. @rite a Cunction named %IX() -&ic&
-i'' produce a t&ird array named C# suc& t&at t&e Co''o-in5 seWuence is Co''o-ed :
2'' ePen numbers oC 2 Crom 'eCt to ri5&t are copied into C Crom 'eCt to ri5&t.
2'' odd numbers oC 2 Crom 'eCt to ri5&t are copied into C Crom ri5&t to 'eCt
2'' ePen numbers oC 8 Crom 'eCt to ri5&t are copied into C Crom 'eCt to ri5&t.
2'' odd numbers oC 8 Crom 'eCt to ri5&t are copied into C Crom ri5&t to 'eCt
2# 8 and C are passed as ar5uments to %IX().
e.5. : 2 is M.#*#1#;#9#.O and 8 is M?#.#7#9#*#N#1>O# t&e resu'tant array C is M*#9#9#*#N#1>#7#.#?#.#;#1#.O
So'ution : Poid mi) (int C/0, int I/0, int n, int m)
{ int c/3#0,i"#,9"#,!"#,l;
B"m&n<%;
'hile (i<n 11 !<3#)
{ i$ (C/i0J3""#)
D/!&&0 " C/i&&0;
else D/l<<0 " C/i&&0;
}
Khile (9<m 11 !<3#)
{ i$ (I/90J3""#)
D/!&&0"I/9&&0;
else D/l<<0"I/9&&0;
}
cout<<( LnMhe elements o$ an arra* D is .(;
$or (i"#;i<m&n;i&&)
cout<<(Ln(<<D/i0;
}
void main()
{ int C/9" { 5,3,%,N,?,5}, I/0" {G,5,;,?,3,O,%#};
4i)(C,I,?,N);
}
1. *. Suppose an array P containin5 C'oat is arran5ed in ascendin5 order. @rite a user deCined Cunction in C""
to searc& Cor one C'oat Crom P -it& t&e &e'p oC binary searc& met&od. T&e Cunction s&ou'd return an inte5er > to
s&o- absence oC t&e number and inte5er 1 ti s&o- presence oC t&e number in t&e array. T&e Cunction s&ou'd &aPe
t&e parameters as (1) an array (*) t&e number )2T2 to be searc&ed (.) number oC e'ement .
So'ution : int bsearch ($loat P/%#0, $loat 2CMC, int 6)
{ int beg "#, end " 6<%,mid, os " <%;
'hile(beg<"end)
{ mid " ( beg& end )=3;
i$ (P/mid0 "" 2CMC)
{ os "mid &%;
Irea!;
}
else i$ (item > C>/mid0 )
beg " mid &%;
else
end " mid<%;
}
return ((os""<%)Q #.%);
}
6 11 6
1. . @rite a Cunction in C"" -&ic& accepts an inte5er array and its siIe as ar5uments R parameters and
assi5n t&e e'ements into a t-o dimensiona' array oC inte5ers in t&e Co''o-in5 Cormat :
IC t&e array is 1# *#.#3#7#9 IC t&e array is 1#*#.
T&e resu'tant *) array is 5iPen be'o- T&e resu'tant *) array is
1 * . 3 7 9 5iPen be'o-
1 * . 3 7 > 1 * .
1 * . 3 > > 1 * >
1 * . > > > 1 > >
1 * > > > >
1 > > > > >
So'ution :
void $unc(int arr/0, int si-e)
{ int a3/3#0/3#0, i, 9;
$or (i"#;i<si-e; i&&)
{ $or (9"#;9<si-e;9&&)
{ i$ ((i&9) >"si-e)
a3/i0/90"#;
else a3/i0/90" arr/90;
cout<<a3/i0/90<<( H;
}
Dout<<(Ln(;
}
}
163 @rite a Cunction in C"" to perCorm a P!S: operations on a dynamica''y a''ocated stac0 containin5 rea'
numberA
2ns6
struct 6ode
{
$loat data;
6ode * ne)t;
};
Roid ush (6ode*Mo, $loat num)
{
6ode*ntr " ne' 6ode;
ntr <> data " num;
ntr <> ne)t " 6ABB;
i$(Mo "" 6ABB)
Mo " ntr;
else
{
ntr <> ne)t " Mo;
Mo " ntr;
}
}
6 1* 6
167 Eac& node oC a ST2C( containin5 t&e Co''o-in5 inCormation# in addition to reWuired pointer Cie'd:
Ro'' no. oC t&e student
25e oC t&e student.
GPe t&e structure oC node Cor t&e 'in0ed stac0 in Wuestion.
TOP is a pointer to t&e topmost node oC t&e ST2C(. @rite t&e Co''o-in5 Cunction:
P!S:() $ TO pus& a node in to t&e stac0 -&ic& is a''ocated dynamica''y.
POP() $ Te remoPe a node Crom t&e stac0 and to re'ease t&e memory.
2ns6
struct SMCDT
{
int rollno, age;
SMCDT*ne)t;
} *to, *ntr, *tr;
void o()
{
i$ (+o) { cout << (LnAnder$lo'++( ; e)it(%); }
else
{ cout << ULnU << to <> rollno << ULtU << to <> age;
tr " to;
to " to <> ne)t;
delete tr;
}
}
Roid ush()
{
ntr " ne' stac!; ==allocate memor*
cout << HLn >nter roll number and age to be inserted . H ;
cin >> ntr<> rollno >> ntr<>age ;
ntr <> ne)t " 6ABB;
i$ (+to) to " ntr;
else
{
tr <> ne)t " to;
to " ntr
}
}
1.9 @rite a Cunction %2X in C"" -&ic& -i'' return t&e /ar5est number stored in a t-o dimensiona' array oC
Inte5ers.
2ns
#include <iostream.h>
#include <conio.h>
const r " %##, c " %##;
== Eunction to $ind the largest integer in a t'o<dimensional arra*
int 4CV(int a/r0/c0, int m, int n)
{
int ma) " #;
$or(int i" #;i<m;i&&)
$or(int 9" #;9<n;9&&)
{
6 1. 6
i$ (a/i0/90 >ma))
ma) " a/i0/90;
}
return ma);
}
void main()
{
clrscr();
int ar/r0/c0;
int rr, cc, m) " #;
int i, 9;
cout << ,>nter no. o$ ro' . ,;
cin >> rr;
cout << ,>nter no. o$ column . ,;
cin >> cc;
cout << ,>nter the arra* elements . ,;
$or (i"#; i<rr; i&&)
$or (9 " #; 9<cc; 9&&)
cin >> ar/i0/90;
m) " 4CV(ar, rr, cc);
cout << ,Bargest element is . , << ma);
}
1.; @rite a Cunction in c"" -&ic& accepts a *) array oC inte5ers and its siIe as ar5uments and disp'ays t&e
e'ements -&ic& 'ies on dia5ona's.
J 2ssumin5 t&e*) array to be a sWuare matriE -it& odd dimensions # i.e .E.# 7E7#;E;# etc K
EEamp'e iC t&e array content is
7 3 .
9 ; N
1 * ?
Output t&rou5& t&e Cunction s&ou'd be
)ia5ona' one : 7 ; ?
)ia5ona' t-o : . ; 1 .
2ns
RR 4unction to disp'ay t&e e'ements -&ic& 'ie on dia5ona's
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
const 4 " %#;
const 6 " %#;
void disla*Fdiagonals(int 4CMW:V/40/60, int r, int c)
{
clrscr();
== Einding the diagonal $rom le$t inde) to right
cout << ,2iagonal 8ne . ,;
$or(int i"#; i<r; i&&)
$or(int 9"#; 9<c; 9&&)
6 13 6
{
cout << 4CMW:V/i0/90 << , ,;
i&&;
}
cout << endl;
== Einding the diagonal $rom right inde) to le$t
cout << ,2iagonal M'o . ,;
$or(i"#; i<"r; i&&)
{
$or(int 9"c<%; 9>"#; 9<<)
{
cout << 4CMW:V/i0/90 << , ,;
i&&;
}
}
getch();
}
void main()
{
int 4CMW:V/40/60;
int i, 9;
int r, c;
cout << ,>nter total no. o$ ro's. ,;
cin >> r;
cout << ,>nter total no. o$ columns. ,;
cin >> c;
i$ ((r "" c) 11 ((rJ3""%) 11 (cJ3""%)))
{
cout << ,:nut stes,;
cout << ,LnL>nter the element in the arra*Ln,;
$or(i"#; i<r; i&&)
$or(9"#; 9<c; 9&&)
{
cin >> 4CMW:V/i0/90;
}
}
else
return;
disla*Fdiagonals(4CMW:V, r, c);
}
6 17 6
1.N @rite a Cunction in C"" -&ic& accepts a *) array oC inte5ers and its siIe as ar5uments and disp'ays t&e
e'ements oC t&e midd'e ro- and t&e e'ements oC midd'e co'umn.
EEamp'e iC t&e array content is
. 7 3
; 9 ?
* 1 N
Output t&rou5& t&e Cunction s&ou'd be:
%idd'e ro-: ;9? %idd'e co'umn: 7 9 1
Ans
== Eunction to disla* the elements 'hich lie on middle o$ ro' and column
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
const 4 " %#;
const 6 " %#;
void disla*FWo'Dol(int Crra*/40/60, int r, int c)
{ int ro' " r = 3;
int col " c = 3;
== Einding the middle ro'
cout << ,4iddle Wo' . ,;
$or(int 9"#; 9<c; 9&&)
cout << Crra*/ro'0/90 << , ,;
cout << endl;
== Einding the middle column
cout << ,4iddle Dolumn . ,;
$or(9"#; 9<c; 9&&)
cout << Crra*/90/col0 << , ,;
getch();
}
void main()
{ int Crra*/40/60;
int i, 9;
int r, c;
cout << ,>nter total no. o$ ro's. ,;
cin >> r;
cout << ,>nter total no. o$ columns. ,;
cin >> c;
i$ ((r "" c) 11 ((rJ3""%) 11 (cJ3""%)))
{ cout << ,:nut stes,;
cout << ,LnL>nter the element in the arra*Ln,;
$or(i"#; i<r; i&&)
$or(9"#; 9<c; 9&&)
{ cin >> Crra*/i0/90; }
}
else
{ cout << ,:nut ro' and column not valid,;
getch();
return;
}
disla*FWo'Dol(Crra*, r, c);
}
6 19 6
1. ?. )ec'are a stac0 usin5 array t&at contains int type numbers and deCine pop and pus& Cunction usin5 C""
SyntaE.
2ns
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ct*e.h>
#de$ine 4CV %## == Sho's ma)imum arra* length
int stac!/4CV0; == 2eclares arra* global variable
int to; == 2eclares integer to
== Eunction rotot*es o$ add stac!, delete stac!, and
== sho' stac! in arra* imlementation
void ush(int stac!/0, int val, int 1to); == Cdd stac!
int o(int stac!/0, int 1to); == 2elete stac!
void sho'FStac!(int stac!/0, int to); == Sho' stac!
void main()
{
int choice, val;
char ot " XYX; == Mo continue the do loo in case
to " <%; == :nitiali-ation o$ Zueue
clrscr();
do
{
cout << ,LnLtLt 4ain 4enu,;
cout << ,LnLt%. Cddition o$ Stac!,;
cout << ,LnLt3. 2eletion $rom Stac!,;
cout << ,LnLt5. Mraverse o$ Stac!,;
cout << ,LnLt4. >)it $rom 4enu,;
cout << ,LnLn>nter *our choice $rom above <> ,;
cin >> choice;
s'itch (choice)
{
case %.
do
{ cout << ,>nter the value to be added in the stac! ,;
cin >> val;
ush(stac!, val, to);
cout <<,Ln2o *ou 'ant to add more elements <Y=6> Q ,;
cin >> ot;
} 'hile (touer(ot) "" XYX);
brea!;
case 3.
ot " XYX; == :nitiali-e $or the second loo
do
{ val " o(stac!, to);
i$ (val +" <%)
cout << ,Ralue deleted $rom statc! is , << val;
cout <<,Ln2o *ou 'ant to delete more elements<Y=6>Q,;
cin >> ot;
} 'hile (touer(ot) "" XYX);
brea!;
6 1; 6
case 5.
sho'FStac!(stac!, to);
brea!;
case 4.
e)it(#);
}
}
'hile (choice +" 4);
}
== Eunction bod* $or add stac! 'ith arra*
void ush(int stac!/0, int val, int 1to)
{
i$ (to "" 4CV < %)
{ cout << ,Stac! Eull ,;
}
else
{ to " to & %;
stac!/to0 " val;
}
}
== Eunction bod* $or delete stac! 'ith arra*
int o(int stac!/0, int 1to)
{
int value;
i$ (to < #)
{ cout << ,Stac! >mt* ,;
value " <%;
}
else
{ value " stac!/to0;
to " to < %;
}
return (value);
}
== Eunction bod* $or sho' stac! 'ith arra*
void sho'FStac!(int stac!/0, int to)
{
int i;
i$ (to < #)
{ cout << ,Stac! >mt*,;
return;
}
i " to;
clrscr();
cout << ,Mhe values are ,;
do
{ cout << ,Ln, << stac!/i0;
i " i < %;
}'hile(i >" #);
}
1.1>. )eCine Cunctionstac0pus&( ) to insert nodes and stac0 pops ( ) to de'ete nodes . Cor a 'in0ed 'ist
imp'emented stac0 &aPin5 t&e Co''o-in5 structure Cor eac& node
6 1N 6
struct 6ode
{
Dhar name / 3# 0
:nt age ;
6ode * lin! ;
};
Dlass stuc! {
6ode * to ;
Public
Stac! ( ) { to " null ;} ;
Roid stac!ush ( );
Roid stac! o ( ) ;
}
2ns
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ct*e.h>
== 2eclares a stac! structure
struct node
{
char name/3#0;
int age;
node *lin!;
};
class stac!
{
node *to;
ublic .
stac!() { to " 6ABB; }
void stac!ush(); == Cdd stac!
void stac!o(); == 2elete stac!
void sho'FStac!(); == Sho' stac!
};
== Eunction bod* $or adds stac! elements
void stac!..stac!ush()
{
int val;
node *tem;
tem " ne' node;
cout << ,>nter name . ,;
gets(tem<>name);
cout << ,>nter age . ,;
cin >> tem<>age;
tem<>lin! " 6ABB;
i$(to ""6ABB)
to " tem;
else
{
tem<>lin! " to;
6 1? 6
to " tem;
}
}
== Eunction bod* $or delete stac! elements
void stac!..stac!o()
{
node *tem;
i$ (to "" 6ABB)
{
cout << ,Stac! >mt* ,;
}
else
{
tem " to;
to " to<>lin!;
tem<>lin! " 6ABB;
delete tem;
}
}
== Eunction bod* $or sho' stac! elements
void stac! .. sho'FStac!()
{
node *tem;
tem " to;
clrscr();
cout << ,Mhe values are Ln,;
'hile (tem +" 6ABB)
{
cout << ,Ln, << tem<>name << ,Lt, << tem<>age;
tem " tem<>lin!;
}
}
== 4ain rogramming logic
void main()
{
int choice;
stac! SMCDT;
char ot " XYX; == Mo continue the do loo in case
clrscr();
do
{
cout << ,LnLtLt 4ain 4enu,;
cout << ,LnLt%. Cddition o$ Stac!,;
cout << ,LnLt3. 2eletion $rom Stac!,;
cout << ,LnLt5. Mraverse o$ Stac!,;
cout << ,LnLt4. >)it $rom 4enu,;
cout << ,LnLn>nter *our choice $rom above ,;
cin >> choice;
s'itch (choice)
{
case %.
6 *> 6
do
{
SMCDT.stac!ush();
cout<<,2o *ou 'ant to add more elements<Y=6>Q,;
cin >> ot;
} 'hile (touer(ot) "" XYX);
brea!;
case 3.
ot " XYX; == :nitiali-e $or the second loo
do
{
SMCDT.stac!o();
cout<<,2o *ou 'ant to delete more element<Y=6>Q,;
cin >> ot;
} 'hile (touer(ot) "" XYX);
brea!;
case 5.
SMCDT.sho'FStac!();
brea!;
case 4.
e)it(#);
}
}
'hile (choice +" 4);
}
%ATA 1I5E HA#%5I#6
11# 2ssumin5 t&e c'ass Ve&ic'e as Co''o-s:
Dlass vehicle
6 *1 6
{ char vehiclet*e/%#0;
int noFo$ 'heels;
ublic.
void getdetials()
{ gets(vehiclet*e);
cin>>noFo$F'heels;
}
void sho'details()0
{ cout<<(Rehicle M*e(<<vehiclet*e;
cout<<(6umber o$ Kheels"(<<noFo$F'heels;
}
}
@rite a Cunction s&o-Ci'e() to read a'' t&e records present in an a'ready eEitin5 binary Ci'e SPEE).)2T and
disp'ay t&em on t&e screen #a'so count t&e number oC records present in t&e Ci'e.
Ans7er2
Roid sho'$ile()
{ i$stream $in;
$in.oen(HSP>>2.2CM(,ios..in@ios..binar*);
vehicle v%;
int count"#;
'hile (+$in.eo$())
{ $in.read((char *)1v%,si-eo$(v%));
count&&;
v%.sho'details();
}
cout<<(Motal number o$ records are H<<count;
}
1*. @rite a pro5ram t&at prints a teEt Ci'e on t&e printer.
Ans7er20
#include<iostream.h>
#include<$stream.h>
#include<rocess.h>
int main()
{ char $ilename/%50, ch;
cout<<(enter the te)t $ile name .(;
cin.getline($ilename,%5);
i$stream $in;
$in.oen($ilename);
i$(+$in)
{cerr<<(LnEile canUt be oened +Ln(;
e)it(<%);
}
o$stream $out;
$out.oen(HPW6();
'hile($in.get(ch)+"#)
$out.ut(ch);
return #;
}
1.. @rite a c"" pro5ram #-&ic& initia'iIes a strin5 Pariab'e to t&e content.FTime is a 5rat teac&er but
unCortunate'y it 0i''s a'' its pupi's.8er'ioIFand output t&e strin5 one c&aracter at a time to t&e dis0 Ci'e
O!T.TXT .You &aPe to inc'ude a'' t&e &eader Ci'es reWuired.
6 ** 6
2ns-er:
#include<$stream.h>
:nt main()
{
o$stream $out(H8AM.MVM();
Dhar*str"( Mime is a grat teacher but un$ortunatel* it !ills all its
uils.Ierlio-(;
:nt i"#;
:$(+$out)
{
cout<<(Eile cannot be oened H;
return #;
}
Khile (str/i0+"UL#U)
{
$out<<str/i0;
i&&;
}
$out.close();
}
13. @rite a pro5ram t&at disp'ay t&e siIe oC a Ci'e in bytes.
2ns-er:
#include<iostream.h>
#include<$stream.h>
#include<rocess.h>
#include<conio.h>
int main()
{
char $ilename/%50;
clrscr();
cout<(>nter Eilename.Ln(;
cin.getline($ilename,%5);
i$stream in$ile($ilename);
i$(+in$ile)
{
cout>>(sorr* + Dan not oen H<<$ilename <<($ileLn(;
>)it(<%);
}
int noFb*tes"#;
char ch;
'hile(cin.get(ch))
{
noFb*tes &&;
}
cout<<(Eile Si-e is(<<noFb*tes<<(b*tesLn(;
return #;
}
17. @&at -i'' be t&e output produced by t&e Co''o-in5 codeA
2ns-er:
#include<iostream.h>
6 *. 6
#include<$stream.h>
#include<rocess.h>
#include<conio.h>
int main()
{
clrscr()
char $ilename/%50;
cout<<(>nter Eilename.(;
cin.getline($ilename,%5);
i$stream in($ilename);
i$(+in)
{cout<<(Dannot oen inut $ile+Ln(;
return (#)
}
Dhar str/3;;0;
Khile(in)
{in.getline(str,3;;);
Dout<<str<<(Ln(;
}
in.close();
return #;
}
%ATA $ASE CO#CEPT
6 *3 6
!('( What is 8oreign 9e4& What is its purpose&
2ns: 2 non 0ey attribute# -&ose Pa'ue are deriPed Crom t&e primary 0ey oC some ot&er tab'e# is 0no-n as
Corei5n 0ey in t&e current tab'e.
T&e tab'e in -&ic& t&is non60ey attribute i.e. Corei5n 0ey attribute eEists# is ca''ed a Corei5n tab'e.
!(:( %e8ine the terms Tuple and Attri-ute
2ns: Tup'es: T&e ro-s oC tab'es (re'ations) are 5enera''y reCerred to as tup'es.
2ttribute: T&e co'umns oC tab'es are 5enera''y reCerred to as attribute.
!(;( What do 4ou understand -4 the terms Cardinalit4 and %egree o8 the ta-le&
2ns )e5ree: T&e number oC attributes in a re'ation determines t&e de5ree oC a re'ation. 2 re'ation
&aPin5 . attributes is said to be a re'ation oC de5ree ..
Cardina'ity: T&e number oC ro-s in a re'ation is 0no-n as Cardina'ity.
!(<( What is the main 8unction o8 %$A(
2ns: T&e )82 must be a mana5er# more t&an a tec&nician6see0in5 to meet t&e needs oC peop'e -&o use t&e
data. Since many user may s&are t&e same data resource# t&e )82 must be prepared to meet t&e need and
ob,ectiPe.
!(=( Write a >uer4 on the customers ta-le 7hose output 7ill e?clude all customers 7ith a rating @A'BB+
unless the4 are located in Shimla(
2ns. SE/ECT Z 4RO% customers @:ERE ratin5 B1>> OR city L=S&im'a= S
!(C( Write a >uer4 that selects all orders e?cept those Deros or #"55s in the amount 8ield(
2ns. SE/ECT Z 4RO% Orders @:ERE amt U B> 2) (amt IS OT !//) S
1.;. @rite a Wuery t&at 'ists customers in descendin5 order oC ratin5.
Output t&e ratin5 Cie'd Cirst# Co''o-ed by t&e customer=s name and number.
2ns. SE/ECT ratin5# cust6name# cust6num 4RO% customers OR)ER 8Y ratin5 )ESC S
!(E( Write a command that puts the 8ollo7ing /alues+ in their gi/en order+ into the salesman ta-le2
cust0name0Fanisha+ cit40Fanali+ comm(0 #"55+ cust0num0'GB'(
2ns. ISERT ITO sa'esman (city# cust6name# comm.#cust6num)
V2/!ES([%anis&a=#!//#1?>1) S
!(G( What are %%5 and %F5&
2ns:6 T&e ))/ proPides statements Cor t&e creation and de'etion oC tab'es and indeEes.
T&e )%/ proPides statements to enter# update# de'ete data and perCorm comp'eE Wueries on t&ese tab'es.
!('B( What is the di88erence -et7een Where and Ha/ing Clause &
2ns: T&e :2VIG c'ause p'aces t&e condition on 5roup but @:ERE c'ause p'aces t&e condition on
indiPidua' ro-s
!(''( What do 4ou understand -4 constraints &
2ns: Constraints are used to enCorce ru'es at tab'e 'ePe' -&en ePer ro- is inserted# updatedRde'eted Crom tab'e.
Constraints can be deCined to one oC t&e T-o 'ePe'.
Co'umn /ePe': ReCerence to a sin5'e co'umn. can be deCined any type oC inte5rity.
Tab'e /ePe': ReCerences one or more co'umns and is deCined separate'y Crom deCinition oC t&e co'umns in t&e
tab'e.
6 *7 6
!(':( Write some 8eatures o8 S!5&
2ns: RecoPery ad Concurrency:6 Concurrency is concerned -it& t&e manner in -&ic& mu'tip'e user operate
upon t&e )atabase.
Security: T&e Security can be maintained by Pie- mec&anism.
Inte5rity Constraints6B Inte5rity constraints are enCorced by t&e system.
!(';( Write /arious data-ase o-.ects a/aila-le in S!5&
2ns: Tab'e: 2 Tab'e is used to store )ata
Vie-: 2 Pie- is t&e temporary tab'e created usin5 Ori5ina' tab'e.
SeWuence: SeWuences are used to 5enerate Primary 0ey Pa'ue.
IndeE: T&ey are used to improPe Wueries.
Synonym: T&ey 5iPe a'ternatiPe names to ob,ects.
!('<( Write the rules to name an o-.ects&
2ns :
T&e maEimum 'en5t& must be .> c&aracter 'on5.
T&e Ob,ect name s&ou'd not contain Wuotation mar0.
T&e name must start -it& 'etter.
T&e use oC \ and ] is discoura5ed in t&e ob,ect name.
2 name must not be a reserPed name.
!('=( What are group 1unctions
2ns: T&e a55re5ate Cunctions are 5roup Cunctions. T&ey return resu't based on 5roups oC ro-s. T&e 5roup
Cunctions are
2VG()# CO!T()# %2X()# %I ()# S!%()
!('C( What are column alias&
2ns: In many cases &eadin5 tab'e may not be descriptiPe and &ence it diCCicu't to understand. In suc& case
-e use co'umns a'ias It -i'' c&an5e co'umn &eadin5 -it& co'umn a'ias.
6 *9 6
1.1;. @rite t&e S1/ Wuery commands based on Co''o-in5 tab'e
Table : Book
$ookHid $ook name AuthorHname Pu-lisher Price T4pe !uantit4
C>>>1 4ast Coo0 /ata (apoor EP8 .77 Coo0ery 7
4>>>1 T&e Tears
@i''iam
:op0ins 4irst Pub'i. 97> 4iction *>
T>>>1 %y 4irst c""
8rain +
8roo0e 4P8 .7> TeEt 1>
T>>>*
C"" 8rain
-or0s 2.@. Rossaine T): .7> TeEt 17
4>>>* T&underbo'ts 2nna Roberts 4irst Pub'. ;7> 4iction 7>
Table : issued
$ookHId !uantit4 Issued
TBBB' <
CBBB' =
1BBB' :
@rite S1/ Wuery Cor (a) to (C)
(a) To s&o- boo0 name# 2ut&or name and price oC boo0s oC 4irst Pub. Pub'is&er
(b) To 'ist t&e names Crom boo0s oC teEt type
(c) To )isp'ay t&e names and price Crom boo0s in ascendin5 order oC t&eir prices.
(d) To increase t&e price oC a'' boo0s oC EP8 pub'is&ers by 7>.
(e) To disp'ay t&e 8oo0VId# 8oo0Vname and Wuantity issued Cor a'' boo0s -&ic& &aPe been issued
(C) To insert a ne- ro- in t&e tab'e issued &aPin5 t&e Co''o-in5 data. [4>>>.=# 1
(5) GiPe t&e output oC t&e Co''o-in5
i. Se'ect Count(Z) Crom 8oo0s
ii. Se'ect %aE(Price) Crom boo0s -&ere Wuantity BL17
iii. Se'ect boo0Vname# aut&orVname Crom boo0s -&ere pub'is&ersL=Cirst pub'.=
iP. Se'ect count(distinct pub'is&ers) Crom boo0s -&ere PriceBL3>>
Ans2
(a) Se'ect boo0Vname# aut&orVname # price Crom boo0s -&ere pub'is&erL=4irst Pub'=
(b) Se'ect boo0Vname Crom boo0s -&ere typeL=TeEt=
(c) Se'ect boo0Vname# price Crom boo0s Order by PriceS
(d) !pdate boo0s set priceLprice"7> -&ere pub'is&ersL=EP8=
(e) Se'ect a.boo0Vid#a.boo0Vname#b.WuantityVissued Crom boo0s a# issued b -&ere
a.boo0VidLb.boo0Vid
(C) Insert into issued Va'ues ([4>>>.=#1)S
(5)
i. 7
ii. ;7>
iii. 4ast Coo0 /ata (appor
%y 4irst c"" 8rain + 8roo0e
iP. 1
6 *; 6
!('E(
TABLE: GRADUATE
S(#O #AFE STIPE#% S"$IECT A)ERA6E %I)(
1 (2R2 3>> P:YSICS 9N I
* )I@2(2R 37> CO%P. Sc. 9N I
. )IVY2 .>> C:E%ISTRY 9* I
3 RE(:2 .7> P:YSICS 9. I
7 2R<! 7>> %2T:S ;> I
9 S28I2 3>> CE:%ISTRY 77 II
; <O: *7> P:YSICS 93 I
N RO8ERT 37> %2T:S 9N I
? R!8I2 7>> CO%P. Sc. 9* I
1> VI(2S 3>> %2T:S 7; II
(a) /ist t&e names oC t&ose students -&o &aPe obtained %I) I sorted by 2%E.
(b) )isp'ay a report# 'istin5 2%E# STIPE)# S!8<ECT and amount oC stipend receiPed in a year
assumin5 t&at t&e STIPE) is paid ePery mont&.
(c.) To count t&e number oC students -&o are eit&er P:YSICS or CO%P!TER SC 5raduates.
(d) To insert a ne- ro- in t&e GR2)!2TE tab'e:
11#F(2<O/F# .>># DCO%P. SC.F# ;7# 1
(e) GiPe t&e output oC Co''o-in5 sW' statement based on tab'e GR2)!2TE:
(i) Se'ect %I(2VER2GE) Crom GR2)!2TE -&ere S!8<ECTLFP:YSICSFS
(ii) Se'ect S!%(STIPE)) Crom GR2)!2TE @:ERE diPL*S
(iii) Se'ect 2VG(STIPE)) Crom GR2)!2TE -&ere 2VER2GEBL97S
(iP) Se'ect CO!T(distinct S!8)<ECT) Crom GR2)!2TES
2ssume t&at t&ere is one more tab'e G!I)E in t&e database as s&o-n be'o-:
Ta-le2 6"I%E

(C) @&at -i'' be t&e output oC t&e Co''o-in5 Wuery:
SE/ECT 2%E# 2)VISOR 4RO% GR2)!2TE#G!I)E @:ERE S!8<ECTL %2I2RE2S
2ns:
(a) SE/ECT 2%E 4RO% GR2)!2TE @:ERE )IVL^I^ OR)ER 8Y 2%ES
(b) SE/ECT 2%E# STIPE)# S!8<ECT# STIPE)Z1* STIPE)VYE2R 4RO% GR2)!2TES
(c) SE/ECT S!8<ECT# CO!T(2%E) 4RO% GR2)!2TE GRO!P8Y (S!8<ECT) :2VIG
S!8<ECTL^P:YSICS^ OR S!8<ECTL^CO%P. Sc.^S
(d) ISERT ITO GR2)!2TE V2/!ES(11#^(2<O/^#.>>#^CO%P. Sc.^#;7#1)S
(e) (i) %I(2VER2GE) 9.
(ii) S!%(STIPE)) N>>
(iii) 2VG(STIPE)) 3*>
(iP) CO!T()ISTICTS!8<ECT) 3
(C) SE/ECT 2%E# 2)VISOR 4RO% GR2)!2TE# G!I)E @:ERE S!8<ECTL%2I2RE2S
#AFE A%)ISOR
)IVY2 R2<2
S28I2 R2<2
(2R2 VIO)
RE(:2 VIO)
<O: VIO)
6 *N 6
FAI#AREA A%)ISOR
P:YSICS VIO)
CO%P!TER SC 2/O(
C:E%ISTRY R2<2
%2T:E%2TICS %2:ES:
!('G( Ta-le2 Emplo4ees
Empid 1irstname 5astname Address Cit4
>1> RaPi (umar Ra, na5ar G_8
1>7 :arry @a'tor Gand&i na5ar G_8
17* Sam Tones .. E'm St. Paris
*17 Sara& 2c0erman 33> !.S. 11> !pton
*33 %ani'a Sen5upta *34riends street e- )e'&i
.>> Robert Samue' ? 4iCt& Cross @as&in5ton
..7 Ritu Tondon S&astri a5ar G_8
3>> Rac&e' /ee 1*1 :arrison St. e- Yor0
331 Peter T&ompson 11 Red Road Paris
Ta-le2 EmpSalar4
Empid Salar4 $ene8its %esignation
>1> ;7>>> 17>>> %ana5er
1>7 97>>> 17>>> %ana5er
17* N>>>> *7>>> )irector
*17 ;7>>> 1*7>> %ana5er
*33 7>>>> 1*>>> C'er0
.>> 37>>> 1>>>> C'er0
..7 3>>>> 1>>>> C'er0
3>> .*>>> ;7>> Sa'esman
331 *N>>> ;7>> sa'esman
@rite t&e S1/ commands Cor t&e Co''o-in5 :
(i) To s&o- Cirstname#'astname#address and city oC a'' emp'oyees 'iPin5 in paris
(ii) To disp'ay t&e content oC Emp'oyees tab'e in descendin5 order oC 4irstname.
(iii) To disp'ay t&e Cirstname#'astname and tota' sa'ary oC a'' mana5ers Crom t&e tab'es Emp'oyee and
empsa'ary # -&ere tota' sa'ary is ca'cu'ated as sa'ary"beneCits.
(iP) To disp'ay t&e maEimum sa'ary amon5 mana5ers and c'er0s Crom t&e tab'e Empsa'ary.
(/ 6i/e the Output o8 8ollo7ing S!5 commands2
(i) Se'ect Cirstname#sa'ary Crom emp'oyees #empsa'ary -&ere desi5nation L [Sa'esman= and
Emp'oyees.empidLEmpsa'ary.empidS
(ii) Se'ect count(distinct desi5nation) Crom empsa'aryS
(iii) Se'ect desi5nation# sum(sa'ary) Crom empsa'ary 5roup by desi5nation &aPin5 count(Z) B*S
(iP) Se'ect sum(beneCits) Crom empsa'ary -&ere desi5nation L=C'er0=S
2ns: (i) se'ect Cirstname# 'astname# address# city Crom emp'oyees -&ere cityL^Paris^S
(ii) se'ect Z Crom emp'oyees order by Cirstname descS
(iii) se'ect emp'oyees.Cirstname# emp'oyees.'astname# empsa'ary.sa'ary " empsa'ary.beneCits tota'Vsa'ary Crom
emp'oyees# empsa'ary -&ere emp'oyees.empidLempsa'ary.empid and desi5nationL^%ana5er^S
(iP) se'ect maE(sa'ary) Crom empsa'ary -&ere desi5nation in(^%ana5er^#^C'er0^)
(P) (i) se'ect Cirstname# sa'ary Crom emp'oyees# empsa'ary -&ere desi5nationL^Sa'esman^ and
emp'oyees.empidLempsa'ary.empid
4IRST2%E S2/2RY
Rac&e' .*>>>
Peter *N>>>
(ii)se'ect count(distinct desi5nation) Crom empsa'aryS
CO!T()ISTICT)ESIG2TIO)
3
(iii)se'ect desi5nation# sum(sa'ary) Crom empsa'ary 5roup by desi5nation &aPin5 count(Z)B*S
)ESIG2TIO S!%(S2/2RY)
C'er0 1.7>>>
%ana5er *17>>>
(iP)se'ect sum(beneCits) Crom empsa'ary -&ere desi5nationL^C'er0^S
S!%(8EE4ITS)
.*>>>
6 *? 6
$oolean Alge-ra
'( Pro/e that X((X*JAX -4 alge-raic method(
So'ution:
/.:.S.L X.(X"Y)LX .X " X .Y
L X " X .Y
L X .(1"Y)
LX . 1 L X L R.:.S
:( 6i/e duals 8or the 8ollo7ing 2
a A* K$
- A$*K$
So'ution:
a) 2. (` "8) b) (2 " 8). (` " 8)
;( State and /eri84 In/olution la7(
So'ution:
InPo'ution /a- states : ` L 2
Trut& Tab'e:

<( State and /eri84 %ualit4 principle(
So'ution:
Princip'e oC dua'ity states t&at Crom ePery boo'ean re'ation# anot&er boo'ean rea'ation can be deriPed by
(i) c&an5in5 eac& OR si5n(") to an 2) si5n(6).
(ii) c&an5in5 eac& 2) si5n(6) to an OR si5n(")
(iii) rep'acin5 eac& 1 by > and eac& > by 1.
T&e ne- deriPed re'ation is 0no-n as t&e dua' oC t&e ori5ina' re'ation.
)ua' oC 2" `8 -i'' be
2" `8 L 2. (` "8).
=( State and /eri84 A-sorption la7 in -oolean alge-ra.
So'ution: 2bsorption 'a- states:
(i) X " XYL X (ii) X ( X " Y) L X
Input Output
X Y X " XY
>
1
1
1
>
1
>
1
>
>
1
1
6 .> 6
2 `
`
>
1
1
>
>
1
C( %ra7 logic circuit diagram 8or the 8ollo7ing e?pression2
JA A$*$C*CK
So'ution:
a
b
Y
c
L( State t&e distributiPe 'a-s oC boo'ean a'5ebra.
So'n: )istributiPe 'a-s states:
(i) X(Y"_)LXY"X_
(ii) X"Y_L(X"Y)(X"_)
E( Reduce the 8ollo7ing $oolean e?pression using 90Fap2
4(P#1#R#S)La(>#.#7#9#;#11#1*#17)
So'n: R=S= R=S RS RS=
P=1=
P=1
P1
P1=
T&is is 1 Wuad# *airs + * 'oc0
1uad(m."m;"m17"m11) reduces to RS
Pair(m7"m;) reduces to P=1S
Pair (m;"m9) reduces to P=1R
8'oc0 m>LP=1=R=S=
%1*LP1R=S=
&ence t&e Cina' eEpressions is 4LRS " P=1S " P=1R " P1R=S= " P=1=R=S=
G( Reduce the 8ollo7ing $oolean e?pression using 90Fap2
4(2#8#C#))Lb(>#1#.#7#9#;#1>#13#17)
6 .1 6
1
> 1
1
. *
3
1
7
1
;
1
9
1
1* 1.
1
17 13
N ?
1
11 1>
2)
2)
2)
So'n:
Reduced eEpressions are as Co''o-s:
4or pair 1# (2"8"C)
4or pair *# (2="C="))
4or 1uad 1# (2")=)
4or 1uad *# (8="C=)
:ence Cina' POS eEpression -i'' be
Y(2#8#C#))L (2"8"C) (2"C")) (2")) (8"C)
Communication and #et7ork Concepts
!(' @&at is protoco'A :o- many types oC protoco's are t&ereA
Ans( @&en computers communicate eac& ot&er# t&ere needs to be a common set oC ru'es and instructions t&at
eac& computer Co''o-s. 2 speciCic set oC communication ru'es is ca''ed a protoco'.
Some protoco': PPP# :TTP# S/IP# 4TP# TCPRIP
!(: @&at is t&e diCCerence bet-een et-or0in5 and Remote et-or0in5A
Ans( T&e main diCCerence bet-een et-or0in5 and Remote et-or0in5# is t&e net-or0 -&ic& -e use in oCCices
or ot&er p'aces 'oca''y suc& /2 or ITERET and remote net-or0in5 is one -&ic& -e use TER%I2/
SerPices to communicate -it& t&e remote users suc& @2.
!(; @&at is point6to6point protoco'A
6 .* 6
> > >
> > >
> >
>
Ans. 2 communication protoco' used to connect computer to remote net-or0in5 serPices inc'ude Internet
SerPice ProPiders. In net-or0in5# t&e Point6to6Point protoco' is common'y used to estab'is& a direct connection
bet-een t-o nodes. Its primary use &as been to connect computers usin5 a p&one 'ine.
!(< :o- 5ate-ay is diCCerent Crom routerA
Ans. 2 5ate-ay operates at t&e upper 'ePe's oC t&e OSI mode' and trans'ates inCormation bet-een t-o
comp'ete'y diCCerent net-or0 arc&itectures. Routers a''o- diCCerent net-or0s to communicate -it& eac& ot&er.
T&ey Cor-ard pac0ets Crom one net-or0 to anot&er based on net-or0 'ayer inCormation. 2 5ate-ay can interpret
and trans'ate t&e diCCerent protoco's t&at are used on t-o distinct net-or0s. !n'i0e routers t&at successCu''y
connect net-or0s -it& protoco's t&at are simi'ar# a 5ate-ay perCorm an app'ication 'ayer conPersion oC
inCormation Crom one protoco' stac0 to anot&er.
!(= @&at is t&e ro'e oC net-or0 administratorA
Ans. 8asic tas0s Cor -&ic& a net-or0 administrator may be responsib'e:
Settin5 up and conCi5urin5 net-or0 &ard-are and soCt-are.
Insta''in5 and conCi5urin5 net-or0 media and connections.
Connectin5 user nodes and perip&era's oC a'' 0inds to t&e net-or0.
2ddin5 users to and remoPin5 users Crom t&e net-or0.
%ana5in5 user account.
Ensurin5 t&e security oC t&e net-or0.
ProPide trainin5 to t&e users to uti'iIe t&e net-or0=s resources.
!(C @&at is t&e diCCerence bet-een baseband and broadband transmissionA
Ans( 8aseband is a bi6directiona' transmission -&i'e broadband is a unidirectiona' transmission.
o 4reWuency diPision mu'tip'eEin5 possib'e in base band but possib'e in broadband.
So 8aseband 8roadband
1 Entire band-idt& oC t&e cab'e is consumed
by a si5na'
broadband transmission# si5na's are sent on mu'tip'e
CreWuencies# a''o-in5 mu'tip'e si5na's to be sent
simu'taneous'y.
* )i5ita' si5na's 2na'o5 si5na's
. bi6directiona' transmission unidirectiona' transmission
3 o 4reWuency diPision mu'tip'eEin5
possib'e
4reWuency diPision mu'tip'eEin5 possib'e
7 !ses Cor s&ort distance !ses Cor 'on5 distance
!(; What are the di88erence -et7een domain and 7orkgroup&
Ans(
So )omain @or05roup
1. One or more computers are serPers 2'' Computers are peers.
*. IC you &aPe a user account on t&e domain# you
can 'o5on to any computer on t&e domain.
Eac& computer &as a set oC accounts.
.. T&ere can be 1>>" computers Typica''y not more t&en *>6.> computers
3. T&e computers can be on diCCerent 'oca' net-or0 2'' computers must be on t&e same 'oca' netor0.
!(E @&at is the di88erences -et7een POP; and IFAP Fail Ser/er&
Ans( I%2P is a standard protoco' Cor accessin5 e6mai' Crom a 'oca' serPer. 2 simp'er e6mai' protoco' is Post
OCCice Protoco' . (POP.)# -&ic& do-n'oad mai' to t&e computer and does not maintain t&e mai' on t&e serPer.
6 .. 6
I%2P# e6mai's are stored on t&e serPer# -&i'e in POP.# t&e messa5es are transCerred to t&e c'ient=s computer
-&en t&ey are read.
!('B ame diCCerent 'ayer oC t&e ISO OSI %ode'.
Ans( Internationa' Standard Orr5anisation $ Open Systems Interconnection &as sePen 'ayersS
P&ysica' /ayer
)ata /in0 /ayer
et-or0 /ayer
Transport /ayer
Session /ayer
Presentation /ayer
2pp'ication /ayer
!('' @&at is c'ient serPer arc&itectureA
Ans( To desi5nated a particu'ar node -&ic& is -e'' 0no-n and CiEed address# to proPide a serPice to t&e net-or0
as a -&o'e. T&e node proPidin5 t&e serPice is 0no-n as t&e serPer and t&e nodes t&at use t&at serPices are ca''ed
c'ients oC t&at serPer. T&is type oC net-or0 is ca''ed C'ient6SerPer 2rc&itecture.
!(': @&at is 4)%A GiPe eEamp'e.
Ans( 4)%64reWuency )iPision %u'tip'eEin5 is used in ana'o5 transmission. It is oCten used in s&ort distance. It
is code transparent and any termina' oC t&e same speed can use t&e same sub6c&anne' aCter t&e sub6c&anne' is
estab'is&ed. T&e best eEamp'e iC 4)% is t&e -ay -e receiPe Parious stations in a radio.
!('; describe t&e Co''o-in5 in brieC:
i) %OS2IC ii) !SEET iii) @2IS
Ans( i) %OS2IC: is t&e pro5ram Cor cruisin5 t&e internet. T&e ationa' centre -rote t&is pro5ram Cor Super
Computer app'ication at t&e uniPersity oC I''inois. It &as a simp'e -indo- interCace# -&ic& creates useCu'
&yperteEt 'in0s t&at automatica''y perCorm some oC t&e menu bar and button Cunctions.
ii) !SEET: is t&e -ay to meet peop'e and s&are inCormation. !senet ne-s5roup is a specia' 5roup set up by
peop'e -&o -ant to s&are common interests ran5in5 Crom current topic to cu'tura' &erita5es.
iii) @2IS: is a @I)E 2RE2 I4OR%2TIO SERVER.
6 .3 6

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