Monday, February 15, 2010

Sorting a Structure of Multiple Keys

C Program that accepts a set of 5 records for students -

Ask user to enter name, age and height of a student. Sort these records in ascending order of their names. If the names are alike then sort according to their age.

/* Sorting of a structure of multiple keys. */

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

struct stud
{
      char name[25] ;
      int age ;
      float height ;
} ;

void main( )
{
      int i, j, choice ;
      struct stud s[5], temp ;

      float ff ( float ) ;

      clrscr( ) ;

      printf ( "Enter student's name, age and height in cm :-\n") ;
      for ( i = 0 ; i  < = 4 ; i++ )
      {
            fflush ( stdin ) ;
            gets ( s[i].name ) ;
            scanf ( "%d %f", &s[i].age, &s[i].height ) ;
      }

      clrscr( ) ;

      for ( i = 0 ; i  < = 3 ; i++ )
      {
            for ( j = 0 ; j  < = 3 - i ; j++ )
            {
                  if ( strcmp ( s[j].name, s[j + 1].name )  > = 0 )
                  {
                        if ( strcmp ( s[j].name, s[j + 1].name ) == 0 )
                        {
                              if ( s[j].age  >  s[j + 1].age )
                              {
                                    temp = s[j] ;
                                    s[j] = s[j + 1] ;
                                    s[j + 1] = temp ;
                              }
                        }
                        else
                        {
                              temp = s[j] ;
                              s[j] = s[j + 1] ;
                              s[j + 1] = temp ;
                        }
                  }
            }
      }

      printf ( "Records after sorting :-\n") ;
      printf ( "Students Name\t\tAge Height\n" ) ;

      for ( i = 0 ; i  < = 4 ; i++ )
      {
            printf ( "%-20s %2d %.2f\n", s[i].name, s[i].age, s[i].height ) ;
      }

      getch( ) ;
}

float ff ( float f )
{
      float *f1 = &f ;
    return *f1 ;
}

So, how is that for a Tutorial?

Monday, November 30, 2009

Relationships in RDBMS

The relationship in a RDBMS refers to the relation which exists between data of one table and data of another table. There are three kinds of relationships:

1. One to One relationship: In a normalized table, preference should always be given to one-one relationship. This means that a particular column in a table should have a one-to-one relationship with the primary key. In other words, if we know the value of the column we will immediately know the value of the primary key.

2. Many to one or one to many relationship: This refers to the relation between a single primary key and many foreign keys or a single foreign key and many other primary keys. In such relationships, a table is present where each key column of the different tables are included.

3.Many to many relationship - An example of such a relationship is a supplier supplying different parts and a part being supplied by different suppliers. In such cases, a third table is created which will hold the supplier as well as the parts tables’ columns.

What is Normalization: Basics of Relational Databases

Normalization is a design procedure which provides a method for representing data and their relationships precisely in a tabular format that makes database easy to understand and operationally efficient.

Advantages of normalization -

1. Reduced data redundancy - Data redundancy means the repetition of data in a table. This is undesirable since data maintenance becomes a tedious job as more and more records are added to the table.

2.Protection against update and delete anomalies - Update and delete anomalies: The tables which are normalized will contain primary and foreign keys. To maintain data integrity and referential integrity constraints, RDBMS instructs us to insert primary key values into a table at any given point of time but foreign keys can be inserted into any table if and only if the corresponding primary key value is already existing. This helps in maintaining data integrity and referential integrity constraints.

Similarly, with delete anomalies a primary key value will be deleted unconditionally only if any dependencies does not exist for that key.

3.Smaller tables - A table will be split into many smaller tables when it is normalized

Wednesday, September 2, 2009

Any Faithful Followers?

Hi,

It has been quite sometime that i updated this blog, sorry about that!

Coders i am back in action and now i will start the series of XML and PL/SQL Tutorials.

Keep your comments coming and you can also find interesting updates on my new web technology blog and tech blog too

Next post coming in few hours :)

Saturday, April 11, 2009

Handy JavaScript Code Snippet to float a block of code

Here's a handy JavaScript Code Snippet to float a block of code, you can particularly use this piece of code to float your ad-blocks to left or right!

< div style="display:inline; padding:5px; margin:0 0 0 10px;border:1px solid #fff >

/* your business logic goes here */

< /div >