Friday, 27 July 2012

Generate Auto Id


Logic to generate unique id -

Create a table in the database named tbl_id and set the fields (the number of unique id’s to be generated. For Example – In Computer rental system, there is a need to generate id for both the customer and the Computer. So, two fields one for the customer and second for the computer must be set / defined. One thing to make sure is that the data type of fields must be Number)

Set the default value to 1000. (Depending on the requirement if the user wants that the id must start from 1 set the default values to 1)

On the form or the web page where unique need to be generated a select query need to be written in which the field value from the table tbl_id need to be selected. For Example – In case of customer id, select the customer_id field value from the table tbl_id by writing a query like this – SELECT customer_id from tbl_id.

Store the result obtained from this query in a variable of type integer. Now if the user wants that the id must be in a suitable format such as CS – 1000, or CUS – 1000 or whatever the format is just concatenating the prefix required with this variable. (make sure that concatenation does not change the value of the variable.

On the click of the save button or key depending on the programming language or the way the action is being performed update the value of the variable by adding 1 to it and update this variable value again in the tbl_id customer_id field.

Wednesday, 25 July 2012

Computer Rental System in Visual Basic.NET



Introduction to Java

This post has been created to present a quick overview of Java, what exactly are the features Java and writing your first Hello World Program in Java (compiling it and executing it).

Genesis of Java Language


C and C++ are the programming languages that provides a basis for Java. Java derives its syntax from C and object oriented features from C++. Later in this chapter we will discuss the reasons and the section of events that lead to the creation of Java. 

Programming Language innovation occurs to solve a fundamental problem that the preceding languages were not able to solve and java is no different.  

C Programming Evolution -


In early 1970's there was a need of a structured programming language that could replace the assembly code when creating system programs.This lead to the creation of C that shocked the programming world. Even today its power cannot be underestimated. Operating Systems like LINUX, UNIX are coded in C. Various factors need to be considered before using a programming language such as -
  • Ease of Use vs. Power
  • Safety vs. Efficiency
  • Rigidity vs. Extensibility
Before C Language, options available to programmers were FORTRAN, BASIC, COBOL, ASSEMBLY LANGUAGE. While one was easy to make scientific applications but not system programs, other was easy to learn but not powerful. They were not even structured to. GOTO was the primary means of program control (resulting in a lot of spaghetti code). While language like PASCAL was structured they were not designed for efficiency, PASCAL was not considered for systems-level code.



Sunday, 22 July 2012

Constructor/Method outside the class

Defining a constructor/method outside the class - 

      For defining a constructor or method outside the class four things should be kept in mind - 
    1. Return Type
    2. Class Name
    3. Scope Resolution Operator
    4. Constructor/Method name

Note - Constructors/Destructors don't have a return type, so while defining constructors/destructors outside the class return type is not specified.

Syntax - (return type) (class name)(scope resolution operator)(constructor/method name)

For Example - Consider the definition of class student that a constructor, method and destructor.

class student
{
    private : 
              int id ;
    public :
              student ( );
              void add_student ( );
              ~student ( );
}


Implementing constructor student ( ) outside the class -
student : : student ( )
{
}


Implementing method add_student ( ) outside the class - 
void student : : student ( )
{
}


Implementing destructor student ( ) outside the class - 
student : : ~student ( )
{
}



Saturday, 21 July 2012

Structured Query Language : Database Language

SQL - 

             SQL is known as Structured Query Language (pronounced as S-Q-L) was developed by IBM in mid-1970's. It’s a non-procedural language (i.e. one does not have to specify all the steps required to perform a action).
It’s an international language used for querying and creating relational databases (database that stores data in the form of tables i.e. rows and columns) and the most common SQL standard is SQL-92 (standard is known as SQL-92 because the standard was approved in 1992).However the standards SQL-99 extensions are used by most vendors.

SQL CLASSIFICATION - 

              SQL command can be divided into 3 categories - 

  1. DDL 
  2. DML
  3. DCL
DDL is referred as Data Definition Language. It generally includes commands that are used for defining  a database i.e. creating, altering, dropping database, tables and establishing constraints such as primary-foreign key constraints. For Example - 
  • CREATE command is used to create a database or table. CREATE DATABASE db_admin.
  • DROP command can be used for various purposes such as deleting a database,  table or an index. DROP DATABASE db_admin.


DML is referred as Data Manipulation Language. It generally includes commands that are used for maintaining and querying a database i.e. inserting, deleting, searching or updating a record in a table. For Example - 


  • INSERT command is used to insert a new record in the table in database. INSERT INTO tbl_admin VALUES ('a','b').
  • SELECT command is used to select and view a record depending in the way query is used. SELECT * FROM tbl_admin.
DCL  is referred as Data Control Language. It generally includes commands that are used to control a database i.e. administering, privileges and committing data. For Example -
  • GRANT is used to allow specified users to perform specified tasks. GRANT SELECT ON TABLE tbl_admin TO PUBLIC.
  • REVOKE to cancel previously granted or denied permissions. REVOKE CREATE TABLE FROM testing. (testing is a role)

Thursday, 19 July 2012

Decimal Number to hexadecimal number in C


Steps to convert Decimal number into Hexadecimal number - 


  1. Divide the decimal number by 16. Treat the division as an integer division.
  2. Write down the remainder (in hexadecimal, ie. if the remainder is 12, write down "C").
  3. Divide the result again by 16. Treat the division as an integer division.
  4. Repeat step 2 and 3 until result is less than 1.
  5. The hexadecimal value is the digit sequence of the remainders from the last to first. (So if you had 001, it's 100.)

Sample Output - 



Code - 


/* Program to convert Decimal number into Hexadecimal number */

#include<stdio.h>

#include<conio.h>

int main()
{
int decimal_number = 0, temp_number = 0, remainder = 0, counter = 0, i  = 0, value = 0;

char hexadecimal_number[10];

printf("\n\t __ Program to convert Decimal number into Hexadecimal number __");

printf("\n\n\n  Enter the Decimal Number - ");

scanf("%d",&decimal_number);

temp_number = decimal_number;

while(temp_number > 1)
{
remainder = temp_number % 16;

temp_number = temp_number / 16;

value = 0;

if (remainder >= 0 && remainder <= 9)
{
value = 48;

for ( i = 1; i <= remainder; i ++)
{
value = value + 1;
}
}
else if (remainder >= 10 && remainder <= 15)
{
value = 65;

for ( i = 11; i <= remainder; i ++)
{
value = value + 1;
}
}

hexadecimal_number[counter] = (char)value;

counter++;
}

printf("\n\n  Hexadecimal Conversion of %d (base 10) is ", decimal_number);

for( i =  counter - 1 ; i >= 0; i -- )
{
printf("%c", hexadecimal_number[i]);
}

printf(" (base 16)");

getch();

return 0;
}

Tuesday, 17 July 2012

Deadlock


In a multiprogramming environment, several processes may compete for a finite number of resources. Generally a process may utilize the resource in the following fashion –

ð  Request for a resource
ð  Use the resource
ð  Release the resource

But in an Operating System sometimes a situation might occur when a process enters a waiting state because a resource requested by it is being held by another process, which in turn is waiting for another resource. The above situation is known as Deadlock.

Note - If a process is unable to change its state indefinitely because the resources requested by it are being used by other waiting process, then the system is said to be in a deadlock.

Question – What can be a resource?
Answer – A resource can be anything that can only be used by a process at any instant of time.

Deadlock is a common problem in –  Multiprocessing systems,  Parallel computing,  Distributed systems

Necessary conditions for Deadlock – A deadlock situation might arise if the following conditions are held simultaneously in the system –
  1. Mutual Exclusion
  2. Hold and Wait
  3. No - Preemption
  4. Circular Wait

Sunday, 15 July 2012

Java Programming language



What is Java?
JAVA is an object oriented programming language (OOPS) which simulates the real world object in the Programming world. It is a computing platform first released by sun Microsystems in 1995. Java runs on more than 850 million personal computers worldwide, and on billions of devices worldwide, including mobile and TV devices. 

Why should we study JAVA?
Java is a platform independent language. It is free to use. Millions of developers are there to help us when we need any help on this platform. It is safe and secure to use. We can develop our own application and sell it in the market that too without any licensing charges for the language. It has been developed very much since 1995 and many other frameworks have been added to Java ex. Spring, Hibernate etc. Today mobile based applications are being developed on Android whose base is Java. There are many reasons to choose Java apart from these.





Simple Hello World Program in Java

public class HelloWorld{
            public static void main(String args[]){
                        System.out.println("Hello World!!");
                        }
}
Instructions –
  1. Save the file with name HelloWorld.java
  2. Compile it with javac HelloWorld.java 
  3. And run it using java HelloWorld.

Saturday, 14 July 2012

Why C Language ?




C Programming language –
            C Programming language developed at Bell Laboratories of USA is a general purpose programming language initially developed by Dennis Ritchie in 1972 and later replaced programming languages of those times including PL/I, ALGOL etc.
There were few reasons why C became more popular as compared to programming languages of that time including FORTRAN, because it was reliable, simple and easy to code. One must learn C language before jumping to other object oriented programming languages such as C++, C#, Java because of the following reasons –
  1. One must learn the actual language elements before jumping to advance concepts including classes, objects, inheritance, polymorphism, templates, exception handling etc because learning these difficult elements without knowing the actual programming elements is learning the things in wrong order.
  2. Operating systems such as Windows, UNIX, and LINUX are all written in C language which itself defines its importance. Even today nothing can strike C when execution speed becomes a factor. Device driver programs are also written in C.


Floyd's Triangle in C

Floyds's triangle - 

 Its is a right-angled triangular array of natural numbers , used in computer science education. It is named after Robert Floyd. It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner: 

1
2 3
4 5 6
7 8 9 10



Sample Output -



Code -


/* C program to print Floyd's triangle:- This program prints Floyd's triangle. Number of rows of Floyd's triangle to print is entered by the user. First four rows of Floyd's triangle are as follows :-
1
2 3
4 5 6
7 8 9 10
It's clear that in Floyd's triangle nth row contains n numbers. */

#include<stdio.h>

#include<conio.h>

int main()
{
    int number_rows = 0, rows = 0, coloumn = 0, number = 1;

    printf("\n\n\t\t __ Program to print Floyd's Triangle in C __");

    printf("\n\n\n  Enter the number of Rows - ");

    scanf("%d",&number_rows);

    printf("\n\n");

    for(rows = 1; rows <= number_rows; rows++)
    {
        printf("\t");

        for(coloumn = 1; coloumn <= rows; coloumn++)
        {
            printf("%d ", number);
           
            number++;    //__ Number variable represents the numbers to be printed ___
        }

        printf("\n\n");
    }

    getch();

    return 0;

}



Friday, 13 July 2012

Program to check for Vowel in C


Sample Output - 



Code - 


/* Program to check whether an input alphabet is a vowel or not */

/* Both if statement or switch case can be used */

#include<stdio.h>

#include<conio.h>

int main()
{
    char input_character;

    printf("\n\n\t __ Program to check for vowel or consonant (Using if Statement) __");

    printf("\n\n\n  Enter the Character - ");

    scanf("%c",&input_character);

    /*__ Another way of scanning the character is to use

        input_character = getchar();

    Note - a,e,i,o,u in english character set are known as Vowels */

    if ((input_character == 'o') || (input_character == 'O') || (input_character == 'a') || (input_character == 'A') || (input_character == 'e') || (input_character == 'E') || (input_character == 'i') || (input_character == 'I') || (input_character == 'u') || (input_character == 'U'))
    {
        printf("\n\n\t\t\t __ %c is a Vowel __ ",input_character);
    }
    else
    {
        printf("\n\n\t\t\t __ %c is a Consonant __",input_character);
    }

    getch();

    return 0;

    /* return 0 tells the compiler that the program has
   
                executed successfully without any error */
}




Sample Output - 



Code - 


/* Program to check whether an input alphabet is a vowel or not */

/* Both if statement or switch case can be used */

#include<stdio.h>

#include<conio.h>

int main()
{
    char input_character;

    printf("\n\n\t __ Program to check for vowel or consonant (Using Switch) __");

    printf("\n\n\n  Enter the Character - ");

    scanf("%c",&input_character);

    /*__ Another way of scanning the character is to use

        input_character = getchar();

    Note - a,e,i,o,u in english character set are known as Vowels */

    switch(input_character)
    {
   
    case 'a':
    case 'A':
    case 'e':
    case 'E':
    case 'i':
    case 'I':
    case 'o':
    case 'O':
    case 'u':
    case 'U': printf("\n\n\t\t\t __ %c is a Vowel __ ",input_character);
        break;

    default : printf("\n\n\t\t\t __ %c is a Consonant __",input_character);
   
    }

    getch();

    return 0;

    /* return 0 tells the compiler that the program has
   
                executed successfully without any error */
}



Thursday, 12 July 2012

Program to calculate factorial of a number using recursion in C


Sample Output -




Code -



/* Program to calculate Factorial of a number using Recursion */

/* Recursion is a programming technique that allows the programmer to express operations in terms of themselves.

   In C/C++, this takes the form of a function that calls itself. */

#include<stdio.h>

#include<conio.h>

int factorial(int number);

int main()
{
int number = 0, result = 0;

printf("\n\n\t __ Program to calculate the factorial of a number using Recursion __");

printf("\n\n\n  Enter the Number - ");

scanf("%d",&number);

result = factorial(number);

printf("\n\n\t Factorial of %d = %d",number, result);

getch();

return 0;

/*___ return 0 tells the compiler that program has executed

successfully without any error */
}

int factorial(int number)
{
if (number == 1) //__ Condition that will stop the infinite looping __
{
return 1;
}
else
{
return number * factorial (number - 1); //__ Recursion __
}
}

Program to add Binary numbers in C




Sample Output -





Code - 



/* Program to add two binary numbers (No validation included) */

/* Program is a combination of 3 programs

1. Decimal to Binary
2. Binary to Deimal
3. Binary Numbers addition

*/

//___ Including header files ____

#include<stdio.h>

#include<conio.h>

#include<math.h>

int binary_decimal(int binary_number);

int decimal_binary(int decimal_number);

int main()
{
int bi_number_first = 0, bi_number_second = 0, de_number_first = 0, de_number_second = 0, sum = 0;

printf("\n\n\t\t  _____ Program to add two binary numbers_____");

printf("\n\n\t\t\t ___ No Validations included __");

printf("\n\n  Enter the first binary number  - ");

scanf("%d", &bi_number_first);

printf("\n\n  Enter the second binary number - ");

scanf("%d", &bi_number_second);

de_number_first = binary_decimal(bi_number_first);

de_number_second = binary_decimal(bi_number_second);

sum = de_number_first + de_number_second;

sum = decimal_binary(sum);

printf("\n\n\t\t  Sum of %d and %d is %d", bi_number_first, bi_number_second, sum);

getch();

return 0;
}

int binary_decimal(int binary_number)

//__ Function to convert binary number to decimal number __

{
int decimal_number = 0, remainder = 0, counter = 0;

while(binary_number != 0)
{
remainder = binary_number % 10; //___ Extracting the digits ____

binary_number = binary_number / 10; //__ Creating a new number ____

decimal_number = decimal_number + remainder * pow(2,counter);

          //___ Forming the decimal number __

counter++;
}

return decimal_number;

}

int decimal_binary(int decimal_number)

//__ Function to convert decimal number to binary number __

{
int remainder = 0, binary_number = 0, counter = 1;

while(decimal_number != 0)
{
remainder = decimal_number % 2;

decimal_number = decimal_number / 2;

binary_number = binary_number  + remainder * counter ;
 
                //__ Forming the binary number __

counter = counter * 10;
}

return binary_number;
}

Student Management System in C



Sample Output - 

First Screen (About System) - 




Navigational Menu - 





Stay Tuned will be updated every 15 minutes........

Code Coming later in the evening according to Indian Time.......

Program to convert Binary Number into Decimal Number in C


Sample Output - 





Code - 


/* Program to convert Binary number into Decimal number (No Validations Included)*/

//___ For Full Logic visit another post named "Convert Decimal to Binary/Binary to Decimal" ___

#include<stdio.h>

#include<conio.h>

#include<math.h> //__ Included for the pow(x,y) function __

/* To find out the implementation of the pow(x,y) function
check out post "One number raise to power another number in C" */

int main()
{
int decimal_number = 0, binary_number = 0, temp_number = 0, remainder = 0, counter = 0;

printf("\n\n\t   __ Program to convert Binary number into Decimal number __");

printf("\n\n\t\t\t __ No Validation Included __");

printf("\n\n\n  Enter the Binary Number - ");

scanf("%d",&binary_number); //__ Reading the binary number ___

temp_number = binary_number;

//__ Creating a copy of the binary_number inputted for diaplying purposes __

while(binary_number != 0)
{
remainder = binary_number % 10; //___ Extracting the digits ____

binary_number = binary_number / 10; //__ Creating a new number ____

decimal_number = decimal_number + remainder * pow(2,counter);
    
               //___ Forming the decimal number above __

counter++;
}

printf("\n\n  Decimal Conversion of Binary Number %d (BASE 2) is -- %d (BASE 10)", 

temp_number, decimal_number);

getch();

return 0;

/* return 0 tells the compiler that program has executed successfully without any errors */
}



Object Oriented Features (C++)



Objects -

In structured programming language a problem is approached by dividing it into functions however in object-oriented programming the problem is divided into objects. An object is a component of a program that can have its own set of data and can be used to perform more than a repeated task. Designing the system with objects allowed developer to model system after the real world.
For Example – The developer has created an object of the student class to store data associated with a single student using member data and can perform certain operations using this object such as adding a new student, listing a student, checking whether a particular student record exist or not using the member functions of the class.
The object has been defined using the class name and object name with the following format –
void student_module()
{
      student student_record;                  

// ............CREATING THE OBJECT OF THE STUDENT CLASS.............
     
      char ch,che;
      int count = 0;
There are many candidates that are treated as objects in the system which are students, books, and administrator.


Inheritance - 


As C++ allowed developer to create its own data types (classes) just like built in data types, C++ allowed the developer to use classes as building blocks of other classes using a concept called inheritance, new classes are built on top of the old ones. The new class referred to as a derived class, can inherit the data and functions of the original or the base class and can add its own data elements and functions.
For Example – The developer has designed a class named login as base class and inherited the class in the admin as well as student class as both student and admin need to login in the system. Data member for login class is a structure named login info having structure elements username and password, and a virtual member function system login. Both the admin and student class inherited login class and added its own data member’s admin name, structure student information etc.
The base class is inherited in the derived classes in following format –
Base Class –
class login
{
public:
            struct log_info{
                  int username;
                  char password[20];
            }log;

//__________PURE VIRTUAL FUNCTION______________ 

      virtual int system_login() = 0;    
     
};
Derived Classes –
class admin: public login          

//.........ADMIN CLASS INHERITING THE LOGIN CLASS..............
{
      private:
            char admin_name[20];
            char flag;
            fstream file;

      public:
            admin();
            int system_login(); //overriding
            void addrec();
};
class student: public login   //______INHERITANCE________
{
      public:
      struct student_information{

            char flag;
            int roll_number;
            char student_name[20];
            char course[20];
            char branch[16];
            int book_code;

            char issue_date[10], return_date[10];
            int fine;
            }b;

      private:
            fstream file;

      public:
            student();
            int system_login();
            void addrecUser();
            void addrec();
            void listrec();
            void delrec();
            void modrec();
            int check_record(int student_roll_number, int check_information);
            int check_exist( int student_roll_number);  //overloading 
            void Uprec();
            int  GetRoll();        
//______________FOR RANDOMLY GENERATING THE STUDENT ROLL NUMBER_____________

};