Vous êtes sur la page 1sur 36

INTRODUCTION TO ‘C’

C is a general-purpose computer programming language developed in 1972


by Dennis Ritchie at the Bell Telephone L aboratories for use with the
Unix operating system.[2]

Although C was designed for implementing system software, it is also


widely used for developing portable application software.

C is one of the most popular programming languages[4][5] and there are only a
few computer architectures for which a C compiler does not exist. C has
greatly influenced many other popular programming languages, most
notably C++, which originally began as an extension to C.

C is an imperative (procedural) systems implementation language. It was


designed to be compiled using a relatively straightforward compiler, to
provide low-level access to memory, to provide language constructs that
map efficiently to machine instructions, and to require minimal run-time
support. C was therefore useful for many applications that had formerly been
coded in assembly language.

Despite its low-level capabilities, the language was designed to encourage


machine-independent programming. A standards-compliant and portably
written C program can be compiled for a very wide variety of computer
platforms and operating systems with little or no change to its source code.
The language has become available on a very wide range of platforms, from
embedded microcontrollers to supercomputers.
C's design is tied to its intended use as a portable systems implementation
language. It provides simple, direct access to any addressable object (for
example, memory-mapped device control registers), and its source-code
expressions can be translated in a straightforward manner to primitive
machine operations in the executable code. Some early C compilers were
comfortably implemented (as a few distinct passes communicating via
intermediate files) on PDP-11 processors having only 16 address bits. C
compilers for several common 8-bit platforms have been implemented as
well.

C's primary use is for "system programming", including implementing


operating systems and embedded system applications, due to a combination
of desirable characteristics such as code portability and efficiency, ability to
access specific hardware addresses, ability to "pun" types to match
externally imposed data access requirements, and low runtime demand on
system resources. C can also be used for website programming using CGI as
a "gateway" for information between the Web application, the server, and
the browser.[8] Some factors to choose C over Interpreted languages are its
speed, stability and less susceptibility to changes in operating environments
due to its compiled nature.

One consequence of C's wide acceptance and efficiency is that compilers,


libraries, and interpreters of other programming languages are often
implemented in C.

C is sometimes used as an intermediate language by implementations of


other languages. This approach may be used for portability or convenience;
by using C as an intermediate language, it is not necessary to develop
machine-specific code generators. Some compilers which use C this way are
BitC, Gambit, the Glasgow Haskell Compiler, Squeak, and Vala.
Unfortunately, C was designed as a programming language, not as a
compiler target language, and is thus less than ideal for use as an
intermediate language. This has led to development of C-based intermediate
languages such as C. C has also been widely used to implement end-user
applications, but as applications became larger, much of that development
shifted to other languages.
OUTPUT SCREENS
SOFTWARE CODING

//PAYROLL MANAGEMENT SYSTEM


//This program manages the payroll system of an organisation.

#include<graphics.h>
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<iomanip.h>

struct date_rec
{
short int dd;
short int mm;
int yyyy;
} current_date;

class payfile
{
private:
unsigned long emp_num;
char emp_name[25];
char emp_designation[20];
int days_worked;
float basic_pay;
float DA;
float HRA;
float CCA;
float con_veyance;
float gross_pay;
float PF;
float income_tax;
float other_deductions;
float net_pay;

public:
payfile()
{
days_worked=0;
basic_pay=DA=HRA=CCA=con_veyance=gross_pay=0.0;
PF=income_tax=other_deductions=net_pay=0.0;
}
void get_pay();
void update_pay_file();
void reports();
void add_pay_object(unsigned long code,char name[25],char desig[10]);
void del_pay_object(unsigned long code);
void modify_pay_object(unsigned long code,char desig[20]);
}pay;
void payfile::add_pay_object(unsigned long code,char name[25],char
desig[20])
{
fstream outfile;
pay.emp_num=code;
strcpy(pay.emp_name,name);
strcpy(pay.emp_designation,desig);
outfile.open("payfile.dat",ios::app);
outfile.write((char*)&pay,sizeof(pay));
outfile.flush();
outfile.close();
}

void payfile::del_pay_object(unsigned long code)


{
fstream outfile,infile;
outfile.open("tempfile.dat",ios::app);
infile.open("payfile.dat",ios::in);
infile.seekg(0,ios::beg);
infile.read((char*)&pay,sizeof(pay));
while(!infile.eof())
{
if(pay.emp_num!=code)
outfile.write((char*)&pay,sizeof(pay));
infile.read((char*)&pay,sizeof(pay));
}
infile.close();
outfile.close();
remove("payfile.dat");
rename("tempfile.dat","payfile.dat");
}

void payfile::modify_pay_object(unsigned long code,char desig[20])


{
fstream file;
file.open("payfile.dat",ios::in/ios::out);
file.seekg(0,ios::beg);
file.read((char*)&pay,sizeof(pay));
int n=file.tellg();
while(!file.eof())
{
if(code==pay.emp_num)
{
strcpy(pay.emp_designation,desig);
file.seekg(n-sizeof(pay));
file.write((char*)&pay,sizeof(pay));
file.flush();
file.seekg(0,ios::end);
}
file.read((char*)&pay,sizeof(pay));
n=file.tellg();
}
file.close();
}
void payfile::get_pay()
{
cout<<"\nENTER THE BASIC SALARY:->";
cin>>basic_pay;
cout<<"\nENTER THE NO. OF DAYS WORKED:->";
cin>>days_worked;
cout<<"\nENTER THE DEARNESS ALLOWENCE:->";
cin>>DA;
cout<<"\nENTER THE HOUSE RENT ALLOWENCE:->";
cin>>HRA;
cout<<"\nENTER THE CCA:->";
cin>>CCA;
cout<<"\nENTER THE CONVEYENCE ALLOWENCE:->";
cin>>con_veyance;
cout<<"\nENTER THE PROVIDENT FUND:->";
cin>>PF;
cout<<"\nENTER THE INCOME TAX:->";
cin>>income_tax;
cout<<"\nENTER OTHER DEDUCTIONS:->";
cin>>other_deductions;
gross_pay=basic_pay+DA+HRA+CCA+con_veyance;
net_pay=gross_pay-(PF+income_tax+other_deductions);
gotoxy(22,24);
cout<<"PRESS ANY KEY TO CONTINUE";
getch();
clrscr();
}

void payfile::update_pay_file()
{
fstream file;
file.open("payfile.dat",ios::in|ios::out);
file.seekg(0,ios::beg);
file.read((char*)&pay,sizeof(pay));
int n=file.tellg();
char choice='y';
while(choice=='y')
{
clrscr();
cout<<"\nENTER DATA FOR EMPLOYEE NO.:-
>"<<pay.emp_num;
pay.get_pay();
file.seekg(n-sizeof(pay));
file.write((char*)&pay,sizeof(pay));
file.flush();
file.seekg(n);
file.read((char*)&pay,sizeof(pay));
n=file.tellg();
cout<<"any more data";
cin>>choice;
}
file.close();
}
class employee:public payfile
{
private:
unsigned long employee_num;
char employee_name[25];
char employee_address[35];
date_rec date_joining;
date_rec date_birth;
char desig_nation[20];
float basic_salary;

public:
char ch;
unsigned long get_rec_no();
void get_data();
void show_data();
void add_object();
void show_object();
void del_object();
void modify_object();
void search_object();
}emp;

unsigned long employee::get_rec_no()


{
int found=0;
unsigned long recno,temp_recno;
struct node
{
unsigned long rec_no;
node*link;
};
node*start,*ptr,*ptr1,*ptr2;
fstream infile;
infile.open("employee.dat",ios::in);
infile.seekg(0,ios::end);
int n=infile.tellg();
infile.close();
if(n==0)
recno=1;
else
{
infile.open("employee.dat",ios::in);
start=ptr=new node;
infile.seekg(0,ios::beg);
infile.read((char*)&emp,sizeof(emp));
while(!infile.eof())
{
ptr->rec_no=employee_num;
ptr->link=new node;
ptr=ptr->link;
infile.read((char*)&emp,sizeof(emp));
}
ptr->link=NULL;
ptr1=start;
while(ptr1->link!=NULL)
{
ptr2=ptr1->link;
while(ptr2!=NULL)
{
if(ptr2->rec_no<ptr1->rec_no)
{
temp_recno=ptr2->rec_no;
ptr2->rec_no=ptr1->rec_no;
ptr1->rec_no=temp_recno;
}
ptr2=ptr2->link;
}
ptr2=ptr1->link;
ptr1=ptr2;
}

ptr1=start;
while(ptr1!=NULL && found!=1)
{
ptr2=ptr1;
ptr1=ptr1->link;
if((ptr2->rec_no)+1!=ptr1->rec_no)
{
recno=(ptr2->rec_no)+1;
found=1;
}
}
if(found!=1)recno=(ptr2->rec_no)+1;
ptr=start;
while(start!=NULL)
{
start=start->link;
delete ptr;
}
}//end of else
return recno;
}//end of function

void employee::get_data()
{
clrscr();
employee_num=get_rec_no();
cout<<"\nENTER THE NAME:";
gets(employee_name);
cout<<"\nENTER THE ADDRESS:";
gets(employee_address);
cout<<"\nENTER THE DATE OF JOINING<<dd/mm/yyyy>>:";
cin>>date_joining.dd>>ch>>date_joining.mm>>ch>>date_joining.yyyy;
cout<<"\nENTER THE DATE OF BIRTH<<dd/mm/yyyy>>:";
cin>>date_birth.dd>>ch>>date_birth.mm>>ch>>date_birth.yyyy;
cout<<"\nENTER THE DESIGNATION:";
gets(desig_nation);
cout<<"\nENTER THE BASIC SALARY:";
cin>>basic_salary;
}

void employee::show_data()
{
clrscr();
cout<<"\n EMPLOYEE NO.->"<<employee_num;
cout<<"\n EMPLOYEE's NAME->"<<employee_name;
cout<<"\n DATE OF JOINING->"<<date_joining.dd
<<"_"<<date_joining.mm
<<"_"<<date_joining.yyyy;
cout<<"\n EMPLOYEE's ADDRESS->"<<employee_address;
cout<<"\n DATE OF BIRTH->"<<date_birth.dd
<<"_"<<date_birth.mm
<<"_"<<date_birth.yyyy;
cout<<"\n DESIGNATION->"<<desig_nation;
cout<<"\n BASIC SALARY->RS"<<setw(15)
<<setprecision(2)
<<setiosflags(ios::left)
<<setiosflags(ios::showpoint)
<<setiosflags(ios::fixed)
<<basic_salary;
gotoxy(22,24);
cout<<"PRESS ANY KEY TO CONTINUE";
getch();
}

void employee::add_object()
{
fstream outfile;
char choice='y';
while(choice=='y')
{
clrscr();
char ch;
outfile.open("employee.dat",ios::app);
emp.get_data();
outfile.write((char*)&emp,sizeof(emp));
outfile.flush();
outfile.close();

add_pay_object(emp.employee_num,emp.employee_name,emp.desig_natio
n);
cout<<"\n ANY MORE EMPLOYEE TO BE ADDED->";
cin>>choice;
}
}

void employee::show_object()
{
fstream infile;
infile.open("employee.dat",ios::in);
infile.seekg(0,ios::beg);
infile.read((char*)&emp,sizeof(emp));
while(!infile.eof())
{
emp.show_data();
infile.read((char*)&emp,sizeof(emp));
}
}

void employee::del_object()
{
unsigned long code;
fstream infile,outfile;
cout<<"\n ENTER THE MEMBERSHIP NO. TO BE DELETED->";
cin>>code;
outfile.open("tempfile.dat",ios::app);
infile.open("employee.dat",ios::in);
infile.seekg(0,ios::beg);
infile.read((char*)&emp,sizeof(emp));
while(!infile.eof())
{
if(emp.employee_num!=code)
outfile.write((char*)&emp,sizeof(emp));
infile.read((char*)&emp,sizeof(emp));
}
infile.close();
outfile.close();
remove("employee.dat");
rename("tempfile.dat","employee.dat");
del_pay_object(code);
}

void employee::modify_object()
{
fstream file;
int mod_choice;
unsigned long code;
do
{
clrscr();
cout<<"\n MODIFY MENU ";
cout<<"\n-----------------";
cout<<"\n CHANGE ADDRESS ..1";
cout<<"\n CHANGE DESIGNATION ..2";
cout<<"\n CHANGE BASIC SALARY ..3";
cout<<"\n EXIT MODIFY MENU ..4";
cout<<"\n ENTER YOUR CHOICE NO.->";
cin>>mod_choice;
if(mod_choice!=4)
{
cout<<"\n ENTER THE EMPLOYEE NO.->";
cin>>code;
file.open("employee.dat",ios::in|ios::out);
file.seekg(0,ios::beg);
file.read((char*)&emp,sizeof(emp));
int n=file.tellg();
while(!file.eof())
{
if(code==emp.employee_num)
{
switch(mod_choice)
{
case 1:clrscr();
cout<<"\n ENTER THE NEW ADDRESS->";
gets(emp.employee_address);
file.seekg(n-sizeof(emp));
file.write((char*)&emp,sizeof(emp));
file.flush();
break;

case 2:clrscr();
cout<<"\n ENTER THE NEW DESIGNATION->";
gets(desig_nation);
file.seekg(n-sizeof(emp));
file.write((char*)&emp,sizeof(emp));
file.flush();
modify_pay_object(code,desig_nation);
break;

case 3:clrscr();
cout<<"\n ENTER NEW BASIC SALARY->";
cin>>emp.basic_salary;
file.seekg(n-sizeof(emp));
file.write((char*)&emp,sizeof(emp));
file.flush();
break;

} //end switch
} //end if
file.read((char*)&emp,sizeof(emp));
n=file.tellg();
} //end while
file.close();
} //end if
} //end do while loop
while(mod_choice!=4);

clrscr();
cout<<"\N YOU ENDED THE MODIFY SESSION";
cout<<"\N THANK YOU !";
delay(700);
}

void employee::search_object()
{
fstream infile;
int search_choice;
long int phno;
unsigned long code;
char name[25];
do
{
int counter=0;
clrscr();
cout<<"\n SEARCH MENU ";
cout<<"\n-----------------";
cout<<"\n EMPLOYEE CODE ..1";
cout<<"\n EMPLOYEE NAME ..2";
cout<<"\n EXIT ..3";
cout<<"\n\n ENTER YOUR CHOICE NO.->";
cin>>search_choice;
switch(search_choice)
{
case 1:clrscr();
cout<<"\n ENTER THE MEMBER CODE TO BE SEARCHED-
>";
cin>>code;
infile.open("employee.dat",ios::in);
infile.seekg(0,ios::beg);
infile.read((char*)&emp,sizeof(emp));
while(!infile.eof())
{
if(emp.employee_num==code)
{
counter++;
emp.show_data();
}
infile.read((char*)&emp,sizeof(emp));
}
infile.close();
gotoxy(22,20);
cout<<"RECORD FOUND="<<counter;
getch();
break;

case 2:clrscr();
cout<<"\n ENTER THE MEMBER TO BE SEARCHED->";
cin>>name;
infile.open("employee.dat",ios::in);
infile.seekg(0,ios::beg);
infile.read((char*)&emp,sizeof(emp));
while(!infile.eof())
{
if(strcmpi(emp.employee_name,name)==0)
{
counter++;
emp.show_data();
}
infile.read((char*)&emp,sizeof(emp));
}
infile.close();
gotoxy(22,20);
cout<<"RECORD FOUND="<<counter;
getch();
break;

case 3:clrscr();
gotoxy(22,15);
cout<<"YOU ENDED THE SEARCH SESSION";
gotoxy(27,18);
cout<<"THANK YOU !";
delay(700);
break;
}//end of switch
}
while(search_choice!=3);
}//end of function

void payfile::reports()
{
fstream infile;
int report_choice;
do
{
clrscr();
cout<<"\n REPORT MENU ";
cout<<"\n--------------------";
cout<<"\n LIST OF ALL EMPLOYEES ..1";
cout<<"\n SALARY STATEMENTS OF ALL EMPLOYEES ..2";
cout<<"\n SALARY SLIPS OF ALL EMPLOYEES ..3";
cout<<"\n EXIT REPORTS SESSION ..4";
cout<<"\n\n REPORT ON WHAT ?< ENTER CHOICE NO.>
---->";
cin>>report_choice;
switch(report_choice)
{
case 1: clrscr();
emp.show_object();
break;

case 2:clrscr();
cout<<"\n----------------------------------------------------";
cout<<"\n ABC CORPORATION ";
cout<<"\n----------------------------------------------------";
cout<<"\n EMP.NO. EMP.NAME EARNINGS
DEDUCTIONS ";
cout<<"\n DESIG. BASIC DA PF OTHER DED.
GROSS PAY ";
cout<<"\n HRA CCA ITAX NET PAY ";
cout<<"\n CONVEYANCE ";
cout<<"\n--------------------------------------------------\n";
infile.open("payfile.dat",ios::in);
infile.seekg(0,ios::beg);
infile.read((char*)&pay,sizeof(pay));
while(!infile.eof())
{
cout<<" ";
cout<<setiosflags(ios::left)
<<setw(9)
<<pay.emp_num
<<setw(14)
<<pay.emp_name;
cout<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint)
<<setprecision(2)
<<setw(12)
<<pay.basic_pay
<<setw(10)
<<pay.DA
<<setw(10)
<<pay.PF
<<setw(10)
<<pay.other_deductions
<<setw(12)
<<pay.gross_pay
<<endl;
cout<<" ";
cout<<setiosflags(ios::left)
<<setw(17)
<<pay.emp_designation;
cout<<setiosflags(ios::fixed)
<<setprecision(2)
<<setiosflags(ios::showpoint)
<<setw(12)
<<pay.HRA
<<setw(10)
<<pay.CCA
<<setw(20)
<<pay.income_tax
<<setw(12)
<<pay.net_pay
<<endl;
cout<<" ";
cout<<setiosflags(ios::fixed)
<<setprecision(2)
<<setiosflags(ios::showpoint)
<<setw(8)
<<pay.con_veyance
<<endl
<<endl;

infile.read((char*)&pay,sizeof(pay));
}//end of while
infile.close();
gotoxy(22,24);
cout<<" PRESS ANY KEY TO CONTINUE ";
getch();
break;

case 3: clrscr();
char ch,month[9];
cout<<"\n ENTER CURRENT DATE <<dd/mm/yyyy>>
------->";
cin>>current_date.dd>>ch
>>current_date.mm>>ch
>>current_date.yyyy;
switch(current_date.mm)
{
case 1: strcpy(month,"JANUARY");
break;
case 2: strcpy(month,"FEBRUARY");
break;
case 3: strcpy(month,"MARCH");
break;
case 4: strcpy(month,"APRIL");
break;
case 5: strcpy(month,"MAY");
break;
case 6: strcpy(month,"JUNE");
break;
case 7: strcpy(month,"JULY");
break;
case 8: strcpy(month,"AUGUST");
break;
case 9: strcpy(month,"SEPTEMBER");
break;
case 10: strcpy(month,"OCTOBER");
break;
case 11: strcpy(month,"NOVEMBER");
break;
case 12: strcpy(month,"DECEMBER");
break;
}//end of switch
infile.open("payfile.dat",ios::in);
infile.seekg(0,ios::beg);
infile.read((char*)&pay,sizeof(pay));
while(!infile.eof())
{
clrscr();
cout<<"\n----------------------------------------------------";
cout<<"\n ABC CORPORATION ";
cout<<"\n SALARY SLIP FOR THE MONTH OF
"<<month<<"-"<<current_date.yyyy;
cout<<"\n----------------------------------------------------";
cout<<"\n EMPLOYEE NO.:"<<setiosflags(ios::left)
<<setw(10)
<<pay.emp_num;
cout<<" NAME:";
cout<<setiosflags(ios::left)
<<setw(20)
<<pay.emp_name;
cout<<"\n\n EARNINGS DEDUCTIONS";
cout<<"\n------------ ----------";
cout<<"\n BASIC:RS."<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint)
<<setprecision(2)
<<setw(12)
<<pay.basic_pay;
cout<<" PF :RS.";
cout<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint)
<<setprecision(2)
<<setw(12)
<<pay.PF;
cout<<"\n DA :RS.";
cout<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint)
<<setprecision(2)
<<setw(12)
<<pay.DA;
cout<<" ITAX :RS. ";
cout<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint)
<<setprecision(2)
<<setw(12)
<<pay.income_tax;
cout<<"\n HRA : RS.";
cout<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint)
<<setprecision(2)
<<setw(12)
<<pay.HRA;
cout<<" OTHER DEDUCTIONS :RS.";
cout<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint)
<<setprecision(2)
<<setw(12)
<<pay.other_deductions;
cout<<" CCA :RS. ";
cout<<setiosflags(ios::fixed)
<<setprecision(2)
<<setiosflags(ios::showpoint)
<<setw(12)
<<pay.CCA;
cout<<"\n CONVEYANCE : RS. ";
cout<<setiosflags(ios::fixed)
<<setprecision(2)
<<setiosflags(ios::showpoint)
<<setw(12)
<<pay.con_veyance;
cout<<"\n\n GROSS PAY : RS.";
cout<<setiosflags(ios::fixed)
<<setprecision(2)
<<setiosflags(ios::showpoint)
<<setw(12)
<<pay.gross_pay;
cout<<" TOTAL DEDUCTIONS :RS.";
cout<<setiosflags(ios::fixed)
<<setprecision(2)
<<setiosflags(ios::showpoint)
<<setw(12)
<<pay.gross_pay-pay.net_pay;
cout<<"\n NET PAY : RS.";
cout<<setiosflags(ios::fixed)
<<setprecision(2)
<<setiosflags(ios::showpoint)
<<setw(12)
<<pay.net_pay;
cout<<"\n-------------------------------------------------";

cout<<"\n SIGNATORY AUTHORITY ";


cout<<"\n-------------------------------------------------";
cout<<"\n-------------------------------------------------";
gotoxy(22,24);
cout<<" PRESS ANY KEY TO CONTINUE ";
getch();
infile.read((char*)&pay,sizeof(pay));
}//end of while
infile.close();
break;
case 4: clrscr();
gotoxy(22,15);
cout<<" YOU ENDE THE REPORT SESSION";
gotoxy(22,18);
cout<<" THANK YOU !";
delay(700);
break;
}//end of switch
}
while(report_choice!=4);
}//end of function

void main()
{
int main_choice;
do
{
clrscr();
gotoxy(22,7);
cout<<" MAIN MENU ";
gotoxy(22,8);
cout<<"-------------------------";
gotoxy(22,10);
cout<<"REGISTER A NEW EMPLOYEE ..1";
gotoxy(22,11);
cout<<"REMOVE AN EMPLOYEE ..2";
gotoxy(22,12);
cout<<"MODIFY AN INFORMATION ABOUT AN EMPLOYEE
..3";
gotoxy(22,13);
cout<<"SEARCH FOR INFORMATION ABOUT AN EMPLOYEE
..4";
gotoxy(22,14);
cout<<"UPDATE MONTHLY PAY FILE ..5";
gotoxy(22,15);
cout<<"REPORTS ..6";
gotoxy(22,16);
cout<<"EXIT ..7";
gotoxy(22,17);
cout<<"ENTER YOUR CHOICE NO.----->";
cin>>main_choice;
switch(main_choice)
{
case 1: emp.add_object();
break;
case 2: emp.del_object();
break;
case 3: emp.modify_object();
break;
case 4: emp.search_object();
break;
case 5: pay.update_pay_file();
break;
case 6: pay.reports();
break;
case 7: clrscr();
gotoxy(25,10);
cout<<" YOU ENDED THE SESSION ";
gotoxy(27,12);
cout<<" THANK YOU ! ";
delay(1000);
break;
}//end of switch
}
while(main_choice!=7);
}//end of main

Vous aimerez peut-être aussi