Procedure Oriented Programming

 

Procedure oriented programming is a set of functions. In this program Clanguage is used. To perform any particular task, set of function are compulsory. For example , a program may involve collecting data from user, performing some kind of calculation on that data and printing the data on screen when is requested. Calculating, reading or printing can be written in a program with the help of different functions on different tasks.

POP method also emphases the functions or the subroutines.

Structure of POP method

Here is some problems in POP method like its difficult to handling data because it gives no importance to data.  Dat means the information that are collected from user and after calculation new result come. If any one is familiar with C programming than he may recollect storage classes in C.  In C, data member is declared GLOBAL in order to make 2 or more functions in the program. What happen when 2 or functions on the same data member. For example,  when if there are 7 functions in a program and this become a global data member. Unfortunately,  if the value of any global data member or that may key element than it will affect the whole program. It is a big problem to identify that which function is causing the problem.

Handling of data & functions in POP

One of the most important feature of C language is structure. Programmer use integer data, decimal point data(float), array data pack together  into single entity by using structure. The reason of the popularity of structure was introduced first by c language.

Object Oriented Programming

An OOP method differs from POP in its basic approach itself. All the best features of structured of OOP is developed by retaining the programming method, in which they have added number of concepts which makes efficient programming. Object oriented programming methods have number of features and it makes possible an entirely new way of approaching a program. We have to mind first that OOP retains all best features of POP method like functions/sub routines, structure etc.

Read also  Legal Concepts In A Business Setting Information Technology Essay

1) The first feature that any programmer would talk about OOP is “data hiding” facility. Programmer can hide the important core data from external world by using OOP method. The basic concept of OOP revolves around a feature similar to structure in POP, named as class in OOP.. Data members can be declared as private or public inside a class.  Programmer have to note that a class is really similar to structure in ‘C’. Due to same structure, a class packs together different things into a single entity.

2) Another important feature of OOP is ‘code reusability‘. The simple means of code reusability is just that the code is written earlier in program or read or used it later.  This is made possible by a feature of classes named “inheritance”. By using inheritance, one class can acquire the properties of another class. Let i will try to explain this using an example. Take the example of a “School Management System” and management decided to make software based on the data of  students only. The programmer made the software and deciding to collecting personal details like Name, Age, Sex, Address etc. After one year school management decides to incorporate data of teachers to the software. The programmer can add this extension within a small time as he can reuse many of the codes he had written earlier by making use of “inheritance“. The class personal details is of general nature (Age, Sex etc are same for every person irrespective of student/teacher). ( CircuitsToday, 2015)

C codes

#include<stdio.h>

Read also  Lottery Program Java

#include<stdlib.h>  //1

FILE *fpgagan;  //the actual students file

FILE *fp1gagan; //temporary file

    struct st_record

    {

        int id;

        char fname[20];

        char lname[20];

        char class_name[20];

        char address[40];

        char phone[12];

        char email[20];

    };

    struct st_record s1;

void main()

{

    menu();

}

menu()

{

    int choice;

    printf(“nPress 1 to create a new record”);

    printf(“nPress 2 to edit an existing record”);

    printf(“nPress 3 to search records”);

    printf(“nPress 4 to delete a record”);

    printf(“nPress 5 to exit this p

program n”);

    scanf(“%d”, &choice);

    if(choice == 1)

    {

        create_fn();

    }

    else if(choice == 2)

    {

        edit_fn();

    }

    else if(choice == 3)

    {

        search_fn();

    }

    else if(choice == 4)

    {

        delete_fn();

    }

    else if(choice == 5)

    {

        exit_fn();

    }

    else

    {

        printf(“nPlease enter the correct choice”);

        menu();

    }

}

create_fn()

{

    printf(“nStudent ID :”);

    scanf(“%d”, &s1.id);

    printf(“nFirst name :”);

    scanf(“%s”, &s1.fname);

    printf(“nLast name :”);

    scanf(“%s”, &s1.lname);

    printf(“nClass name :”);

    scanf(“%s”, &s1.class_name);

    printf(“nAddress :”);

    scanf(“%s”, &s1.address);

    printf(“nPhone :”);

    scanf(“%s”, &s1.phone);

    printf(“nEmail :”);

    scanf(“%s”, &s1.email);

    fpgagan=fopen(“students.txt”,”a+”);  //3

    fprintf(fpgagan,”n%dt%st%st%st%st%st%s”,s1.id,s1.fname,s1.lname,s1.class_name,s1.address,s1.phone,s1.email); //4

    fclose(fpgagan);

    menu();

}

edit_fn()

{

    printf(“nThis is the edit function”);

    int id1,found;

    found = 0;

    printf(“nPlease enter the Student ID :”);

    scanf(“%d”, &id1);

    if((fpgagan=fopen(“students.txt”,”r”))==NULL)

        {

            printf(“Empty”);

        }

        else

        {

            fp1gagan=fopen(“students1.txt”,”a+”);

            while(!feof(fpgagan)&& found==0)

                {

                fscanf(fpgagan,”n%dt%st%st%st%st%st%s”,&s1.id,&s1.fname,&s1.lname,&s1.class_name,&s1.address,&s1.phone,&s1.email);

                if(s1.id==id1) {

                    found=1;

                     printf(“nStudent record found.”);

                     printf(“n%dt%st%st%st%st%st%s”,s1.id,s1.fname,s1.lname,s1.class_name,s1.address,s1.phone,s1.email);

                     printf(“nEnter the new details now”);

                     printf(“nStudent ID :”);

                     scanf(“%d”, &s1.id);

                     printf(“nFirst name :”);

                     scanf(“%s”, &s1.fname);

Read also  The Basics Of Designing A Network Information Technology Essay

                     printf(“nLast name :”);

                     scanf(“%s”, &s1.lname);

                     printf(“nClass name :”);

                     scanf(“%s”, &s1.class_name);

                     printf(“nAddress :”);

                     scanf(“%s”, &s1.address);

                     printf(“nPhone :”);

                     scanf(“%s”, &s1.phone);

                     printf(“nEmail :”);

                     scanf(“%s”, &s1.email);

                     fprintf(fp1gagan,”n%dt%st%st%st%st%st%s”,s1.id,s1.fname,s1.lname,s1.class_name,s1.address,s1.phone,s1.email);

                     continue;

                    }

                else {

                        fprintf(fp1gagan,”n%dt%st%st%st%st%st%s”,s1.id,s1.fname,s1.lname,s1.class_name,s1.address,s1.phone,s1.email);

                }

                }

                fclose(fpgagan);

                fclose(fp1gagan);

                remove(“students.txt”);

                rename(“students1.txt”,”students.txt”);

        }

       if(found!=1)

       {

         printf(“Not found”);

         getch();

       }

    menu();

}

search_fn()

{

    int id1,found;

    found = 0;

    printf(“nPlease enter the Student ID :”);

    scanf(“%d”, &id1);

    if((fpgagan=fopen(“students.txt”,”r”))==NULL)

        {

            printf(“Empty”);

        }

        else

        {

            while(!feof(fpgagan)&& found==0)

                {

                fscanf(fpgagan,”n%dt%st%st%st%st%st%s”,&s1.id,&s1.fname,&s1.lname,&s1.class_name,&s1.address,&s1.phone,&s1.email);

                if(s1.id==id1)

                    found=1;

                }

        }

       if(found==1)

       {

         printf(“nStudent record found.”);

         printf(“n%dt%st%st%st%st%st%s”,s1.id,s1.fname,s1.lname,s1.class_name,s1.address,s1.phone,s1.email);

       }

       else

       {

         printf(“Not found”);

         getch();

       }

       menu();

}

delete_fn()

{

    printf(“nThis is the delete function”);

    int id1,found;

    found = 0;

    printf(“nPlease enter the Student ID :”);

    scanf(“%d”, &id1);

    if((fpgagan=fopen(“students.txt”,”r”))==NULL)

        {

            printf(“Empty”);

        }

        else

        {

            fp1gagan=fopen(“students1.txt”,”a+”);

            while(!feof(fpgagan)&& found==0)

                {

                fscanf(fpgagan,”n%dt%st%st%st%st%st%s”,&s1.id,&s1.fname,&s1.lname,&s1.class_name,&s1.address,&s1.phone,&s1.email);

                if(s1.id==id1) {

                    found=1;

                     printf(“nStudent record found.”);

                     printf(“n%dt%st%st%st%st%st%s”,s1.id,s1.fname,s1.lname,s1.class_name,s1.address,s1.phone,s1.email);

                     printf(“nRecord deleted”);

                     continue;

                    }

                else {

                        fprintf(fp1gagan,”n%dt%st%st%st%st%st%s”,s1.id,s1.fname,s1.lname,s1.class_name,s1.address,s1.phone,s1.email);

                }

                }

                fclose(fpgagan);

                fclose(fp1gagan);

                remove(“students.txt”);

                rename(“students1.txt”,”students.txt”);

        }

       if(found!=1)

       {

         printf(“Not found”);

         getch();

       }

    menu();

}

exit_fn()

{

     printf(“nThis is the exit function”);

}

Here we are recording three students  record

In this screen short we are able to see the record of the students

In this screen shot we try to editing the record

Here we can see the change in the record.

Here we try to delete the record

And in this screen shot only one record is left

CircuitsToday. (2015). Retrieved from Difference between Procedure Oriented(POP) and Object Oriented Programming(OOP): http://www.circuitstoday.com/difference-between-procedure-oriented-and-object-oriented-programming

Order Now

Order Now

Type of Paper
Subject
Deadline
Number of Pages
(275 words)