Board Notes: Computer Science
Board Notes: Computer Science
Board Notes: Computer Science
Class XIIth
Computer Science
S.No.
1 Review of C++ 1
2 Objected Oriented Programming in C++ 16
3 Arrays 27
4 Linked list, Stacks, Queues 33
5 Data File Handling 46
6&7 Database and SQL 57
8 Boolean Algebra 80
9 Networking 86
Vidyamandir Classes
15. How does OOPs overcome the shortcomings of traditional programming approaches?
Sol. The traditional programming approaches emphasize more on doing things. The algorithm for the solution plays a key
role here. The data is not given as much concern as required. Data is after all, the reason for a program’s existence.
Another problem associated with traditional programming languages is that they do no model the real world very
well.
The OOPs concept overcomes these short comings by (i) the method of reusing the code through inheritance
(ii) giving data the prime consideration and (iii) modelling the real world entities classes and objects. It is the data
(and associated functions) that is the key factor while declaring classes. And the real world behavior is reflected
through objects and their properties.
28. Differentiable between a Logical Error and Syntax Error? Also give suitable examples of each in C++.
Sol. Logical Error is an error which occurs because of wrong interpretation of logic. With logical error(s), the code is
syntactically correct but does something undesired. For example, if in place of c = a + b; if by mistake, c = a * b ; is
written, it will be logical error.
A syntax error is the error that occurs when statements are wrongly written violating rules of the programming
language. For example, MAX + 2 = DMAX is a syntax error as an expression cannot appear on the left side of an
assignment operator.
29. What is the difference between Actual Parameter and Formal Parameter? Also, give a suitable C++ code to illustrate
both.
Sol. Actual Parameter is a parameter, which is used in function call statement to send the value from calling function to
the called function.
Formal Parameter is a parameter, which is used in function header of the called function to receive the value form
actual parameter.
For example,
void Multiply(int T) //T is formal parameter
{
cout<< 5*t;
}
int main()
{
int A = 45;
Multiply(A); //A is actual parameter sent to Multiply()
return 0;
}
30. What is the difference between call by value and call by reference in a user defined function in C++? Give an
example to illustrate the same.
Or
What is the difference between call by value and call by reference? Also, given a suitable C++ code to illustrate both.
Or
What is the difference between call by value and call by reference? Given an example in C++ to illustrate both.
Sol. In call by value method, the called function creates its own copies of the original values sent to it. Any changes, that
are made, occur on the called function’s copy of values and are not reflected back to the calling function.
In call by reference method, the called function accesses and works with the original values using their references.
Any changes, that occur, take place on the original values and are reflected back to the calling code.
Example of call by value
int main()
{ int a = 5;
cout << "a = " <<a;
change(a);
cout<<"\n a=" <<a;
return 0;
}
void change (int b)
{ b=10;
}
Output will be :
a=5
a=5
Example of call by reference
int main()
{
int a = 5;
cout<<"a= " <<a;
change (a);
cout<< "\n a = " << a;
return 0;
}
void change (int & b)
{ b = 10;
}
Output will be :
a=5
a = 10
31. What is the purpose of using a typedef command in C++? Explain with suitable example.
Sol. A typedef command defines a new name or an alias name or an alias name for an existing type. For example, all
transactions generally involved amounts which are of (say) double type. So, for a bank application, we can safely
provide an alias name as Amount to the predefined double type. For this, we shall write :
typedef double Amount ;
Now we can define any amount using the datatype Amount as :
Amount loan, balance, instalment, interest ;
32. What do you understand by default arguments and constant arguments? Write a short note on their usefulness.
Sol. The default argument is a way to specify predefined/default value to an argument in case it is not provided in the
function call statement.
The const argument is a way to ensure that the argument declared as const cannot be altered in the function body. For
example,
int F1(int time const, float prin=6000);
With above prototype, function calls like this:
int t = 5 ;
int r = F1(t);
will consider the default value 6000 for second argument as it is missing in the function call statement further first
argument cannot be modified in F1() i.e.,
int F1 (int time const, float prin = 6000)
{ time = 10; // NOT ALLOWED
…….
}
33. Define a macro. How is it different from a constant defined through const ?
Sol. A macro refers, to #define definition that is used to define words to enhance readability and understandability. Before
compilation the preprocessor replaces every occurrence of macro as per the definition e.g.,
#define EOF 0
will replace every occurrence of EOF with 0 within program.
A macro is a preprocessor directive and is text–replaced during compilation whereas a const is a type identifier
having constant value. Other major differences between a macro and const are :
(i) A const object is subject to scoping rules for variables whereas a #define is not.
(ii) The compiler does not type–check a macro whereas a const is definitely type-checked.
34. Which of the following are correctly formed #define statements?
(i) #define INCH PER FEET 12
(ii) #define DOUBLE (X) (2*X)
(iii) #define DOUBLE(X) 2*X
(iv) #define DOUBLE(X) (2*X)
Name the macros that get defined through above statements.
Sol. All of the above statements are syntactically correct but they may pose following errors :
(i) It will define a macro INCH with value to be substituted as PER FEET 12, which may result into errors in
expressions.
(ii) It will define a macro namely DOUBLE having substitute value as (X) (2*X) (because of a space following
DOUBLE).
(iii) It will define a macro DOUBLE(X) with X as parameter having substitute value as 2*X.
(iv) It will define a macro DOUBLE(X) with X as parameter, having substitute value as (2*X).
35. Find errors if any in the following program;
// the aim of this program is to interchange the values of two variables by using
// the function swap(float, float)
#include<iostream.h>
void swap(float, float);
voidmain(
float a, b;
cout<<"\nEnter a real no. x";
cin>>x;
cout<<"Enter a real no. y";
cin>>y;
swap(x,y);
cout<<"\n Now the value of x = "<<x;
cout<<"\n Now the value of y = "<<y;
}
void swap(float a, float b)
{
int temp;
temp = a;
b = a;
a = temp;
}
Sol. The function swap() intends to swap the values of two passed parameters. However, values are passed to it by value,
which means any changes in the parameters will not be reflected back. Therefore, the actual purpose of the function is
defeated. To correct this problem, the parameters should be passed by reference i.e. the prototype of swap() should be
void swap (float & , float &); and the function header should be
void swap (float & a, float & b)
36. Rewrite the following program after removing the syntactical errors (if any). Underline each correction.
#include [isotream.h]
typedef char Text (80);
void main()
{
Text T = "Indian"
int Count = strlen(T)
cout<<T<<’has’ <<Count<<’characters’<<endl;
}
Sol. #include<iostream.h>
#include<string.h>
typedef char Text[80];
void main()
{
Text T = “Indian”;
int Count = strlen(T);
cout << T < “has” << Count << “characters” <<endl;
}
37. Rewrite the following program after removing the syntactical error(s), if any. Underline each correction.
#include<iostream.h>
const int Max 10;
void main()
{
int Numbers[Max];
Numbers = {20, 50, 10, 30, 40};
for (Loc = Max – 1; Loc > =0; Loc– –)
cout >> Numbers[Loc];
}
Sol. #include<stdlib.h>
const int Max = 10;
void main()
{
int Numbers[Max] = {20, 50, 10, 30, 40};
for(int Loc = Max – 1; Loc > = 0; Loc – –)
cout << Numbers[Loc];
}
38. Rewrite the corrected code for the following program. Underline each correction (if any);
#include<iostream.h>
structure Swimmingclub
{
int memnumber;
char memname[20];
char memtype[] = "LIG";
};
void main()
{
Sol. #include<iostream.h>
void main()
{int X[] = {60, 50, 30, 40}, Y, Count = 4;
cin >> Y;
for (int I = Count -1; I > = 0; I --)
switch (I)
{
case 0 :
case 2 : cout << Y* X[I] << endl; break;
case 1 :
case 3 : cout << Y + X[I];
}
}
40. Find the syntax error(s), if any, in the following program :
#include<iostream.h>
main()
{
int x[5], *y, z[5];
for (i = 0 ; i < 5; i++)
{ x [i] = i;
z[i] = i + 3;
y = z;
x = y;
}
}
Sol.
Erroneous Statements Errors and Corrections
1. int x[5], *y, z[5]; There should not be space between array name and its size as it
is in x and [5]. The corrected code is :
int x[5], *y, z[5];
2. for(i = 0; i < 5; i++) i variable not defined. The corrected code shall be
for (int i = 0; i < 5; i++)
3. x = y; x being array name can not be assigned any other value. Thus x
= y is erroneous. The corrected code could be
x[i]=*y; or y = x ;
43. Please list the output of the program below. In other words, every time there is a cout statement, list the values that
will appear on the screen.
#include<iostream.h>
int main(void)
{
for(int i = 1; i<3 ; i++)
for (int j = 1; j <= 5 ; j += 2)
cout << i <<"*" <<j<<"=" <<i * j <<endl ;
double xx = 1;
while (xx << 32)
xx *=2 ;
cout << "xx =" << xx << endl;
int i = 8, j = 3;
int k = i/j;
double x = i/j;
double y = ((double) i/(double) j);
cout <<"Now k = " <<k <<",x="<<x <<", y = "<< y << endl;
return 0;
}
Sol. 1*1=1
1*3=3
1*5=5
2*1=2
2*3=6
2 * 5 = 10
xx = 32
Now k = 2, x = 2.0, y = 2.666.
44. What is the output of the following program.
#include<iostream.h>
void main()
{ struct point
{ int x, y;
}polygon[] = {{1,2], {1,4}, {2, 4}, {2,2}};
point *a;
a = polygon;
a++ ;
a -> x++;
cout << polygon -> x <<endl;
}
Sol. Polygon points to polygon[0] and polygon[0].x i.e., polygon–> x is 1. (a –>x will represent 2 as a++ (0 + 1) points to
polygon[1] and a ->x++ makes polygon[1].x as 1 + 1 = 2).
45. Consider the following program:
#define two(x) x * x
# define ddouble(x) x + x
main()
{
Buy(I[1], 5);
cout<<I[1].Ino<<":" <<I[1].Qty<<endl;
Buy(I[0],10);
cout<<I[0].Ino<<":"<<I[0].Qty<<endl;
Buy(I[1]);
cout<<I[1].Ino<<":"<<I[1].Qty<<endl;
}
Sol. 103 : 25
101 : 60
103 : 27
52. Give the output of the following program :
#include<iostream.h>
int a = 3;
void demo(int x, int y, int &z)
{
a += x + y;
z = a + y;
y += x;
cout << x <<y<<z<<endl;
}
void main()
{
int a = 2, b = 5;
demo (::a, a, b);
cout << ::a << a << b << endl;
demo(::a, a, b);
}
Sol. : 3 5 10
8 2 10
8 10 20
Define the term Data Encapsulation in the context of Object Oriented Programming. Give a suitable example using a
C++ code to illustrate the same.
Sol. Data Encapsulation is the wrapping up of data and operations/functions (that operate on the data) into single unit
(called class) is known as Encapsulation.
Data Hiding is keeping un-essential and critical data hidden from outside world to prevent any accidental charges or
unsafe practices.
A Class implements both data encapsulation and data hiding e.g.,
class clock
{ double alarmtime;
char brand[50];
double time; (Hidden data because it is private.)
public ;
void getTime();
void setTime();
void setAlarm();
void ringAlarm();
}; (Class implements encapsulation by defining data and functions as one unit.)
11. What do you understand by Polymorphism ? Give a suitable example of the same.
Sol. Polymorphism is the property by which the same message can be sent to objects of several different classes and each
object can respond to it in a different way depending upon its class. In C++, Polymorphism is implemented through
overloading (and virtual functions).
A function name having several definitions that are differentiable by the number and types of their arguments, is
known as function overloading.
For example,
float area (float a)
{
return a*a;
}
float area (float a, float b)
{
return a*b;
}
12. How is memory allocated to a class and its objects?
Sol. When a class is defined, memory is allocated for its member functions and they are stored in the memory. When an
object is created, separate memory space is allocated for its data members. All objects work with the one copy of
member functions shared by all.
13. When will you make a function inline and why?
Sol. A function is made inline when the following features are there :
(i) the function is small.
(ii) the function is not returning any value and contains no return statement.
(iii) the function does not contain a loop or a switch or a goto.
(iv) the function does not contain static variables.
(v) the function is not recursive.
The inline functions run a little faster than the normal functions as function–calling overheads are saved.
14. While defining a class, you can define its methods (member functions) inside or outside the class definition. How are
these two definitions different?
Sol. There are basically two differences in these two definitions :
1. In the why the function names are written. When a member function is defined outside the class definition,
its name must be a qualified name i.e., its name must be in the form classname::function name whereas this
is not required for an inside definition.
2. In the way the functions are processed. A member function defined inside the class definition are
automatically trerated as inline functions which is not the case when the functions are defined outside the
class definition unless the functions are explicitly made inline.
2. When an object is passed by value to a function, then the copy of the passed object is created for the function
by invoking the copy constructor.
3. When a function returns an object, the copy constructor creates a temporary object to hold the return value of
the function returning an object.
20. How many times is the copy constructor called in the following code?
Sample func(Sample u)
{
Sample v(u);
Sample w = v ;
return w ;
}
void main()
{
Sample x ;
Sample y = func(x);
Sample z = func(y);
}
Sol. : The copy constructor is called 8 times in this code. Each call to the function func() requires call to the copy
constructor :
(i) When the parameter is passed by value by u
(ii) when v is initialized
(iii) when w is initialized
(iv) when w is returned.
21. Differentiate between Constructor and Destructor function with respect to Object Oriented Programming
Or
What is the use of a constructor function in a class ? Give a suitable example of a constructor function in a class.
Sol. A constructor is a member function of a class with these characteristics : (i) same name as that of the class, (ii) no
return type. A Constructor is automatically invoked when an object is created and it is used to initialize data members
of the object. Constructors can be overloaded.
A destructor is also a member function of a class with these characteristics : (i) same name as that of class with a ~
before the name, (ii) no return type. Destructors are automatically invoked when an object goes out of scope and it is
used to free all resources to the object during run-time. Destructor cannot be overloaded.
22. What do you understand by default constructor and copy constructor functions used in classes ? How are these
functions different from normal constructors?
Sol. A constructor that accepts no parameters is called default constructor.
A constructor that constructs an object by initializing it with another object of the same class is called copy
constructor.
Normally, constructors can be default, parameterized or copy constructors. A parameterized constructor can take
arguments and if its arguments have default values, it becomes equivalent to default constructors.
23. What do you understand about a base class and derived class ? If a base class and a derived class each include a
member function with the same name and arguments, which member function will be called by the object of the
derived class if the scope operator is not used?
Sol. A base case is the class whose properties are inherited by another class.
The derived class is the class that inherits properties from base class.
If a base class and a derived class each include a member function with the same name and argument, the member
function of derived class will be called if the scope operator is not used.
24. How does inheritance influence the working of constructors and destructors?
Sol. Inheritance means a class (derived class) is inheriting properties form another class (the base class). When an object
of the derived class is declared, in order to create it, firstly the constructor of the base class is invoked and then, the
constructor of the derived class is invoked.
On the other hand when an object of the derived class is destroyed, first the destructor of the derived class is invoked
followed by the destructor of the base class. That is, the destructors are invoked in the reverse order of constructor
invocation.
Sol. A derived class invokes its base class’s constructor explicitly i.e., by naming the constructor name while invoking it.
A container class invokes it member object’s class constructor implicitly i.e., it does not name the constructor but
through the object name it gets invoked.
For example,
case A {
};
case B {
};
class C : public A
{ B object 1;
public:
C( ) : A( ), object ( )
{
}
}
28. When does ambiguity arise in multiple inheritance? How can one resolve it ? What are virtual base classes ? What is
their significance ?
Sol. : Ambiguity arises in an inheritance hierarchy of multiple, multilevel inheritance if an inherited member of common
origin gets inherited via two different path.
This ambiguity is resolved through virtual base classes which ensures that only single copy of common origin gets
inherited. When two or more objects are derived from a common base class, you can prevent multiple copies of base
class from being present in an object derived from those objects by declaring the base class as virtual when it is
inherited. This is accomplished by putting the keyword virtual before the base class name when it is inherited.
Example:
class base
{ public :
int a ;
};
class D1 : virtual public base
{ public :
int b ;
}
class D2 : virtual public base
{ public :
int c ;
}
class D3 : public D1, public D2
{ public :
int d ;
void show ( )
{
cout << a << b << c << d ;
}
};
void main ( )
{ D3 Obj ;
Obj . a = 10
Obj . b = 20
Obj . c = 30
Obj . d = 40
cout << Obj. a <<Obj.b<<Obj.c <<Obj.d ; // Obj. show ( ) ;
}
29. Rewrite the following program after removing the syntactal error (if any). Underline each correction.
#include<iostream.h>
class BOOK
{ long BId, Qty ;
Public :
void Purchase() {cin >> BId >> Qty; }
void Sale
{ cout << setw(5) << BId << "Old: " << Qty<<endl;
cout << "New: " <<--Qty << endl;
}
};
void main()
{ BOOK B;
B.Purchase();
Sale();
B.Sale()
}
Sol. #include<iostream.h>
#include<iomanip.h>
class Book
{
long BId, Qty;
public :
void Purchase(){cin >> BId >> Qty;}
void Sale
{cout << setw(5) << BId << "Old:" << Qty <, endl;
cout <, "New:" << -- Qty << endl;
}
};
void main()
{
Book B;
B. Purchase();
B.Sale();
B.Sale();
}
30. How is matching done in case of overloaded functions ?
Sol.: With a function call that uses the name of an overloaded function, the compiler follows the following steps in order to
find the best match :
1. Search for an exact match is performed. If an exact match is found, the function is invoked.
2. If an exact match is not found, a match through promotion is searched for. Promotion means conversion of
integer type char, short, enumeration and int into int or unsigned int (whatever is capable of representing all
the values of the datatype being promoted) and conversion of float into double.
3. If first two steps fail then a match through application of C++ standard conversion rules is searched for.
4. If all the above mentioned steps fail, a match through application of user – defined conversions and build –
in conversions is searched for.
5. If all these steps fail, the complier flashes a message reporting no match.
6. If more than one definition qualify for the function call, the compiler reports an ambiguous match.
31. Given the following code fragment :
int x, b;
class X
{
int x;
float y;
VMC | Board Notes 22 Computer Science
Vidyamandir Classes
char z ;
void int (void)
{x = y = z = 0;
}
public:
int a;
int b;
void sqr(int i)
{
cout <<"Private sum:"<<(x + y) * 1;
cout << "\n" << "Public sum:" <, (a + b) * 1 << "\n";
}
void start(int i, float j, char k);
friend void sum(void)
}; //class X
void X :: start(in i, float j, char k)
{
int();
x = i;
y = j;
z = k;
}
void sum(void)
{cout << "sum=" << x + y + a + b << "\n";
}
X O1;
void check(void)
{int a = 10;
cout << a << O1.b << x ;
}
What all variables can be accessed by the following functions?
sqr ( ), start( ), sum (), check( )
Sol. sqr( ) can access X :: x, :: x, X :: y, X :: z, X :: a, X :: b, :: b
start( ) can access all the variables as that of sqr( )
sum( ) can also access all the variables as that of above two functions.
check( ) can access :: x, :: b, X :: a, X :: b and its local variable a.
32. Consider the following code fragment :
Sol. int x = 5;
int y = 3;
class Outer
{ public:
int x ;
int a ;
static int s ;
class inner
{int a;
public:
void f(int i)
{ x = i;
s = i;
y=i;
a = i;
}
}; //Inner definition over
Inner I1; //Inner object
};
void g(int i)
{ x = i;
y = 1;
a = i;
s = i;
}
}; //Outer definition over
Outer O1 //Outer object
int main()
{O1.I1.f(3); //statement1
O1.g(8): //statement2
return 0;
}
What will be the values of :: x, ::y, Outer :: x, Outer ::a, Outer::s, Inner::a after statement 1 and statement 2 of above
code?
Sol. After statement 1
:: x = 5; ::y = 3; Outer :: x = 3; Outer ::a = Not Defined; Outer :: s = 3; Inner :: a = 3
After statement 2
::x = 5 ; ::y = 8; Outer :: x = 8 ; Outer :: a = 8 ; Outer :: s = 8 ; Inner :: a = Its previous value
33. What will be output of following program :
# include<iostream.h>
# Include<conio.h> // for cirscr( )
class X {
int x ;
float y;
public :
void init(void)
{
x = 0;
y=0;
}
void getval(int i, float j)
{ x = i;
y = j;
}
void prn(void)
{cout << "x=" << x << "\t";
cout << "y=" << y << "\n";
}
};
int main()
{cirscr()
X O1, O2;
O1.init();
O2.init();
O1.getval(25,12.71);
O1.prn();
O2.prn();
return 0;
}
35. Answer the questions (i) to (iv) base on the following code :
class FaceToFace
{
char CenterCode[10];
public:
void Input();
void Output();
};
class Online
{
char website[50];
public:
void SiteIn();
void SiteOut();
};
class Training : public FaceToFace, private Online
{
long Tcode;
float charge;
int period;
public:
void Register();
void Show();
};
(i) Which type of Inheritance is shown in the above example?
(ii) Write names of all the member functions accessible from Show() function of class Training.
(iii) Write name of all the members accessible through an object of class Training.
(iv) Is the function Output() accessible inside the function SiteOut()? Justify your answer.
Sol. (i) Multiple Inheritance
(ii) Register(), Siteln(), Siteout(), Input(), Output()
(iii) Register (), Show(), Input(), Output()
(iv) No, function Output() is not accessible inside the function SiteOut(), because Output() is a member of class
FaceToFace and SiteOut() is a member of class Online, and the classes FaceToFace and Online are two independent
classes.
36. What is the difference between Macros and inline function ?
Sol. The difference between macros and inline function is that macros are replaced in the preprocessing stage while inline
functions are replaced in the compilation stage.
Note: Memory allocation of various types:
char 1 byte
short 1 byte
int 2 bytes
long 4 bytes
float 4 bytes
double 8 bytes
long double 10 bytes
Chapter - 3 Arrays
Address Calculation:
Address in Row-major order B w [ n ( I r ) ( J c )]
Address in Column-major order=B + w [(I -r) + r (J - c )]
B : Base address r : no. of rows I : Row of element given
w : Width/element size n : no. of columns J : Column of element given
r : lower row c : lower column
If nothing is given, we assume that the array is stored row-wise, i.e., address is calculated using Row-major.
Eg: An array A[40][10] is stored in the memory along the column with each element occupying 4 bytes. Find out the
address of the location A[3][6] if the location A[30] [10] is stored at the address 9000.
R = 40, N = 10, W=4 I=3 J=6 B=?
9000 = B 4 [(30 0) 40 (10 0)]
9000 = B 4 [30 400]
Program in arrays:
(i) Selection sort :
void selsort ()
{
int small, pos, temp ;
for(int i = 0 ; i < size ; i++)
{
small = Ar[i];
pos = i ;
for (int j = i+1 ; j < size ; j++)
{
if (Ar[j] < small)
{
Small = Ar[j];
pos = j;
}
}
}
temp = Ar[i];
Ar[i] = Ar[pos];
Ar[pos] = temp;
}
Explanation :
1. If two arrays A,B are in ascending order then merge them to form C which is also in ascending order
Sol. void mergesort()
{
int a, b, c;
for(a=0, b=0, c=0; a<M&&b<N;) //M: size of array, N: size of array
{
if (A[a]<=B[b])
C[c++]= A[a++];
else
C[c++]= B[b++];
}
if (a<M)
{
while(a<N N)
C[c++]=A[a++];
}
else
{
while(b<N)
C[c++]= B[b++];
}
}
2. If an array A is in ascending order and an array B is in descending order, then merge them to form C which is in
ascending order.
Sol. void mergesort()
{
int a, b, c;
for(a=0. b=N-1, c=0; a<M&&b>=0;) //M: size of array, N: size of array
{
if(A[a]<=B[b])
C[c++]= A[a++];
else
C[c++]= B[b--];
}
if(a<M)
{
while(a<M)
C[c++]=A[a++];
}
else
{
while(b>=0)
C[c++]=B[b--];
}
}
(v) Search :
1. Linear search :
cout<<"\nNothing Found!!";
}
int main()
{
system("cls");
int choice,a[10],value,index;
char choices;
cout<<"Enter the elements(10) for the array: ";
for(int i=0;i<10;i++)
cin>>a[i];
do
{ system("cls");
cout<<"\nEntert the element to be searched: ";
cin>>value;
system("cls");
linear(a,value);
}
2. Binary search :
void bubblesort(int r[])
{
int i,j,swapped=1,temp;
for(i=0;((i<9)&&(swapped));i++)
{ swapped=0;
for(j=9;j>i;j--)
if(r[j]<r[j-1])
{ swapped=1;
temp=r[j];
r[j]=r[j-1];
r[j-1]=temp;
}
}
cout<<"\nYour Array was sorted in Ascending order to perform binary search!!\n";
for(int k=0;k<10;k++)
cout<<r[k]<<" ";
cout<<endl;
}
void binary(int p[],int r)
bubblesort(p);
int b=0,l=9,mid;
while(b<=l)
{
mid=(b+l)/2;
if(p[mid]==r)
{
cout<<"\nsearch successful. . . . . no. FOUND!!!";
cout<<"\nIndex: "<<mid<<"Position :"<<(mid+1);
return;
}
else if(r>p[mid])
b=mid+1;
else
l=mid-1;
}
cout<<"\nnumber Not Found!!";
}
VMC | Board Notes 32 Computer Science
Vidyamandir Classes
int main()
{
system("cls");
int choice,a[10],value,index;
char choices;
cout<<"Enter the elements(10) for the array: ";
for(int i=0;i<10;i++)
cin>>a[i];
do
{ system("cls");
cout<<"\nEntert the element to be searched: ";
cin>>value;
system("cls");
binary(a,value); }
#define max 10
class stack
{
int a[max],top;
public:
stack()
{top=-1;}
void push();
void pop();
void display();
};
void stack::push()
{
cout<<" Enter the value: ";
int val;
cin>>val;
if(top==(max-1))
cout<<" Stack is full !! ";
else
a[++top]=val;
}
void stack::pop()
{
if(top==-1)
cout<<" Stack is empty !!! ";
VMC | Board Notes 33 Computer Science
Vidyamandir Classes
else
--top;
}
void stack::display()
{
for(int i=top;i>=0;--i)
cout<<a[i]<<endl;
}
int main()
{
int c;
char ch;
stack s;
do{
system("cls");
cout<<"Enter your choice\n";
cout<<"1.push \n";
cout<<"2.pop \n";
cout<<"3.Display \n";
cout<<"4.Exit \n";
cin>>c;
switch(c)
{
case 1:s.push(); break;
case 2:s.pop(); break;
case 3:s.display(); break;
case 4:exit(0); break;
}
cout<<endl<<"Try again?? (y/n)...."<<endl;
cin>>ch;
}while(ch=='y'|| ch=='Y');
}
struct node{
int value;
node *next;
};
class stack{
node *top;
public:
stack()
{top=NULL;}
void push();
void pop();
void display();
};
void stack::push()
{
node *ptr;
ptr=new node;
if (ptr==NULL)
{
cout<<" memory overflow!!!";
getch();
exit(0);
}
ptr->next=NULL;
cout<<"Enter a number: ";
cin>>ptr->value;
if (top==NULL)
top=ptr;
else
{
ptr->next=top;
top=ptr;
}
}
void stack::pop()
{
node *ptr=top;
if (top==NULL)
{cout<<"Stack is empty!!! ";
return;}
top=ptr->next;
delete ptr;
cout<<" POPPED OUT OF THE STACK !!";
}
void stack::display()
{
node *ptr=top;
if (ptr==NULL)
{ cout<<"STACK is EMPTY !!";
return;
}
while(ptr!=NULL)
{ cout<<ptr->value<<" ";
cout<<endl;
ptr=ptr->next;
}
}
int main()
{
char ch;
int choice;
stack s;
do
{
system("cls");
cout<<"What do you wish to do??\n1.push \n";
cout<<"2.pop \n";
cout<<"3.Display \n";
Queue as an array:
#define max 10
class Queue
{
int a[max],front,rear;
public:
Queue()
{front=rear=-1;}
void insertQ();
void deleteQ();
void displayQ();
};
void Queue::insertQ()
{
cout<<" Enter the value: ";
int val;
cin>>val;
if(rear==(max-1))
cout<<" Queue is full !!";
else
a[++rear]=val;
if(front==rear)
front=0;
}
void Queue::deleteQ()
{
if(rear<0)
cout<<" Queue is empty !!";
else
if(front==rear)
front=rear=-1;
else
front++;
}
void Queue::displayQ()
{
for(int i=front+1;i<=rear;++i)
cout<<a[i]<<" ";
}
int main()
{
int choice;
char choices;
Queue a;
do{
system("cls");
cout<<"Enter your choice\n";
cout<<"1.insert \n";
cout<<"2.delete \n";
cout<<"3.Display \n";
cout<<"4.Exit \n";
cin>>choice;
switch(choice)
{
case 1:a.insertQ(); break;
case 2:a.deleteQ(); break;
case 3:a.displayQ(); break;
case 4:exit(0); break;
}
cout<<endl<<"try again<y/n>"<<endl;
cin>>choices;
}while(choices!='n');
}
Queues as a linked list:
struct node
{
int value;
node *next;
};
class Queue
{
node *front, *rear;
public:
Queue()
{front=rear=NULL;}
void push();
void pop();
void display();
};
void Queue::push()
{
node *ptr;
ptr=new node;
if (ptr==NULL)
{
cout<<" underflow...!!!!";
getch();
exit(0);
}
ptr->next=NULL;
cout<<"Enter value: ";
cin>>ptr->value;
if (front==NULL)
front=rear=ptr;
else
{rear->next=ptr;
rear=ptr;}
}
void Queue::pop()
{
node *ptr;
if (front==NULL)
{cout<<"Queue is empty ";
return;}
front=front->next;
delete ptr;
cout<<" Deleted ";
}
void Queue::display()
{
node *ptr=front;
if (front==NULL)
{
cout<<"queue is empty";
return;
}
while(ptr!=NULL)
{
cout<<ptr->value<<" ";
ptr=ptr->next;
}
}
int main()
{
char ch;
int choice;
Queue q;
do
{
system("cls");
cout<<"What do you wish to do??\n1.push \n";
cout<<"2.pop \n";
cout<<"3.Display \n";
cout<<"4.Exit\nEnter your choice:";
cin>>choice;
switch(choice)
{
case 1:q.push(); break;
case 2:q.pop(); break;
case 3:q.display(); break;
case 4:exit(0);
}
Circular Queue:
const int size = 10;
int Q(size] ;
void add (int Q [ ], int front, int &rear, int num)
{ if ((rear + 1) % size = = front)
cout << “Queue is full” ;
else
{
rear = (rear + 1) % size ;
Q [rear] = num ;
}
}
int del (int Q[ ], int & front, int rear)
{ if (front = = rear)
{
cout << “Empty Queue” ;
return (–1) ;
}
else
{ front ++ ;
int num = Q[front] ;
return num ;
}
}
void show (int Q [ ], int front, int rear)
{
int i = front ;
if (front = = rear)
cout << “Empty Queue” ;
else
{
cout << “The queue contains :” ;
while (i! = rear)
{
i = (i + 1) % size ;
cout << Q[i] << ‘lt’ ;
}
}
}
1. Convert X ; A + (B* C – (D/EF)*G)* H into postfix form showing stack status after every step in tabular form.
Sol.
Symbol Scanned Stack Expression Y
1. A ( A
2. + (+ A
3. ( (+( A
4. B (+( AB
5. * (+(* AB
6. C (+(* ABC
7. – (+(– ABC*
8. ( (+(–( A BC*
9. D (+(–( ABC*D
10. / (+(–(/ ABC*D
11. E (+ ( – ( / ABC*DE
12. (+(–(/ ABC*DE
13. F (+(–(/ ABC*DEF
14. ) (+(– ABC*DEF/
15. * (+( –* A B C * D E F /
16. G (+(–* A B C * D E F /G
17. ) (+ ABC*DEF/G *–
18. * (+* ABC*DEF/G *–
19. H (+* ABC*DEF/G *–H
20 ) ABC*DEF/G *–H*+
2. Develop the algorithm for evaluating an arithmetic expression A which is in postfix notation. Show the contents of
the stack during the execution the execution of the algorithm using the following.
A = 30, 5, 2 ^ 12, 6, / , + –3.
Sol. For algorithm, refer to Algorithm on pate 540 push ‘(‘ to the stack and add’)’ at the end of expression i.e., the
expression becomes 30, 5, 2, ^, 12, 6, /, +, – 3)
Input
Step Action taken Stack Status Output
Elemnt/symbol
1 (
2. 30 Push (, 30
3. 5 Push (, 30, 5
4. 2 Push (, 30, 5, 2
5. ^ POP (2 elements) (, 30 5 ^ 2 = 25
6. Push the result (25) (, 30, 25
7. 12 Push (, 30, 25, 12
8. 6 Push (, 30, 25, 12,6
9. / POP(2 elements) (, 30, 25 12/6 = 2
10. Push result (2) (, 30, 25, 2
11. + POP (2 elements) (, 30 25 + 2 = 27
12. Push the result (27) (, 30, 27
13. – POP (2 elements) ( 30 – 27 = 3
14. Push the result (3) (3
15. ) POP everything #
3. Convert the expression (TURE && FALSE) || (FALSE || TRUE) to postfix expression. Show the content of the stack
at every step.
Sol. (TRUE && FALSE) || [FALSE || TRUE)]
Adding ] the end of expression and inserting [to the beginning of stack.
Scanning from Left to Right
S.No Symbol Stack Postfix Expression Y
0. [
1. ( [(
2. TRUE _ TRUE
3. && [(&& __
4. FALSE __ TRUE FALSE
5. ) [ TRUE FALSE &&
6. || [|| __
7. | [|| ! __
8. ( [| | !( __
9. FALSE __ TRUE FALSE && FALSE
10. || [||!(|| __
11. TRUE __ TRUE FALSE && FALSE TURE
12. ) [|| ! TRUE FALSE && FALSE TRUE ||
13. ] End of Expression TRUE FALSE && FALSE TRUE [|| ]
4. Evaluate the following postfix notation of expression : 50, 60, +, 20, 10, –,*
Sol.
Step Input symbol Action taken Stack Status Output
1. 50 Push 50 ( – top)
2. 60 Push 50, 60
3. + Pop (2 elements) (empty stack) 50 + 60 = 110
Push result (110) 110
4. 20 Push 110, 20
5. 10 Push 110, 20 10
6. – Pop (2 elements) 110 20 – 10 = 10
Push result (10) 110, 10
7. * Pop (2 elements) (empty stack) 110 * 10 = 1100
Push result (1100) 1100
8. End of expression Pop (result) Ans = 1100
5. Evaluate the following postfix notation expression : (show status of Stack after each operation)
False, True, NOT, OR, True, False, AND, OR
Sol.
8. What do you understand by memory leaks? What are the possible reasons for it? How can memory leaks be avoided?
Sol. If the objects, that are allocated memory dynamically, are not deleted using delete, the memory block remains
occupied even at the end of the program. Such memory blocks are known as orphanded memory blocks.
These orphaned memory blocks when increase in number, bring as adverse effect on the system. This situation is
known as memory leak. The possible reasons for this are:
(i) a dynamically allocated object not deleted using delete.
(ii) delete statement is not getting executed because of some logical error.
(iii) assigning the result of a new statement to an already occupied pointer.
The memory leaks can be avoided by
(i) making sure that a dynamically allocated object is deleted.
(ii) a new statement stores its return value (a pointer) in a fresh pointer.
11. In which two ways can the elements of a double dimensional array may be stored in computer’s memory?
Or
How is computer memory allotted for a two – dimensional array?
Sol. : For two – dimensional array, the computer memory is allocated either in Row-major form or Column major form.
Row Major form stores the 2-D array row wise i.e, firstly the first row is stored, then the second row, then third row,
and so forth.
Column Major form stores the 2-D array column wise i.e., firstly the first column, then the second column, then third,
and so forth. The default form is Row-major.
12. Write a function SKIPEACH (int H[][3], int C, intR) in C++ to display all alternate elements from two – dimensional
array H (starting from H[0][0]).
For Example :
If the array is containing :
12 45 67
33 90 76
21 43 59
Total output will be : 12 67 90 21 59
Sol. viod SKIPEACH(int h[][3], intC, intR)
{
int display = 1;
for (int i = 0 ; i < R ; i++)
for (int j = 0; j < C ; j++)
{
if(display = = 1)
count << h[i][j];
display * = 1;
}
}
13. Distinguish between infix, prefix and postfix algebraic expressions given examples of each.
Sol. Infix Notation. In this notation, the operator symbol is placed in between the operands e.g.,
A + B , (A – C) × B
Prefix Notation. In this notation, the operator symbol is placed before its operands e.g.,
+ AB × –ACB
Postfix Notation. In this notation, the operator symbol is placed after its operands e. g.,
AB+, AC – B×, ABC×+,
14. An algorithm requires two stacks of sizes M and N that are to be maintained in the memory. Illustrate with an
example how will you adjust two stacks in one dimensional array with M + N memory locations so that the overflow
condition in minimized.
Sol. Let us say that stack A is with size M and stack B is with size N.
If the stack A is stored in locations 0 to M – 1 and the stack B is stored in locations M to M + N – 1, the separate
areas for the two are ensured. In the beginning the TOPs of both stacks are at opposite ends. When TOP. A reaches at
M –1, any further insertion will lead to overflow in stack A and when TOP.B reaches at M, any further insertion in
stack B will lead to overflow.
File.read((char*)&B, sizeof(B)) ;
B.ShowVal( );
File.close();
}
void Modify(int RecNo)
{
fstream File;
Book B;
File.open (“BOOK.DAT”, ios::binary|ios::in|ios::out) ;
B.EnterVal( );
_____________ //Statement 2
File.write((char*)&B, sizeof(B));
File.close( );
}
(i) Write statement 1 to position the file pointer to the beginning of the desired record to be read, which is sent
as parameter of the function (assuming RecNo 1 stands for the first record)
(ii) Write statement 2 to position the file pointer to the beginning of the desired record to be modified, which is
sent as parameter of the function (assuming RecNo 1 stands for the first record)
Sol. (i) File.seekg((RecNo – 1) *sizeof(B)) ; //Statement 1
(ii) File.seekp((RecNo – 1)*sizeof(B)); //Statement 2
11. What are file modes? What role do they play in file I/O ?
Sol. The filemode describes how a file is to be used in the program. That is whether the file is to be read from only, to be
written to it or to be appended, and so on. The filemode(s) are specified at the time of opening files. Different
filemode constants defined in ios class are :
ios : : in opens file for reading
ios : : out opens file for writing
ios : : ate seeks to eof upon opening file
ios : : app appends to end of file
ios : : trunk truncates file if it exists
ios : : nocreate causes open fail if file does not exist
ios : : noreplace causes open fail if file does exist
ios : : binary opens file in binary mode.
#include<iostream.h>
#inclued<fstream.h>
class stu { int rollno ;
char name[25] ;
char Class[4] ;
float marks ;
char grade ;
public:
void getdata( )
{ cout << “Rollno:” ; cin >> rollno ;
cout << “Name:” ; cin >> name ;
cout << “Class:” ; cin >> Class ;
cout << “Marks:” ; cin >> marks ;
if (marks >= 75) grade = ‘A’ ;
else if(marks >= 60) grade = ‘B’ ;
else if(marks >= 50) grade = ‘C’ ;
else if(marks >= 40) grade = ‘D’ ;
else grade = ‘F’ ;
}
void putdata( )
{ cout << name << “, rollno”<< rollno<<”has”<< marks
<< “% marks and” << grade <<”grade.”<< endl ;
}
int getrno( ) //accessor function
{ return rollno ;
}
}s1 ;
int main( )
{
int rn ;
char found = ‘n’ ;
ifstream fi(“stu.dat”,ios::in); //stu.dat must exist on disk
cout <<” Enter rollno to be searched for:” ;
cin >> rn ;
while(!fi.eof( ))
{ fi.read((char*)&s1,sizeof(s1));
if (s1.getrno( ) == rn)
{
s1.putdata( );
found = ‘y’ ;
break ;
}
}
if (found == ‘n’)
cout << “Rollno not found in file!!” << endl ;
fi.close( ) ;
return 0;
}
Output:
Enter rollno to be searched for : 108
Venkat, rollno 108 has 78 % marks and A grade.
Enter rollno to be searched for : 119
Rollno not found in file !!
#include<iostream.h>
#inclued<fstream.h>
class stu { int rollno ;
char name[25] ;
char Class[4] ;
float marks ;
char grade ;
public:
void getdata( )
{ cout << “Rollno:” ; cin >> rollno ;
cout << “Name:” ; cin >> name ;
cout << “Class:” ; cin >> Class ;
cout << “Marks:” ; cin >> marks ;
if (marks >= 75) grade = ‘A’ ;
else if(marks >= 60) grade = ‘B’ ;
else if(marks >= 50) grade = ‘C’ ;
else if(marks >= 40) grade = ‘D’ ;
else grade = ‘F’ ;
}
void putdata( )
{ cout << name <<” , rollno” << rollno << “has” << marks
<< “%marks and” << grade <<” grade.” << endl;
}
int getrno( ) //accessor function
{ return rollno ;
}
} s1 ;
int main( )
{ ofstream fo(“stu.dat”,ios::app) ;
char ans = ‘y’ ;
while (ans = = ‘y’)
{s1.getdata( );
fo.write((char*)&s1, sizeof(s1)) ;
cout << “Record added to file.\n” ;
cout << “Want to enter more records? (y/n)…” ;
cin >> ans ;
}
fo.close( );
return 0 ;
}
Output:
Rollno : 109
Name : Tauqueer
Class : XIA
Marks : 79
Record added to file.
Want to enter more records?(y/n)..n
3. Program to insert data in a sorted file.
#include<iostream.h>
#include<fstream.h>
#include<stdio.h> //for rename( ) and remove ( )
class stu { int rollno ;
char name[25]
char Class[4];
float marks ;
char grade ;
public:
void getdata( )
{ cout << “Rollno:” ; cin >> rollno ;
cout << “Name:” ; cin >> name ;
cout << “Class:” ; cin >> Class ;
cout << “Marks:” ; cin >> marks ;
if (marks > = 75) grade = ‘A’ ;
else if(marks > = 60) grade = ‘B’ ;
else if(marks > = 50) grade = ‘C’ ;
else if(marks > = 40) grade = ‘D’ ;
Output:
Enter the details of student whose record is to the entered :
Rollno : 115
Name : Neha
Class : XIA
Marks : 88
File now contains :
Rollno 102 Name : Joseph
Marks : 67 Grade : B
Rollno 104 Name : Simran
Marks : 77 Grade : A
Rollno 105 Name : Manya
Marks : 49 Grade : D
Rollno 107 Name : Tilotma
Marks : 65 Grade : B
Rollno 109 Name : Tauqueer
Marks : 79 Grade : A
Rollno 115 Name : Neha
Marks : 88 Grade : A
4. Program to delete a record form a file.
#include<iostream.h>
#include<fstream.h>
#include<stdio.h> //for rename( ) and remove ( )
#include<string.h>
class stu { int rollno ;
char name[25]
char Class[4];
float marks ;
char grade ;
public:
void getdata( )
{ cout << “Rollno:” ; cin >> rollno ;
cout << “Name:” ; cin >> name ;
cout << “Class:” ; cin >> Class ;
cout << “Marks:” ; cin >> marks ;
if (marks >= 75) grade = ‘A’ ;
else if(marks >= 60) grade = ‘B’ ;
else if(marks >= 50) grade = ‘C’ ;
else if(marks >= 40) grade = ‘D’ ;
else grade = ‘F’ ;
}
void putdata( )
{ cout << “Rollno” << rollno << “\tName :” << name
<< “\n Marks : ” << marks << “\tGrade:” << “grade.” << endl;
}
int getrno( ) //accessor function
VMC | Board Notes 52 Computer Science
Vidyamandir Classes
{ return rollno ; }
}s1, stud ;
int main( )
{ ifstream fio(“stu.dat”, ios::in) ; //stu.dat must exist on disk
ofstream file(“temp.dat” , ios::out) ;
int rno ;
char found = ‘f’, confirm = ‘n’ ;
cout << “Enter rollno of student whose record is to be deleted \n ” ;
cin >> rno ;
while(!fio.eof( ) )
{ fio.read((char*)&s1, sizeof(s1)) ;
if (s1.getrno ( ) == rno )
{ s1.putdata( ) ;
found = ‘t’ ;
cout << “ Are you sure, you want to delete this record? (y/n)..” ;
cin >> confirm ;
if (confirm == ‘n’)
file.write( (char*)&s1, sizeof(s1)) ;
}
else
file.write((char*)&s1, sizeof(s1)) ;
}
if(found == ‘f’)
cout << “Record not found !!\n” ;
fio.close( ) ;
file.close( ) ;
remove(“ stu.dat”) ;
rename(“temp.dat”, “stu.dat”);
fio.open(“stu.dat”, ios: :in);
cout << “Now the file contains\n”;
while(!fio.eof( ) )
{
fio.read((char*)&stud, sizeof(stud)) ;
if (fio.eof( ) ) break ;
stud.putdata( );
}
fio.close( ) ;
return 0 ;
}
Output:
Enter rollno of student whose record is to be deleted
107
Rollno 107 Name : Tilotma
Marks : 65 Grade : B
Are you sure, you want to delete this record? (y/n)..y
Now that file contains
Rollno 101 Name : Abhinav
Marks : 89 Grade : A
Rollno 102 Name : Joseph
Marks : 67 Grade : B
Rollno 103 Name : Naureen
Marks : 59 Grade : C
Rollno 104 Name : Simran
Marks : 77 Grade : A
Rollno 105 Name : Manya
Marks : 49 Grade : D
Rollno 106 Name : David
Marks : 88 Grade : A
Rollno 109 Name : Tauqueer
Marks : 79 Grade : A
Rollno 115 Name : Neha
Marks : 88 Grade : A
5. Program to modify data in a given file.
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h> //for rename( ) and remove ( )
#include<stdio.h>
#include<string.h>
} s1, stud :
void stu::modify( )
{ cout << “Rollno : ” < < rollno < < endl ;
cout << “Name : ” << name << “\t Class : ” << Class
<< “\t Marks : “<< marks << endl ;
cout << “Enter new details. “ < < endl ;
char nm[20] = “ ” , C[4] = “ ” ;
float mks ;
cout << “New Name : (Enter ∵ to retain old one)” ;
cin >> nm ;
cout << “New Marks : (press –1 to retain old one)” ;
cin >> mks ;
if (strcmp(nm, “ . ”)! = 0)
strcpy(name, nm) ;
if (strcmp(Cl, “ . ”) ! = 0)
strcpy(Class, Cl) ;
if (mks ! = -1 )
{ marks = mks ;
if (marks >= 75) grade = ‘A’ ;
else if(marks >= 60) grade = ‘B’ ;
else if(marks >= 50) grade = ‘C’ ;
else if(marks >= 40) grade = ‘D’ ;
else grade = ‘F’ ;
}
}
int main( )
{ fstream fio(“stu.dat”, ios::in|ios::binary); //stu.dat must exist on disk
int rno; long pos; char found = ‘f’ ;
cout << “Enter rollno of student whose record is to be modified\n ” ;
cin >> rno ;
while(!fio.eof( ) )
{ pos = fio.tellg( ) ;
fio.read((char*)&s1, sizeof(s1)) ;
if (s1.getrno( ) == rno )
{ s1.modify( ) ;
fio.seekg(pos) ;
fio.write((char*)&s1, sizeof(s1)));
found = ‘t’
break ;
}
}
if(found = =’f’)
cout << “Record not found!!\n” ;
fio.seekg(0) ;
cout << ‘Now the file contains\n” ;
while(!fio.eof( ) )
{ fio.read( (char*)&stud, sizeof(stud)):
stud.putdata( ) ;
}
fio.close( ) ;
return 0 ;
}
Output:
Enter rollno of student whose record is to be modified
107
Rollno : 107
Name : Tilotma Class : XIA Marks : 65
Enter new details.
New Name : (Enter ‘ . ’ to retain old one) .
New Class : (press ‘ . ’ to retain old one) .
New Marks : (press ‘ -1 ’ to retain old one) 72
Now the file contains
Rollno 101 Name : Abhinav
Marks : 89 Grade : A
Rollno 103 Name : Naureen
Marks : 59 Grade : C
Rollno 104 Name : Simran
Marks : 77 Grade : A
Rollno 106 Name : David
Marks : 88 Grade : A
Rollno 107 Name : Tilotma
Marks : 72 Grade : B
Rollno : 108 Name : Venkat
Marks : 78 Grade : A
Rollno 109 Name : Tauqueer
Marks : 79 Grade : A
Important Points :
Database : Collection of logical units/ inter-related data such as ‘table’, ‘index’ etc.
Table : Collection of Records & Fields.
Tuples : Rows of a relation (table) are known as Tuples.
Attributes : Columns of a Relation are known as Attributes.
Degree : Number of Columns in a Relation.
Cardinality : Number of Rows/Tuples in a Relation.
All the Databases come under Generation IV Language.
Keys :
The name of the Foreign Key can be different from the Primary Key.
Example :
Table Class II
In the above table, columns admn. No. and Roll no. have unique value for each row, so both are candidates to become
Primary key hence both of these columns are candidate keys. Out of these 2 we can assign one as Primary key and
other will become alternate key
This language is for all DBMS and RDBMS. It is furthered divided into certain categories:
DDL : Data Definition Language
DML : Data Manipulation Language
DQL : Data Query Language
DDL DML
Data Definition Language Data Manipulation Language
Works with a table structure Works with the records of the table
Contains 3 statements : Create, Alter and Drop
Contains 3 statements : Insert, Update and Delete
DDL Statements
Create : To create a table, create statement is used.
Alter : It is used to add/modify/delete a column.
Drop : To drop or delete the complete table. The table structure as well as the records are completely removed
from the memory.
DML Statements
Insert : To insert records in the table.
Update : To edit or make changes in the existing record.
Delete : To delete records from the table.
DQL Statements
Contains One Single statement : ‘Select’.
‘Select’ statement is used to display the records of the table.
Things to Remember
In the above table, column AdmNo and RollNo have unique values for each row, so both are candidate to become
primary keys. Hence both of these column are Candidate Keys. Out of these two we can assign one as primary key
and other will become alternate key.
7. What do you understand by Selection and Projection operations in relational algebra?
Sol. Selection means selecting some row (tuples) from according to given condition
e.g., price 20.2 Item
Project Operation yields a vertical subset of a given relation (i.e., select all tuples containing only given column of a
relation).
e.g., NAME, DESIG Employee
The Cartesian product of these two relations, Student × Instructor, will yield a relation as :
Union. The union operation produces a third relation that contains tuples from both the operand relations which must be
union-compatible. To denote the union of two relations X and Y, we write as X Y which will contain all tuples of Y in it.
‘Having’ Clause : The ‘Having’ Clause places conditions on groups in contrast to ‘Where’ clause that places
conditions on individual rows. While ‘Where’ conditions cannot include aggregate functions, ‘Having’
conditions can do so.
For eg.: Select avg(gross), sum(gross) from employee Group By grade Having grade = ‘E4’;
Select job, count(*) from emp Group By job Having count(*)<3;
Solved Problems :
1. Given the following student relation :
Relation Student :
No. Name Age Department Date of adm Fee Sex
1. Pankaj 24 Computer 10/01/97 120 M
2. Shalini 21 History 24/03/98 200 F
3. Sanjay 22 Hindi 12/12/96 300 M
4. Sudha 25 History 01/07/99 400 F
5. Rakesh 22 Hindi 05/09/97 250 M
6. Shakeel 30 History 27/06/98 300 M
7. Surya 34 Computer 25/02/97 210 M
8. Shikha 23 Hindi 31/07/97 200 F
Write SQL commands for (a) to (f) and write output for (g).
(a) To show all information about the students of History department.
(b) To list the names of female students who are in Hindi department.
(c) To list names of all students with their date of admission in ascending order.
(d) To display student’s Name, Fee, Age for Male Students only.
(e) To count the number of students with Age < 23.
(f) To insert a new row in the ‘Student’ table with the following data :
9, “Zaheer”, 36, “Computer”, {12/03/97}, 230, “M”
(g) Give the output of the following SQL statements:
(i) Select COUNT (distinct Department) from Student;
(ii) Select MAX(Age) from Student where Sex = “F”;
(iii) Select AVG(Fee) from Student where Dateofadm < {01/01/98};
(iv) Select SUM(Fee) from Student where Dateofadm < {01/01/98};
SOLUTION :
Write SQL commands for (a) to (f) and write output for (g).
(a) To show all information about the patients of Cardiology department.
(b) To list the names of female patients who are in Orthopedic department.
(c) To list names of all patients with their date of admission in ascending order.
(d) To display Patient’s Name, Charges, Age for Male Patients only.
(e) To count the number of patients with Age > 30.
(f) To insert a new row in the ‘Hospital’ table with the following data :
11, “Mustafa”, 37, “ENT”, {25/02/98}, 250, “M”
(g) Give the output of the following SQL statements:
(i) Select COUNT (distinct Department) from Hospital;
(ii) Select MAX(Age) from Hospital where Sex = “M”;
(iii) Select AVG(Charges) from Hospital where Sex = “F”;
Select SUM(Charges) from Hospital where Dateofadm < {12/08/98};
SOLUTION:
Book_Id Quantity_Issued
T0001 4
C0001 5
F0001 2
Write SQL commands for (a) to (f) and write output for (g).
(a) To show Book name, Author name and Price of Books of First Publ. publishers.
(b) To list the names from books of Text type.
(c) To display the names and price from Books in ascending order of their price.
(d) To increase the price of all books of EPB Publishers by 50.
(e) To display the Book_Id, Book_Name and Quantity_Issued for all books which have been issued. (The query
will require contents from both the tables.)
(f) To insert a new row in the table Issued having the following data : “F0003”, 1
(g) Give the output of the following SQL statements:
(i) Select COUNT (*) from Books;
(ii) Select MAX(Price) from Books where Quantity >= 15;
(iii) Select Book_Name, Author_Name from Books where Publishers = “EPB”;
(iv) Select COUNT(DISTINCT Publishers) from Books where Price >= 400;
SOLUTION:
(a) Select Book_Name, Author_Name, Price from Books where Publishers = “First Publ.”;
(b) Select Book_Name from Books where Type = “Text”;
(c) Select Book_Name, Price from Books order by Price;
(d) Update Books Set Price = Price + 50 where Publishers = “EPB”;
(e) Select Books.Book_Id, Book_Name, Quantity_Issued from Books, Issued where
Books.Book_Id = Issued.Book_Id
(f) Insert into Issued Values (“F0003”, 1);
(g) (i) 5 (ii) 65
(iii) Fast Cook Lata Kapoor
My First C++ Brian & Brooke
(iv) 3850
Table: Employee
Table: Department
Simple Select
2. Display the details of all the employees.
3. Display the Salary, Zone, and Grade of all the employees.
4. Display the records of all the employees along with their annual salaries. The Salary column of the table
contains monthly salaries of the employees.
5. Display the records of all the employees along with their annual salaries. The Salary column of the table
contains monthly salaries of the employees. The new column should be given the name “Annual Salary”.
Using NULL
9. Display the details of all the employees whose Grade is NULL.
10. Display the details of all the employees whose Grade is not NULL.
Using IN Operator
19. Display the names of all the employees who are working in department 20 or 30. (Using IN operator)
20. Display the names and salaries of all the employees who are working neither in West zone nor in Centre zone. (Using
IN operator)
Using BETWEEN Operator
21. Display the details of all the employees whose salary is between 32000 and 38000. (Using
BETWEEN operator)
22. Display the details of all the employees whose grade is between ‘A’ and ’C’
(Using BETWEEN operator)
29. Display the highest and the lowest salaries being paid in department 10.
30. Display the number of employees working in department 10.
40. Delete the records of all the employees of department 10 who are above 40 years of age.
41. Add another column HireDate of type Date in the Employee table.
DROP TABLE
44. Drop the tables Employee and Department.
Simple Select
4. Display the records of all the employees along with their annual salaries. The Salary column of the table contains monthly
salaries of the employees.
mysql> select no, name, zone, age, grade, dept, salary*12 'annual salary' from
employee;
+------+---------+--------+------+-------+------+---------------+
| no | name | zone | age | grade | dept | annual salary |
+------+---------+--------+------+-------+------+---------------+
| 1 | mukul | west | 28 | A | 10 | 360000 |
| 2 | kritika | centre | 30 | A | 10 | 420000 |
| 3 | naveen | west | 40 | NULL | 20 | 384000 |
| 4 | uday | north | 38 | C | 30 | 456000 |
| 5 | nupur | east | 26 | NULL | 20 | 384000 |
| 6 | moksh | south | 28 | B | 10 | 444000 |
| 7 | shelly | north | 26 | A | 30 | 432000 |
+------+---------+--------+------+-------+------+---------------+
7 rows in set (0.00 sec)
Conditional Select using Where Clause
6. Display the details of all the employees who are below 30 years of age.
mysql> select * from employee where age<30;
+------+--------+--------+-------+------+-------+------+
| no | name | salary | zone | age | grade | dept |
+------+--------+--------+-------+------+-------+------+
| 1 | mukul | 30000 | west | 28 | A | 10 |
| 5 | nupur | 32000 | east | 26 | NULL | 20 |
| 6 | moksh | 37000 | south | 28 | B | 10 |
| 7 | shelly | 36000 | north | 26 | A | 30 |
+------+--------+--------+-------+------+-------+------+
4 rows in set (0.02 sec)
Using NULL
9. Display the details of all the employees whose Grade is NULL.
mysql> select * from employee where grade is null;
+------+--------+--------+------+------+-------+------+
| no | name | salary | zone | age | grade | dept |
+------+--------+--------+------+------+-------+------+
| 3 | naveen | 32000 | west | 40 | NULL | 20 |
| 5 | nupur | 32000 | east | 26 | NULL | 20 |
+------+--------+--------+------+------+-------+------+
2 rows in set (0.00 sec)
10. Display the details of all the employees whose Grade is not NULL.
mysql> select * from employee where grade is not null;
+------+---------+--------+--------+------+-------+------+
| no | name | salary | zone | age | grade | dept |
+------+---------+--------+--------+------+-------+------+
| 1 | mukul | 30000 | west | 28 | A | 10 |
| 2 | kritika | 35000 | centre | 30 | A | 10 |
| 4 | uday | 38000 | north | 38 | C | 30 |
| 6 | moksh | 37000 | south | 28 | B | 10 |
| 7 | shelly | 36000 | north | 26 | A | 30 |
+------+---------+--------+--------+------+-------+------+
5 rows in set (0.00 sec)
12. Display the various department numbers from the table Employee. A department number should be displayed only once.
mysql> select distinct dept from employee;
+------+
| dept |
+------+
| 10 |
| 20 |
| 30 |
+------+
3 rows in set (0.00 sec)
15. Display the names and salaries of all the employees who are working neither in West zone nor in Centre zone.
mysql> select name, salary from employee where zone!='west' and zone!='centre';
+--------+--------+
| name | salary |
+--------+--------+
| uday | 38000 |
| nupur | 32000 |
| moksh | 37000 |
| shelly | 36000 |
+--------+--------+
4 rows in set (0.00 sec)
16. Display the names of all the employees who are working in department 20 or 30.
mysql> select name from employee where dept=20 or dept=30;
+--------+
| name |
+--------+
| naveen |
| uday |
| nupur |
| shelly |
+--------+
4 rows in set (0.00 sec)
17. Display the details of all the employees whose salary is between 32000 and 38000.
mysql> select * from employee where salary>32000 and salary<38000;
+------+---------+--------+--------+------+-------+------+
| no | name | salary | zone | age | grade | dept |
+------+---------+--------+--------+------+-------+------+
| 2 | kritika | 35000 | centre | 30 | A | 10 |
| 6 | moksh | 37000 | south | 28 | B | 10 |
| 7 | shelly | 36000 | north | 26 | A | 30 |
+------+---------+--------+--------+------+-------+------+
3 rows in set (0.00 sec)
18. Display the details of all the employees whose grade is between ‘A’ and ’C’.
mysql> select * from employee where grade between 'A' and 'C';
+------+---------+--------+--------+------+-------+------+
| no | name | salary | zone | age | grade | dept |
+------+---------+--------+--------+------+-------+------+
| 1 | mukul | 30000 | west | 28 | A | 10 |
| 2 | kritika | 35000 | centre | 30 | A | 10 |
| 4 | uday | 38000 | north | 38 | C | 30 |
| 6 | moksh | 37000 | south | 28 | B | 10 |
| 7 | shelly | 36000 | north | 26 | A | 30 |
+------+---------+--------+--------+------+-------+------+
5 rows in set (0.00 sec)
19. Display the names of all the employees who are working in department 20 or 30.
mysql> select name from employee
-> where dept in(20,30);
+--------+
| name |
+--------+
| naveen |
| uday |
| nupur |
| shelly |
+--------+
4 rows in set (0.00 sec)
20. Display the names and salaries of all the employees who are working neither in West zone nor in Centre zone.
mysql> select name,salary from employee
-> where zone not in('centre','west');
+--------+--------+
| name | salary |
+--------+--------+
| uday | 38000 |
| nupur | 32000 |
| moksh | 37000 |
| shelly | 36000 |
+--------+--------+
4 rows in set (0.00 sec)
21. Display the details of all the employees whose salary is between 32000 and 38000
mysql> select * from employee where salary between 32000 and 38000;
+------+---------+--------+--------+------+-------+------+
| no | name | salary | zone | age | grade | dept |
+------+---------+--------+--------+------+-------+------+
| 2 | kritika | 35000 | centre | 30 | A | 10 |
| 3 | naveen | 32000 | west | 40 | NULL | 20 |
| 4 | uday | 38000 | north | 38 | C | 30 |
| 5 | nupur | 32000 | east | 26 | NULL | 20 |
| 6 | moksh | 37000 | south | 28 | B | 10 |
| 7 | shelly | 36000 | north | 26 | A | 30 |
+------+---------+--------+--------+------+-------+------+
6 rows in set (0.01 sec)
22. Display the details of all the employees whose grade is between ‘A’ and ’C’.
mysql> select * from employee where grade between 'A' and 'C';
+------+---------+--------+--------+------+-------+------+
| no | name | salary | zone | age | grade | dept |
+------+---------+--------+--------+------+-------+------+
| 1 | mukul | 30000 | west | 28 | A | 10 |
| 2 | kritika | 35000 | centre | 30 | A | 10 |
| 4 | uday | 38000 | north | 38 | C | 30 |
| 6 | moksh | 37000 | south | 28 | B | 10 |
| 7 | shelly | 36000 | north | 26 | A | 30 |
+------+---------+--------+--------+------+-------+------+
5 rows in set (0.00 sec)
33. Display the details of all the employees in the ascending order of their grades and within grades in the
descending order of their salaries.
mysql> select * from employee order by grade asc, salary desc;
+------+---------+--------+--------+------+-------+------+
| no | name | salary | zone | age | grade | dept |
+------+---------+--------+--------+------+-------+------+
| 3 | naveen | 32000 | west | 40 | NULL | 20 |
| 5 | nupur | 32000 | east | 26 | NULL | 20 |
| 7 | shelly | 36000 | north | 26 | A | 30 |
| 2 | kritika | 35000 | centre | 30 | A | 10 |
| 1 | mukul | 30000 | west | 28 | A | 10 |
| 6 | moksh | 37000 | south | 28 | B | 10 |
| 4 | uday | 38000 | north | 38 | C | 30 |
+------+---------+--------+--------+------+-------+------+
7 rows in set (0.00 sec)
38. Increase the salary of all the employees above 30 years of age by 10%.
mysql> update employee set salary=(11/10*salary) where age>30;
Query OK, 2 rows affected (0.05 sec)
Rows matched: 2 Changed: 2 Warnings: 0
39. Delete the records of all the employees whose grade is C and salary is below 30000.
mysql> delete from employee where grade='C' and salary<30000;
Query OK, 0 rows affected (0.05 sec)
mysql> select * from employee;
+------+---------+--------+--------+------+-------+------+
| no | name | salary | zone | age | grade | dept |
+------+---------+--------+--------+------+-------+------+
| 1 | mukul | 30000 | west | 28 | A | 10 |
| 2 | kritika | 35000 | centre | 30 | A | 10 |
| 3 | naveen | 35200 | west | 40 | NULL | 20 |
| 4 | uday | 41800 | north | 38 | C | 30 |
| 5 | nupur | 32000 | east | 26 | NULL | 20 |
| 6 | moksh | 37000 | south | 28 | B | 10 |
| 7 | shelly | 36000 | north | 26 | A | 30 |
+------+---------+--------+--------+------+-------+------+
7 rows in set (0.02 sec)
40. Delete the records of all the employees of department 10 who are above 40 years of age.
mysql> delete from employee where dept=10 and age>=40;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from employee;
+------+---------+--------+--------+------+-------+------+
| no | name | salary | zone | age | grade | dept |
+------+---------+--------+--------+------+-------+------+
| 1 | mukul | 30000 | west | 28 | A | 10 |
| 2 | kritika | 35000 | centre | 30 | A | 10 |
| 3 | naveen | 35200 | west | 40 | NULL | 20 |
| 4 | uday | 41800 | north | 38 | C | 30 |
| 5 | nupur | 32000 | east | 26 | NULL | 20 |
| 6 | moksh | 37000 | south | 28 | B | 10 |
| 7 | shelly | 36000 | north | 26 | A | 30 |
+------+---------+--------+--------+------+-------+------+
7 rows in set (0.00 sec)
41. Add another column HireDate of type Date in the Employee table.
mysql> alter table employee add (Hiredate date);
Query OK, 7 rows affected (0.22 sec)
Records: 7 Duplicates: 0 Warnings: 0
mysql> select * from employee;
+------+---------+--------+--------+------+-------+------+----------+
| no | name | salary | zone | age | grade | dept | Hiredate |
+------+---------+--------+--------+------+-------+------+----------+
| 1 | mukul | 30000 | west | 28 | A | 10 | NULL |
| 2 | kritika | 35000 | centre | 30 | A | 10 | NULL |
| 3 | naveen | 35200 | west | 40 | NULL | 20 | NULL |
| 4 | uday | 41800 | north | 38 | C | 30 | NULL |
| 5 | nupur | 32000 | east | 26 | NULL | 20 | NULL |
| 6 | moksh | 37000 | south | 28 | B | 10 | NULL |
| 7 | shelly | 36000 | north | 26 | A | 30 | NULL |
+------+---------+--------+--------+------+-------+------+----------+
7 rows in set (0.00 sec)
VMC | Board Notes 78 Computer Science
Vidyamandir Classes
43. Display the Name and Department Name of all the employees.
mysql> select dname, name from department, employee where
department.dept=employee.dept;
+---------+---------+
| dname | name |
+---------+---------+
| sales | mukul |
| sales | kritika |
| finance | naveen |
| admin | uday |
| finance | nupur |
| sales | moksh |
| admin | shelly |
+---------+---------+
7 rows in set (0.00 sec)
mysql> exit;
e.g. (i) X X .Y
X. X Y
Vidyamandir Classes
(ii) (A + 0). A.1. A
A.1 A 0 A
X Y X Z A A
X Y .Z ∵X Y.Z X Y X Z
(c). Find maxterms of X .Y Y.Z
X .Y Y .Z X .Y Y X .Y Z ∵A BC A B . A C
X Y . Y Y . Z Y . Z X X Y . Y . Z Y . Z X
X Y Z . Z . Y X . X Z . Z . X . X Z Y . Y .Y X Z
X Y Z . X Y Z . X . X Y Z . X . X Y Z . Y Z X
Y Z X . Z X Y . Z X Y
A BC A B . A C
X Y Z . X Y Z . Z Y X . Z Y X . Z Y X . Z Y X
X Z Y X Z Y X Y Z X Y Z
Desired POS form (after removing duplicate terms)
(d) Convert this POS to SOP form.
X Y Z . X Y Z . X Y Z . X Y Z
F X Y Z . X Y Z . X Y Z . X Y Z
1 0 1 1 0 0 1 1 0 1 1 1
Vidyamandir Classes
= M5 M4 M6 M7
4, 5, 6, 7
XX
e). Idempotent law
(i) XX X (ii) X .X X
f). Absortion law
(i) X X .Y X
Algebric verification:
LHS X X .Y
X .(1 Y )
X .1 (∵1 A 1)
X (∵1.A A)
RHS =X
Hence verified
VMC | Board Notes 82 Computer Science
Vidyamandir Classes
(ii) X XY X Y
Algebric verification:
LHS X XY
( X X ).( X Y ) (∵ A B.C ( A B).( A C))
1.( X Y )
X Y (∵1.A A)
RHS X Y
Hence verified
g). Demoryan’s theorem
(i) X Y X Y (ii) X .Y X Y
Proof for Demorgan’s Theorem : -
(i) X Y X .Y
Let P = X + Y
Now, if P X Y X .Y
Then P P 1 and P.P 0
P P X Y X Y
X Y X .Y
( X X ).( X Y ) Y ( ∵ A + B.C = (A + B).(B + C))
1. X Y Y A A 1
X Y Y 1. A A & A A 1
=X+1=1 ∵1 A 1
P.P ( X Y ).( X Y )
( X Y ).( X .Y )
X . X .Y Y .Y . X (∵A.(B C) A.B A.C)
0.Y 0. X (∵A.A 0)
00 (∵0.A 0)
(ii) X .Y X Y
Let P X .Y
Now, if P X .Y X Y
Them P P 1 P.P 0
P P X .Y X .Y
X .Y X Y
( X X ).( X Y ) Y (∵ A B.C ( A B).( A C))
1.( X Y ) Y (∵A A 1)
X Y Y (∵1.A A) X 1 1 (∵1 A 1)
VMC | Board Notes 83 Computer Science
Vidyamandir Classes
P.P ( X .Y ).( X .Y )
( X .Y ).( X Y )
X .Y.X X .Y.Y (∵ A(B C) AB AC)
0.Y 0.X (∵A.A 0)
0 0 (0. A 0)
=0
Q. How do distributive law here diffuse from that of ordinary algebra?
A X .(Y Z ) X .Y X .Z holds good for all values of X,Y,Z in ordinary algebra.
But; X Y.Z ( X Y ).( X Z ) holds good only for two values (0,1) of (X,Y,Z).
Vidyamandir Classes
2. For POS expression.
Vidyamandir Classes
Chapter - 9 Networking
Network: Two or more computers are said to be in network if they can exchange data through some medium (wires,
wireless etc.)
Need for Networking :
(i) Resource Sharing
(ii) Reliability (if file on one system crashes, it could be retrieved from another PC)
(iii) Cost factor
(iv) Communication Medium
Application of Networking
(i) Sharing :
(a) Peripherals (Printers etc.)
(b) E-mails etc.
(c) Centrally controlled Network
(ii) Access to Remote Database
(iii) Communication Facilities
ARPANET : Advanced Research Project Agency Network
NSFnet : National Science Foundation network (more capable then ARPANET)
Internet : World wide network of Computer Network.
ARPANET :
ARPANET (Advanced Research Projects agency Network) is first Network
Developed in 1969 by U.S. Department Of Defense.
Goal was to connect Computers at different Universities and U.S. Defense.
Used by scientists, engineers, researchers and students for exchanging messages, data, share interests.
NSFnet :
High Capacity Network NSFnet developed in mid 80’s.
NSFnet developed by National Science Foundation.
Used For Academic Research
Internet (World Wide Network Of Computers) :
Private Companies built their own Networks
And this was termed as Internet
Later connected with ARPANET and NSFnet
ARPANET and NSFnet discontinued in 90’s
Made up of many networks each run by a different company and interconnected
Interspace :
It is Client/Server Software
Allows multiple users to communicate audio, video, text in dynamic 3D environments
Gateway : Device that connects dissimilar networks.
Backbone : Central interconnecting structure that connects one or more networks just like the trunk of tree or spine of
a human being.
TCP : Transmission Control Protocol
Responsible for dividing the file/message into small packets and reassembling them.
IP : Internet Protocol
Responsible for handling the address of destination computer so that each packet is routed to its proper destination.
Vidyamandir Classes
Inter Space : Client/Server software program that allows multiple users to communicate online with real-time audio,
video and text chat in dynamic 3D environments.
Server : Computer that facilitates the sharing of data, software, and hardware resources on the network.
(i) Dedicated Servers (ii) Non-Dedicated Servers
Switching Techniques
Circuit Switching Message Switching Packet Switching
Establishes Physical Connection Follows store and forward procedure Same as message switching with
between processes Process continues until the data reaches the only difference that there is
The data is sent and received its destination upper limit on the data that can be
Reserves bandwidth in advance Sends the data to switching office, sent
E.g. Telephone stored on the disk, which then sends it Same as message switching with
to next office the only difference that there is
No permanent physical connection upper limit on the data that can be
establishes sent
Improved performance as data
packets are stored on main
memory
Vidyamandir Classes
Disadvantages :
Expensive than twisted pair cable.
Optical Fibers :
Glass fibers are used as media to transmit the data in the form of light waves.
The glass fibers are covered in plastic jackets.
At the transmitting end of optical fiber, the laser or light emitting diodes are used and the receiving end has detectors
to detect the signal.
Advantages :
Immune to electrical and magnetic interference
High Transmission Capacity
Used for broadband applications
Disadvantages :
Expensive
Connecting two fibers is difficult
Installation is difficult
Micro Waves
Wireless media, which uses the microwaves to transfer the data.
Microwaves travel in the straight line and cannot penetrate the metal structure.
Microwave transmission requires the sender and receiver top be within line of sight.
The Microwave transmission is Terrestrial and Satellite.
Terrestrial Microwave :
High towers are installed with transmitter which is accurately aligned to the direction of receiver on the other tower.
Microwave media is much cheaper than the optical fiber.
Satellite Microwave :
It is used for long distance transmission. The earth station sends the signals to the satellite, which transmits it back to
another earth station.
Advantages :
Cheaper
Ease of communication over oceans and difficult terrains
Disadvantages :
Insecure communication
Bandwidth allocation is limited
Propagation is affected by weather like rain, thunderstorm.
Radio Wave :
Radio frequencies are available to business, private citizens for carrying voice signals over 10 miles of distance.
It has a transmitter and receiver both having antennas.
Advantages :
Cheaper
Ease of communication over difficult terrains
Disadvantages :
Insecure communication
Propagation is prone to weather effects
Vidyamandir Classes
Satellite :
Special case of microwave
It is used for long distance transmission
The earth station sends the signals to the satellite, which retransmits it back to another earth station after amplifying
it.
Advantages :
Large area coverage
Can be used for intercontinental communication
Disadvantages :
High investment cost
Overcrowding of bandwidths
Infrared : Secure Transmission.
Laser : Point-to-point transmission, adversely affected by weather.
Data Channel : Medium used to carry info/data from one point to another.
Baud : Unit of measurement for the info carrying capacity of Communication Channel.
Data transfer rates :
bps Bits per second
Bps Bytes per second
Kbps Kilo bits per second
KBps Kilo bytes per second
Bandwidth : Width of allocated band of frequencies to a channel
LAN : Local Area Network
MAN : Metropolitan Area Network
WAN : Wide Area Network
LAN (Local Area Network)
Connects computer with in a building or an organization.
Speed from 0.2 to 100 Mb/sec
Owned by single organization.
e.g Network in an office
MAN (Metropolitan Area Network)
Connects the computer with in a town or city.
Covers area up to 50 km.
Not generally owned by single organization.
e.g. Cable TV Network
WAN (Wide Area Network)
Connects the computers at larger distances
Like states, countries and continents.
Not owned by single organization.
e.g. Internet
Vidyamandir Classes
Topologies :
Pattern of connecting the computers.
Factors on which topology chosen depends are:
Cost minimize installation cost
Flexibility: Easy to extend
Reliability: Easy fault detection
Different Topologies are:
Bus
Star
Ring
Tree
STAR TOPOLOGY : Consists of central node to which all other nodes are connected
Advantages :
Ease of Service One device per connection
Centralized control/Problem diagnosis Simple access protocols.
Disadvantages :
Long cable length Difficult to expand
Central Node Dependency
BUS TOPOLOGY : Consists of single cable on which all the nodes are connected
Advantage :
Short cable length Simple wiring layout
Resilient Architecture Easy to extend
Disadvantage :
Fault Diagnosis Difficult Fault Isolation Difficult
Nodes must be intelligent Repeater Configuration
RING/CIRCULAR TOPOLOGY : Nodes are connected in the form of ring. Each node is connected to two
neighboring nodes.
Advantage :
Short Cable Length Suitable for Optics Fibres
No wiring closet space req.
Disadvantage :
Node failure causes network failure
Difficult to Diagnose faults
Network re-config. is difficult
TREE TOPOLOGY : Modified form of bus topology. Forms inverted tree like structure.
Advantage :
Easy to extend i.e. new nodes can be added easily.
Fault isolation is easy.
Disadvantage :
If the root node fails, whole network is down.
Vidyamandir Classes
Modem : Modulator Demodulator
Computer peripheral that allows to connect one Computer with other via telephone lines.
Telephone lines carries the analog signals. Modem is a device that can convert the digital signals to analog
signals.(i.e. modulation) and convert that signals back to digital (i.e. demodulation)
Modem is the device that converts digital signals to analog and vice-versa.
RJ-45 : Registered Jack-45, it is 8 wired connector for connecting in Ethernet LAN
Computers that are part of Ethernet, have to install a special card called Ethernet Card. It has connections for Co-
axial (BNC), twisted (RJ 45) or optical Fiber (AUI)
Hub : Hardware device used to connect several computers together. Hub ranges in size from four to several hundred
ports
Three types of Hub :
Active Hub: This type of Hub regenerates the signal before forwarding them.
Passive Hub: This type of Hub combines the signals of different network segments and forwards without
regenerating.
Intelligent Hub: This type of Hub regenerates the signal as well as chooses the path to send the signals.
Switch : Device used to segment networks into different sub-networks called LAN segments. Filters the data i.e.
transforms the data for forwarding packets
Repeater : Device that amplifies & restores signals for long distance transmission.
Bridge : Network device that establishes an intelligent connection between two local networks with the same
standard but diff. type of cables.
Router : Network device to separate diff. segments is a network to improve performance and reliability.
A Router works like a bridge but can handle different protocols.
NIC : Network Interface Card.
Ethernet : LAN Architecture by Xerox corp. in association with DEC & Intel.
Protocol : Formal description of message formats & rules that 2 or more machines must follow to exchange those
messages.
HTTP : Hypertext Transfer Protocol
Set of rules for transferring hypertext on www
FTP : File Transfer Protocol
Standard for exchange of files across Internet.
Datagram : Collection of the data that is sent as a single message.
SLIP : Serial Line Internet Protocol
For delivering IP packets over dialup lines.
PPP : Point to Point Protocol
For transmitting IP packets over several lines.
GSM : Global System for Mobile Communication.
SIM : Subscriber Identification Module
TDMA : Time Division Multiple Access
CDMA : Code Division Multiple Access
WLL : Wireless in Local Loop.
3G : Third Generation of mobile technology.
UMTS : Universal Mobile Telecommunications System
EDGE : Enhanced Data rates for Global Evolution
Telnet : It is an Internet utility that lets you log onto remote computer system.
URL : Uniform Resource Locator
Unique address of a web site.
Vidyamandir Classes
Web Browser is a www client that navigates through the World Wide Web and displays web pages.
Web Server is a www server that responds to the requests made by web browsers
An Internet address which is character based is called a Domain Name.
POP3 : Post Office Protocol version 3
SMTP : Simple Mail Transfer Protocol
NNTP : Network News Transfer Protocol
A location on a net server is called Web Site
A document that uses HTTP is called a Web Page
Web Hosting : Means of hosting web-server application on a computer system through which electronic content on
the Internet is readily available to any web browser client.
Web 2.0 refers to added features and applications that make the web more interactive, support easy online info
exchange and interoperability.
HTML : Hypertext Markup Language
XML : eXtensible Markup Language
DHTML : Dynamic HTML
Script : List of commands embedded in a web-page scripts are interpreted and executed by a certain program or
scripting engine.
Client Side Scripts : Downloaded at the client end
Eg. : VB Script, Java Script, Hypertext Preprocessor (PHP)
Server Side Scripts : Enables completion/carrying out a task at server end and sending the results to client-end.
Eg. : JSP (Java Server Pages), ASP (Active Server Pages)
Perl, PHP (same as the of Client side)
OSS : Open Source Software
FOSS : Free and Open Source Software
FLOSS : Free Livre and open source software
Both free and open source software
GNU : GNU’s Not Unix
GNU Project emphasizes on Freedom.
FSF : Free software foundation
OSI : Open source Initiative
W3C : World wide web consortium
Responsible for producing the software standards of www
Proprietory Software : Neither open nor freely available software.
Freeware : Free of Cost, Allows copying and further distribution BUT not modification
Eg.: Microsoft Internet Explorer.
Shareware :
(i) Source code is not available
(ii) Modifications to the software not allowed
Cookies : Messages that a web server transmits to a Web Browser so that the web server can keep track of the user’s
activity on a specific web site.
Crackers : Malicious programmers who break into secure systems.
Hackers : Interested in gaining knowledge about computer system and possibly using this knowledge for playful
pranks.
Computer Virus : Malicious program that requires a host and is designed to make a system sick, just like real virus.
Trojan Horse : Code hidden in a program such as a game or spreadsheet that looks safe to run but has hidden side
effects.
Vidyamandir Classes
Worm is a program designed to replicate.
Spam : Electronic Junk Mail/Newsgroup postings.
ICMP : Internet control message protocol.
IMAP : Internet mail access protocol.
VoIP : Voice over IP refers to a way to carry telephone calls over an IP data network. It offers a set of facilities to
manage the delivery of voice info over Internet in digital form.
NFS : Network File System.
TCP/IP
It is set of protocols that govern how data should flow across the network.
Internet is based on TCP/IP
It is the standard for the majority of networks
It has only four layers:
Application layer
Transport layer
Internet layer
Network Access layer
TCP: Breaks the data into packets, verifies it and reassembles.
IP: Envelopes the addresses, forwards to data to destination.
FTP( File Transport Protocol)
This protocol which enables files to be transferred between computers.
Files of any type can be transferred.
Works on client/server process.
Files are transferred in compressed mode.
PPP (Point to Point Protocol)
Transmits IP packets over serial lines e.g. telephones
Enables home users to avail internet access for their own PC.
It handles error detection, supports multiple protocols, permits authentication.
Enables to run GUI based browser, ftp client for ones PC.
Wireless/Mobile Computing
Wireless is transferring the information between a computing device, without the use of landlines. It involves cellular
phones, laser or satellite communication.
Mobile computing means computing device which is not always connected to central network like PDA, cell phones ,
laptop.
GSM
GSM Stands for Global System for Mobile communications
GSM is fully digital system.
This technique uses narrowband TDMA, which allows eight simultaneous calls on the same radio frequency.
SIM (Subscribers identity module)
It is a chip that gives cellular device its unique phone no.
It has memory for storing data and applications, processor, and ability to interact with the user.
Used in GSM mobile phones
Vidyamandir Classes
CDMA (Code division Multiple Access)
Every channel uses full available spectrum.
The conversations are encoded with a pseudo random digital sequence.
Each users signal is spread over entire bandwidth.
The signals are spread over the spectrum with Unique spreading code, which is also used at the receivers end for
recovering the data.
WLL (Wireless in Local Loop)
It connects subscribers to the Public switched telephone network using radio signals as a substitute for other
connecting media.
WLL uses advanced transmission techniques that permits support a large subscriber bases.
3G and EDGE
Analog cellular were first generation mobile phones, digital were the second generation.
3G is third generation mobile phones, that work over wireless air interfaces such as GSM, CDMA.
Enhanced Data Rates For Global Evolution i.e EDGE is radio based high speed mobile data standard to meet the
requirements of 3G.
EDGE
Enhanced Data Rates For Global Evolution i.e EDGE is radio based high speed mobile data standard to meet the
requirements of 3G.
A broadband packet based transmission of text, digitized voice, video, and multimedia
Data rates up to and possibly higher than 2Mbps
Offers set of services to mobile computers and phones anywhere in the world.
Web Hosting : Means hosting the web server application on a computer system through which electronic content on
the internet is available to web browser client.
Various Web hosting services are:
Free Hosting \ Dedicated Hosting
Virtual or Shared Hosting Collocation Hosting
Dedicated Hosting
Company wishing to go online, rents an entire web server from hosting company.
It is for large, high traffic sites with special needs as ecommerce.
Co- Location
Company owns the server on which the site is hosted.
Company owning the site is responsible for all server administration.
Free Hosting
Web Pages are hosted for no cost.
E.g. geocities, tripod, homestead etc.
Virtual Hosting
This hosting is provided under one’s own domain e.g http://www.yourname.com/www.yourname.com
Access and update to the site and its file are secured.
HTML (Hyper Text Markup Language)
Used for writing web pages
This language tells the web browsers how to display the text , pictures, and links on the screen.
It provides various tags for alignment, headings , lines, hyper linking etc.
Vidyamandir Classes
XML (eXtensible Markup Language)
It is a language for creating documents containing structured information.
XML specification defines a standard way to add markup to documents.
Difference in HTML and XML
In HTML, both tag and semantics are fixed but not in XML.
XML is meta language, it provides facility to tags and structural relationship between them.
DHTML (Dynamic HTML)
Refers to new tags that will enable a web page to react to users input without sending requests to the web server.
It allows the web page to change after it is loaded into the web browser.
It is animated HTML.
Network Security Concepts
To make sure that only legal or authorized users can gain access to information.
Problems encountered under network security are:
Physical security holes
Software security Holes
Inconsistent Usage Holes
Physical security holes:
Individual gains unauthorized access to computer.
Software security Holes:
Badly written programs or privileged s/w are compromised into doing things that it should not do.
Inconsistent Usage Holes:
System is seriously flawed from security point of view while combination of H/w and S/w.
Protection Methods:
Authorization: It confirms that the service requester is entitled to perform the operation or not. Login id is provided
for this
Authentication: ensures each entity in web service is what it actually claims to be. It is Password protection.
Encrypted Smart Cards
It is hand held smart card that can generate a token for a computer to understand. Every time new token is generated.
Biometric Systems :
Some unique aspect of human body such as finger prints, retinal patterns etc. is used to establish identity.
Firewall :
It is a system designed to prevent unauthorized access to or from a private network.
Can be implemented on both Hardware and Software.
Used to prevent Internet users to access Internet.
It also protects external systems against attacks originating from your network.
Cookies
Cookies are messaging that a web server transmits to a web server so that the web server can keep track of users
activity on a specific web site.
Its main purpose is to identify the user and prepare customized web pages.
Cookies cannot read hard drive, cannot be used to prevent viruses.
Vidyamandir Classes
The personal info. like credit card nos. etc. will be stored on the cookie unless you turn cookie off.
Client Side Scripting Server Side Scripting
Script Code is downloaded and executed at client The script is executed at the server-end and the
end. result is sent to the client end.
Response to interaction is more immediate once Complex Processes are more efficient as the
the program code has been downloaded. program and associated resources are not
Services are secure as they do not have access to downloaded to the browser.
files and databases. Have access to files and databases but have security
Browser dependent. considerations when sending sensitive information.
Affected by the processing speed of user’s Does not depend on browsers.
computer. Affected by the processing speed of host server.
Block A Block C
Block B Block D
Number of Computers
Block A 25
Block B 50
Block C 125
Block D 10
Vidyamandir Classes
Sol. (i)
Block A Block C
Block B Block D
(ii) Block C. The most suitable plane/block to house the server of this organisation would be Block C, as this
block contains the maximum number of computers, thus decreasing the cabling cost for most of the
computers as well as increasing the efficiency of the maximum computers in the network.
(iii) (a)
Block B Block D
(b) In both the layouts, a hub/switch each would be needed in all the blocks, to interconnect the group
of cables from the different computers in each block.
Block A Block C
Hub Repeate Hub
Block B Block D
Hub Hub
(iv) The most economic way to connect it with a reasonable high speed would be to use radius wave
transmission, as they are easy to install, can travel long distances and penetrate buildings easily, so they are
widely used for communication, both indoors and outdoor. Radio waves also have the advantage of being
omni directional, which is they can travel in all the directions from the source, so that the transmitter and
receiver do not have to be carefully aligned physically.
Vidyamandir Classes
2. Ravya Industries has set up its new centre at Kaka Nagar for its office and web based activities. The company
compound has 4 buildings as shown in the diagram below:
Raj Fazz
Building Building
Harsh Jazz
Building Building
Sol. (i)
Raj Fazz
Building Building
Harsh Jazz
Building Building
Vidyamandir Classes
(ii) The most suitable place / block to house the server of this organisation would be Raj Building, as this block
contains the maximum number of computers, thus decreasing the cabling cost for most of the computers as
well as increasing the efficiency of the maximum computers in the network.
(iii) (a) Raj Building since it contains largest number of computers.
(b) In the suggest layout, a hub/switch each would be needed in all the buildings, to interconnect the
group of cables from the different computers in each block.
(iv) The type of network that shall be formed to link the sale counters situated in various parts of the same city
would be a MAN, because MAN (Metropolitan Area Networks) are the networks that link computer
facilities within a city.
3. Quick Learn University is setting up its Academic blocks at Prayas Nagar and planning to set up a network. The
university has 3 academic blocks and one Human Resource Centre as shown in the diagram below:
Business Technology
Block Block
Law HR
Block Block
(i) Suggest the most suitable place (i.e., Block / Center) to install the server of this university with a suitable
reason.
(ii) Suggest an ideal layout for connecting these blocks/centre for a wired connectivity.
(iii) Which device you will suggest to be placed/installed in each of these blocks/centre to efficiently connect all
the computers with in these blocks/centre?
(iv) The university is planning to connect its admission office in the closest big city, which is more than 250 km
form university, which type of network out of LAN, MAN or WAN will be formed ? Justify your answer.
Vidyamandir Classes
Sol.: (i) HR Centre because it has the most number of computers.
(ii)
Business 30 Technology
Block Block
15
40
Law HR
Block Block
(iii) Switch
(iv) WAN because LAN and MAN cannot cover 250 km.
4. Freshminds University of India is starting its first campus in Ana Nagar of South India with its centre admission
office in Kolkata. The university has 3 major blocks comprising of Office Block, Science Block and Commerice
Block in the 5 km area Campus.
As a network expert, you need to suggest the network plane as per (i) to (iv) to the authorities keeping in mind the
distance and other given parameters.
Freshminds University
Commerce
Ana Nagar Campus
block
Office
block
Kolkata
Admission Science
Office block
(i) Suggest the authorities, the cable layout amongst various blocks inside university campus for connecting the
blocks.
(ii) Suggest the most suitable place (i.e., block) to house the server of this university with a suitable reason.
(iii) Suggest an efficient device from the following to be installed in each of the blocks to connect all the
computers :
MODEM SWITCH GATEWAY
Vidyamandir Classes
(iv) Suggest the most suitable (very high speed) service to provide data connectivity between Admission Office
looted in Kolkata and the campus located in Ana Nagar from the following options :
Telephone line Fixed – Line Dial – up connection
Co-axial Cable Network GSM
Leased line Satellite Connection
Sol. (i)
Freshminds University
Commerce
Ana Nagar Campus
block
Office
block
Science
block
Wing Wing
Z Y
Wing Wing
X U
(i) Suggest the most suitable cable layout of connection between the Wings and topology.
(ii) Suggest the most suitable paper (i.e., Wing) to house the server of this organisation
(iii) Suggest the placement of the following devices with justification
(a) Repeater (b) Hub/Switch
Vidyamandir Classes
(iv) The organization is planning to link its head office situated in Delhi with the offices compromise on the
speed of connectivity. Justify your answer.
Sol. (i) Bus Topology
Wing Wing
Z Y
Wing Wing
X U
(ii) The most suitable place to house the server is Wing Y as it has the most number of computers thus
cabling cost will be reduced and most traffic will be local.
(iii) (a) As per suggested layout separate repeaters need not be installed as each building/wing will be
having a hub that acts a repeater.
(b) One hum per wing
Wing Wing
Hub Z Hub Y
Hub Hub
Wing Wing
X U
(iv) An economic way of connecting is Dial-up or broadband as it can connect two computers at an
economic rate through it provides lesser speed than other expensive methods.