Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Data File StructureRSS Feeds

payrol system in Ethiopia

Posted By: Tesfamichael Amsalu     Category: C++ Programming     Views: 7906

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
struct employee
{
char name[20],sex[7],id[10];
float income,tax,penstion,netincome,allowance;
};
employee *accept(employee a[],int n);
employee *tax(employee a[],int n);
inline employee *penstion(employee a[],int n);
inline employee *netincome(employee a[],int n);
void putdata(employee a[],int n,ofstream &of);
void getdata(ifstream &in);
void main ()
{
clrscr ();
ofstream of;
ifstream in;
employee *s;
int n;
int choice;
char ch;
do
{
clrscr ();
cout<<endl;
cout<<endl;
cout<<"Please choose from the following: \n";
cout<<"\t1. write Data. \n";
cout<<"\t2. read Data. \n";
cout<<"\t3. Quit. \n";
cout<<endl;
cout<<"Your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"how many Employees' detail data";
cout<<"do you want yo feed:\n";
cin>>n;
s=new employee[n];
s=accept(s,n);
s=tax(s,n);
s=penstion(s,n);
s=netincome(s,n);
putdata(s,n,of);
break;
case 2:
getdata(in);
break;
case 3:
break;
default:
cout<<"\tInvalid entry!"<<endl;
}
cout<<"\nWould you like to try again (y/n): ";
cin>>ch;

}
while(ch == 'y' || ch == 'Y');
delete []s;
getch ();
}
employee *accept(employee a[],int n)
{
cout<<"please enter the employee detail:name,sex,id,income,allowance: \n";
cout<<endl;
for(int i=0;i<n;i++)
{
cout<<"feed employee"<<" "<<(i+1)<<" "<<"detail data:\n";
cin>>a[i].name>>a[i].sex>>a[i].id>>a[i].income>>a[i].allowance;
}
return a;
}
employee *tax(employee a[],int n)
{
for(int i=0;i<n;i++)
{
if(a[i].income<=150)
a[i].tax=0;
else if (a[i].income<=650)
a[i].tax=(a[i].income*10/100)-15;
else if (a[i].income<=1400)
a[i].tax=((a[i].income*15/100)-47.5);
else if (a[i].income<=2350)
a[i].tax=((a[i].income*20/100)-117.5);
else if(a[i].income<=3550)
a[i].tax=((a[i].income*25/100)-235);
else if (a[i].income<=5000)
a[i].tax=((a[i].income*30/100)-412.5);
else
a[i].tax=((a[i].income*35/100)-662);
}
return a;
}
employee *penstion(employee a[],int n)
{
for (int i=0;i<n;i++)
a[i].penstion=(a[i].income*6/100);
return a;
}
employee *netincome(employee a[],int n)
{
for(int i=0;i<n;i++)
a[i].netincome=(a[i].income+a[i].allowance-a[i].tax-a[i].penstion);
return a;
}
void putdata(employee a[],int n,ofstream &of)
{
of.open("xyz.txt",ios::out|ios::app);
if(of.fail())
{
cerr<<"unable to open /n";
return;
}
for(int i=0;i<n;i++)
{
of<<a[i].name<<"\t"<<a[i].sex<<"\t"<<a[i].id<<"\t"<<a[i].income<<"\t";
of<<a[i].tax<<"\t"<<a[i].penstion<<"\t"<<a[i].allowance<<"\t"<<a[i].netincome;
}
of.close();
}
void getdata(ifstream &in)
{
cout<<"....................................................................\n";
cout<<"E_Name \tSex\tID\tIncome\tTax\tPenst.\tAllow.\tNetI.\n";
cout<<"....................................................................\n";
in.open("xyz.txt");
employee p;
if(in)
{
while(!in.eof())
{
in>>p.name>>p.sex>>p.id>>p.income;
in>>p.tax>>p.penstion>>p.allowance>>p.netincome;
if(in.eof())
break;
cout<<p.name<<"\t"<<p.sex<<"\t"<<p.id<<"\t"<<p.income<<"\t"<<p.tax;
cout<<"\t"<<p.penstion<<"\t"<<p.allowance<<"\t"<<p.netincome;
cout<<endl;
}
in.close();
}
else
cerr<<"unable to open /n";
}

  
Share: 


Didn't find what you were looking for? Find more on payrol system in Ethiopia Or get search suggestion and latest updates.

Tesfamichael Amsalu
Tesfamichael Amsalu author of payrol system in Ethiopia is from Switzerland.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!