Search This Blog

Monday, 16 September 2013

Data Models in SQL

Data Models: Data models represents the arrangements and orgnisation of data in various forms, this helps us to understand how various entities related with each other and helps to implement in computer's memory.

1) Object based model : This represents the data, entities , attributes in pictorial form such as ER-Diagram.

2) Record based model : This represnets the data,entities, attributes in the form records, this manages by a special type of software called database management system(DBMS).

There are three types of record based model:

1)Hierachical Model: In hierachical data model data or entities are represented in the form of tree model. Here one to many relationship exists. One entity can relate with many entity and further each child entity relates with other many entities. There is only one entity that can be called root which is at the top of tree. There can be only one path from the root to any child entity or data.



2) Network model : In network data model data or entities are represented in the form of graph. Here many to many relationship exists. Many entities relate with many related entities. Here each entity can be treated as a node of graph one entity may connects with various entities. There can be multiple paths to visit a node from any other node.

3) Relational model : This model represents the records in the form of relation, a relation is also called a table. A table is collection of various rows and columns. Attributes are called columns in relational model. The total number of columns is called degree of the table/relation. The total number of rows of table is called cardinality. Here all the values of one column belongs to same domain. A domain is a set of rules.



Schema and Instances :
Schema : A schema is the over all defination of a database. This defines various database objects such as tables, columns, relationships, constraints, keys, fuctions, procedures etc. Schema can be created at the time of database creation. Schema is rarely modified. The details of schema is stored in metadata and data dictionary. Metadata is data about data. Schema uses DDL(Data Definition Language).


Instances: Instances are values of database objects. In a database table instances are rows. Instances are always modified by users. This uses DML(Data Manipulation Language).


Sunday, 15 September 2013

Print Pyramid through C++

Pyramid in C++

#include<iostream.h>
#include<conio.h>

main()
{
   int a,b,i,temp;
   cout<<"Enter the level of pyramid:";
   cin>>a;
   temp=a;
   for(i=1;i<=a;i++)
   {
      for(b=1;b<=temp;b++)
      cout<<" ";
      temp--;
      for(b=1;b<=2*i-1;b++)
      cout<<"*";
      cout<<endl;
   }
   getch();
} 

Output 

Binary to Octal Conversion in C++

Digital Conversion From Binary 2 Octal

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<math.h>

void main()
{
  int ar[10],n,j=0,sum=0,dec,i=0;
  cout<<"Enter the binary value:";
  cin>>n;
  while(n>0)
  {
    sum=sum+n%10*pow(2,j);
    j++;
    n=n/10;
  }
  dec=sum;
  while(dec>0)
  {
    ar[i]=dec%8;
    i++;
    dec=dec/8;
  }
 cout<<"octal value is:";
 for(int k=i-1;k>=0;k--)
 {
    cout<<ar[k];
 }
  getch();
}

Output

Binary to Decimal in C++

Digital Conversion from Binary 2 Decimal

#include<iostream.h>
#include<conio.h>

void main()
{

  char ch;
  do
  {
  int n,rem,sum=0,j=1;
  cout<<"\nEnter the binary value:";
  cin>>n;
  while(n>0)
  {
   rem=n%10;
   sum+=rem*j;
   j*=2;
   n=n/10;
  }
  cout<<"\nDecimal value is:"<<sum;
  cout<<"\nDo u want to continue:";
  cin>>ch;
 }while(ch!='0');
  getch();
}
output

Character Count in a String by C++

Total Characters in a String

#include<iostream.h>
#include<conio.h>
#include<string.h>

void main()
{
  char ch[30];
  int cons=0,alpha=0,digit=0;
  cout<<"Enter a alphanumeric string:";
  cin>>ch;
  int k=strlen(ch);
  for(int i=0;i<k;i++)
  {
     int a=ch[i];
     if(a>=33&&a<=47||a>=58&&a<=64)
     cons++;
     else if(a>=48&&a<=57)
     digit++;
     else
     alpha++;
  }
  cout<<"Given stringis:"<<ch<<endl;
  cout<<"Special character is:"<<cons<<endl;
  cout<<"Digits are:"<<digit<<endl;
  cout<<"characters are:"<<alpha;
  getch();
}
output

Concept of Friend Function in C++

Friend Function of C++

#include<iostream.h>
#include<conio.h>

class fri
{
   int a,b;
   public:
       void input(int x,int y)
       {
          a=x;
          b=y;
        }
        friend int add(fri t)
        {
           int sum;
           sum=(t.a+t.b);
           cout<<"Sum is:"<<sum;
        }
};

void main()
{
   fri r;
   r.input(2,8);
   add(r);
   getch();
}

output

Checking a number is Armstrong or not in C++

Concept of Armstrong in C++

#include<iostream.h>
#include<conio.h>

void main()
{
 int n,rem,sum=0,temp;
 cout<<"Enter a number:";
 cin>>n;
 temp=n;
 while(n>0)
 {
   rem=n%10;
   sum=sum+rem*rem*rem;
   n=n/10;
 }
 if(temp==sum)
   cout<<"Entered number is a armstrong";
 else
 cout<<"Entered number is not armstrong";

 getch();
}

output



Wednesday, 11 September 2013

Arithmatic Operation in C#

Concept of Arithmatic Operator in C#

using System;

class Operators
{
    public static void Main(String[] args)
    {
        int a,b,c,d;
        Console.WriteLine("ARITHMATIC OPERATION\n");
        do{
            Console.WriteLine("Enter 1st no for arithmatic operation\n");
            a=Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter 2nd no for arithmatic operation\n");
            b=Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Choose from the following for operation:\n");
            Console.WriteLine("1.+\t2.-\n3.*\t4.%\n");
            c=Convert.ToChar(Console.ReadLine());
            switch(c)
            {
                case '1':d=a+b;
                       Console.WriteLine("Sum is:{0}",d);
                       break;
                case '2':d=a-b;
                       Console.WriteLine("difference is:{0}",d);
                       break;      
                case '3':d=a*b;
                       Console.WriteLine("product is:{0}",d);
                       break;      
                case '4':d=a%b;
                       Console.WriteLine("remainder is:{0}",d);
                       break;   
                                                                                       
            }
        }while(c!=5);
        Console.ReadLine();
    }
}

output: 


    

BST in C#

Binary Search Tree in C#

using System;

public class Node
{
    public int data;
    public Node left;
    public Node right;

    public Node(int data)
    {
        this.data = data;
        left = null;
        right = null;
    }
}

public class BST
{
    Node root, newNode;
    int n,tNode;
    bool flag;
    public BST()
    {
        root = null;
        newNode = null;
        tNode=0;
    }

    public void Add(Node current)
    {
        if (current.data > newNode.data)
        {
            if (current.left != null)
            {
                current = current.left;
                Add(current);
            }
            else
                current.left = newNode;
        }
        else if (current.data <= newNode.data)
        {
            if (current.right != null)
            {
                current = current.right;
                Add(current);
            }
            else
                current.right = newNode;
        }
    }

    public void Insert()
    {
        Console.Write("Enter a number : ");
        n = Convert.ToInt32(Console.ReadLine());
        newNode = new Node(n);
        if (root == null)
            root = newNode;
        else
        {
            Add(root);
        }
    }

    public void PostOrder(Node root)
    {
 
        if (root.left != null)
            PostOrder(root.left);
        if (root.right != null)
            PostOrder(root.right);
        Console.Write(root.data + "\t");
    }
   
    public void countNode(Node root)
    {
        if (root.left != null)
            countNode(root.left);
        if (root.right != null)
            countNode(root.right);
        tNode++;
    }
   
    public void leaf()
    {
       if(root!=null)
       {
         leafCount(root);
         Console.Write("Total leaf node is:"+tNode);
       }
       else
       Console.Write("List is empty");
    }
   
    public void leafCount(Node root)
    {
       if(root.left!=null)
         leafCount(root.left);
       if(root.right!=null)
         leafCount(root.right);
       if(root.right==null && root.left==null)
       {
         tNode++;
       } 
    }
   
     public void interNode()
     {
       if(root!=null)
       {
         internalNodes(root);
         Console.Write("Total internal nodes:"+tNode);
       }
       else
       Console.WriteLine("List is empty");
     }
     public void internalNodes(Node root)
     {
        if(root.left!=null)
         internalNodes(root.left);
        if(root.right!=null)
         internalNodes(root.right);
        if(!(root.right==null && root.left==null))
        {
           tNode++;
        }
     }
    
     public void search()
    {
       if(root!=null)
       {
         flag=false;
         Console.Write("Enter the value for searching:");
         n=Convert.ToInt32(Console.ReadLine());
         searchElement(root);
         if(flag)
         {
           Console.WriteLine("Element found");
         }
         else
         Console.Write("Element not found");
       }
       else
       Console.WriteLine("List is empty");
    }
    public void searchElement(Node root)
    {
      
        if (root.left != null)
           searchElement(root.left);
        if (root.right != null)
            searchElement(root.right);
            if(root.data==n)
            {
                flag=true;
            }   
    }
   
    public void previous()
    {
     
      if(root!=null)
      {
        Console.Write("Element for dislay:");
        n=Convert.ToInt32(Console.ReadLine());
        searchPrevious(root);
        if(flag==true)
        {
          Console.Write("Element found");
          Console.Write("\nCurrent Element is : "+cur.data);         
          Console.Write("\nPrevious Element is : "+pre.data);
        }
        else
        Console.Write("Element not found");
      }
      else
      Console.WriteLine("List is empty");
    }
   
    Node cur=null,pre=null;
    public void searchPrevious(Node root)
    {
     
      if(root.left!=null)
      {
         pre=root;
         cur=root.left;
       if(root.data==n)
       {
         flag=true;
       }
         searchPrevious(root.left);
      }
      if(root.right!=null)
      {
         pre=root;
         cur=root.right;
      if(root.data==n)
      {
         flag=true;
      }
         searchPrevious(root.right);
      }
   
    }
   
   
    public void totalNodes()
    {
       if(root!=null)
       {
         flag=false;
         Console.Write("Enter the value for counting nodes:");
         n=Convert.ToInt32(Console.ReadLine());
         Node s=nodeTotal(root);
         if(flag && s!=null)
         {
           tNode=0;        
                       countNode(s);      
           Console.Write("Total nodes="+(tNode-1));
         }
         else
         Console.WriteLine("Element not found");
       }
       else
       Console.WriteLine("List is empty");
    }
   
    Node found=null;
    public Node nodeTotal(Node root)
    { 
        if (root.left != null)
           nodeTotal(root.left);
        if (root.right != null)
            nodeTotal(root.right);
            if(root.data==n)
            {
                flag=true;
                found=root;
                return found;
            }   
            else
              return found;
    }
   
    public void count()
    {
      if(root!=null)
        countNode(root);
      Console.Write("\ntotal nodes ="+tNode); 
    }
   
    public void leftCount()
    {
       if(root!=null)
       {
           tNode=0;
           countLeft(root.left);
           Console.WriteLine("Total nodes in the left of root : "+tNode);
       }
       else       
       {
         Console.WriteLine("List is empty");
       }
    }
    public void countLeft(Node root)
    {
       if(root.left!=null)
          countLeft(root.left);
       if(root.right!=null)
          countLeft(root.right);
       tNode++;
    }
    public void rightCount()
    {
       if(root!=null)
       {
           tNode=0;
           countRight(root.right);
           Console.WriteLine("Total nodes in the right of root : "+tNode);
       }
       else       
       {
         Console.WriteLine("List is empty");
       }
    }
    public void countRight(Node root)
    {
       if(root.left!=null)
          countLeft(root.left);
       if(root.right!=null)
          countLeft(root.right);
       tNode++;
    }
   
    public void PreOrder(Node root)
    {
        Console.Write(root.data + "\t");
        if (root.left != null)
            PreOrder(root.left);
        if (root.right != null)
            PreOrder(root.right);
    }

    public void InOrder(Node root)
    {
        if (root.left != null)
            InOrder(root.left);
        Console.Write(root.data+"\t");
        if (root.right != null)
            InOrder(root.right);
    }
    public void Display()
    {
        if (root != null)
        {

            Console.WriteLine("\nPreOrder Traversal");
            PreOrder(root);
            Console.WriteLine("\nInOrder Traversal");
            InOrder(root);
            Console.WriteLine("\nPostOrder Traversal");
            PostOrder(root);
        }
        else
            Console.WriteLine("BST is empty");
    }
    public static void Main(String[] args)
    {
        BST b = new BST();
        int k;
        char ch;
        do
        {
            Console.Write("=======Menu=====");
            Console.Write("\n1.Insert\n2.display\n3.Count Node\n4.Search\n5.Total Left Nodes Of Root"
            +"\n6.Total right Nodes Of Root\n7.Total Nodes Of Any Element\n8.Total Leaf Node\n9.Internal Nodes\n10.Show Previous element\n11.Exit\n");
            Console.Write("Choose your option:");
            k = Convert.ToInt32(Console.ReadLine());
            if (k == 1)
                b.Insert();
            else if (k == 2)
                b.Display();
            else if(k==3)
              b.count();
            else if(k==4)
              b.search();
            else if(k==5)
            b.leftCount() ;
            else if (k==6)
            b.rightCount();
            else if(k==7)
            b.totalNodes();
            else if(k==8)
            b.leaf();
            else if(k==9)
            b.interNode(); 
            else if(k==10)
            b.previous();
            else
                break;
            Console.Write("\nDo u want to continue(y/n):");
            ch = Convert.ToChar(Console.ReadLine());
            Console.Clear();
        } while (ch == 'y' || ch == 'Y');
    }
}


output







Popular Posts