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.
My mobile number here in the Philippines is 09173084360
Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
My mobile number here in the Philippines is 09173084360
Program Listing
#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.txt Content 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