Month: September 2014

Normalization

Posted on Updated on

Boyce-Code Normal Form (BCNF)

  • A relationship is said to be in BCNF if it is already in 3NF and the left hand side of every dependency is a candidate key.
  • A relation which is in 3NF is almost always in BCNF. These could be same situation when a 3NF relation may not be in BCNF the following conditions are found true.
  1. The candidate keys are composite.
  2. There are more than one candidate keys in the relation.
  3. There are some common attributes in the relation
Professor Code Department Head of Dept. Percent Time
P1 Physics Ghosh 50
P1 Mathematics Krishnan 50
P2 Chemistry Rao 25
P2 Physics Ghosh 75
P3 Mathematics Krishnan 100

Consider, as an example, the above relation. It is assumed that:

  1. A professor can work in more than one department
  2. The percentage of the time he spends in each department is given.
  3. Each department has only one Head of Department.
  4. The relation diagram for the above relation is given as the following:

 

Untitled

The given relation is in 3NF. Observe, however, that the names of Dept. and Head of Dept. are duplicated. Further, if Professor P2 resigns, rows 3 and 4 are deleted. We lose the information that Rao is the Head of Department of Chemistry.

The normalization of the relation is done by creating a new relation for Dept. and Head of Dept. and deleting Head of Dept. form the given relation. The normalized relations are shown in the following.

Professor Code Department Percent Time
P1 Physics 50
P1 Mathematics 50
P2 Chemistry 25
P2 Physics 75
P3 Mathematics 100

 

Department Head of Dept.
Physics Ghosh
Mathematics Krishnan
Chemistry Rao

See the dependency diagrams for these new relations.

y1

 

 

 

 

 

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

Advertisements

COMPOSITION AND INHERITANCE

Posted on Updated on

  • In real-life, complex objects are often built from smaller, simpler objects. For example, a car is built using a metal frame, an engine, some tires, a transmission, a steering wheel, and a large number of other parts.
  • A PC is built from a CPU, a motherboard, some memory, etc. This process of building complex objects from simpler ones is called composition (also known as object composition).
  • Composition is used for objects that have a has-a relationship to each other.
  • A car has-a metal frame, has-an engine, and has-a
  • A personal computer has-a CPU, a motherboard, and other components.
  • Composition is nothing but relationships between the different objects. Sometimes Object made up from another objects like Airplane is Wings, Landing gears, engines etc. this relationship is called composition
  • Inheritance is extends one class to another class like

Public class A

{//Here methods and variable etc.}

public class B:A

{//here methods and properties variable etc}

public static void main()

{B b = new B();

b.method();

b.Variable ..}

 INHERITANCE

  • One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application.
  • This also provides an opportunity to reuse the code functionality and fast implementation time.
  • When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived
  • The idea of inheritance implements the is a For example, mammal IS-A animal, dog IS-A mammal hence dog IS-A animal as well

            Base & Derived Classes:

  • A class can be derived from more than one class, which means it can inherit data and functions from multiple base classes.
  • To define a derived class, we use a class derivation list to specify the base class. A class derivation list names one or more base classes and has the form:

class derived-class: access-specifier base-class

  • Where access-specifier is one of public, protected, or private, and base-class is the name of a previously defined class. If the access-specifier is not used, then it is private by default.
  • Consider a base class Shape and its derived class Rectangle as follows:

#include <iostream.h>
// Base class
class Shape
{ public:
voidsetWidth(int w)
{ width = w; }
voidsetHeight(int h)
{ height = h; }
protected:
int width;
int height;};
// Derived class
class Rectangle: public Shape
{ public:
intgetArea()
{ return (width * height); }};
void main()
{ Rectangle Rect;
Rect.setWidth(5);
Rect.setHeight(7);
// Print the area of the object.
cout<< “Total area: ” <<Rect.getArea() <<endl;}

      When the above code is compiled and executed, it produces the following result:

 Total area: 35

 Total paint cost: $2450

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com