Sunday, May 31, 2015

Payroll Database System in C++

In this article I will share with you a program that I wrote in C++ that will manage the payroll system of the employees in the company I called this program Payroll Database System in C++ that uses text file to save the records of the employees. In this program I am using CodeBlocks as my text editor and Dev C++ as my C++ compiler that is very available over the Internet for free because it is an open source.

If you have some questions regarding about my work please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines who wish to contact me can reach me thru my mobile number at 09173084360.

Thank you and Happy Programming.



Sample Program Output

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();
    }
}




No comments:

Post a Comment