VB icon

Employees Payroll System in C++ using Text File

Email
Submitted on: 6/4/2016 7:20:16 AM
By: Jake R. Pomperada  
Level: Beginner
User Rating: Unrated
Compatibility: C++ (general)
Views: 2146
author picture
 
     A simple employees payroll system that I retrieve, process and store information in a text file in C++ that I wrote a long time ago. I hope you will find my work useful. Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com My mobile number here in the Philippines is 09173084360
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Employees Payroll System in C++ using Text File
// Description:A simple employees payroll system that I retrieve, process and store information in a text file in C++ that I wrote a long time ago. I hope you will find my work useful.
 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
My mobile number here in the Philippines is 09173084360
// By: Jake R. Pomperada
//**************************************

#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<sstream>
#include<iomanip>
using namespace std;
void append();
void find();
void read();
void whattodo();
void loop();
void about();
void mainfind();
int main()
{
system("Color 2F");
cout<<"\t\t\t------------------"<<endl;
cout<<"\t\t\t* Payroll System *"<<endl;
cout<<"\t\t\t------------------"<<endl;
whattodo();
getch();
return 0;
}
void whattodo()
{
int choice;
loop:
cout << "\n\t\t Created By: Mr. Jake R.Pomperada, MAED-IT";
cout << "\n\n";
cout<<"Type the number of the command you want to perform:"<<endl;
cout<<endl;
cout<<"[1] Append Record"<<endl;
cout<<"[2] Browse all file contents"<<endl;
cout<<"[3] Find a record"<<endl;
cout<<"[4] Exit"<<endl;
cout<<"[5] About"<<endl;
cout<<""<<endl;
cin>>choice;
cout<<""<<endl;
 if (choice==1)
{
system("cls");
append();
cout<<endl;
loop();
}
else if (choice==2)
{
system("cls");
read();
cout<<endl;
loop();
}
else if(choice==3)
{
system("cls");
mainfind();
loop();
}
else if(choice==4)
{
system("cls");
cout<<"Goodbye.";
}
else if(choice==5)
{
system("cls");
about();
}
else
{
cout<<"Invalid! Try again."<<endl;
goto loop;
}
system ("cls");
}
void append()
{
 string emp_first, emp_last;
 string id;
 double salary=0.00;
 ofstream fout;
 fout.open("myRecord.txt",ios::app);// open file for appending
 cout<<"Enter Employee Id: ";
 cin >> id;
 cout << "\n";
 cout<<"Enter Employee Name: ";
 cin >> emp_first >> emp_last;
 cout<<"Enter Employee Salary:";
 cin >> salary;
 fout << setiosflags(ios::fixed | ios :: showpoint)
<< setprecision(2);
fout<< id<< ", " << emp_first
<< " " << emp_last << " , " << salary << endl;
fout << fixed;
 fout.close( );//close file
;
}
void read()
{
string line;
ifstream x ("myRecord.txt");
if (x.is_open())
{
while(!x.eof())
{
cout<<endl;
getline(x,line);
cout<<line<<endl;
}
x.close();
}
else
cout<<"Cant open file."<<endl;
}
void find()
{
ifstream data("myRecord.txt");
string item,line;
int x=0;
int y=0;
string id;
cout<<endl;
cout<<"Enter Employee Id: ";
cin>>id;
cout<<""<<endl;
while(!data.eof())
{
getline(data,line);
string item_array[10];
stringstream stream(line);
x=0,y=0;
while(getline(stream,item,','))
{
item_array[x]=item;
x++;
item_array[y]=item;
y++;
}
if(item_array[0]==id)
{
cout<<setfill('-')<<left<<setw(10)<<"\t\t\tID:" <<right<<" "<<item_array[0]<<endl;
cout<<setfill('-')<<left<<setw(10)<<"\t\t\tName: " <<right<<" "<<item_array[1]<<endl;
cout<<setfill('-')<<left<<setw(10)<<"\t\t\tRate: " <<right<<" "<<item_array[2]<<endl;
cout<<""<<endl;
}
}
data.close();
}
void loop()
{
string choice;
cout<<""<<endl;
cout<<"Do you want to make another choice?(yes/no)";
cin>>choice;
system("cls");
cout<<""<<endl;
if (choice=="yes")
{
whattodo();
}
else if(choice=="no")
{
cout<<"Goodbye.";
}
}
void about()
{
cout<<endl;
cout<<"ABC Computer Training Center"<<endl;
cout<<" 1st Floor, Victoria Center"<<endl;
cout<<"Bacolod City, Philippines Tel.No. 4335081"<<endl;
cout<<" Endterm Exams"<<endl;
cout<<""<<endl;
cout<<" Professor: Sir Jake R. Pomperada"<<endl;
cout<<""<<endl;
cout<<" Project Manager : Juan Dela Cruz"<<endl;
cout<<""<<endl;
cout<<" Program Designer: Pedro Santa Maria"<<endl;
cout<<""<<endl;
loop();
}
void mainfind()
{
find();
string id;
cout<<"Type back to go to main menu."<<endl;
cout<<"Press any key to find another profile."<<endl;
cin>>id;
system("cls");
if (id=="back")
{
whattodo();
}
else
{
mainfind();
find();
}
}
myRecord.txtContent Records in a Text File
101, Joey Smith, 500.00
102, Lydia Gamboa, 560.34
103, Mark Chua,750.55
104, Lebron James, 850.32
105, Jake R. Pomperada,15000.50
106, Allie Pomperada , 12340.50
107, Jacob Samuel Pomperada , 23400.20
108, Julianna Rae Pomperada , 3500.12
109, Kobe Bryant , 781234.40
110, Albrecht Aldaba , 53423.13


Other 69 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.