Thursday, October 1, 2015

Payroll System Using Structure in C++

I this article I would like to share with you guys a sample program that I wrote a long time ago in my C++ programming class in college using structure as our data structure. I called this program payroll system that will compute the salary of an employee in the company. To give you some idea structure is also known as records in other programming language such as Pascal it can contains several variables and different data type but still belong with the same entity. 

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.



Program Listing


#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

struct employee {
    string name, department;
    int age;
    char gender;
    float days, rate;
};

main() {

    float solve=0.00;
    string sex;
    employee user;

     cout << "\t\t XYZ Payroll Solver 1.0";
     cout << "\n\n";
     cout << "\t Created By: Mr. Jake R. Pomperada, MAED-IT";
     cout << "\n\n";
     cout << "Enter the Name of the Employee    : ";
     getline(cin,user.name);
     cout << "Enter the Name of Department      : ";
     getline(cin,user.department);
     cout << "Enter the Gender of the Employee  : ";
     user.gender = getchar();
     cout << "Enter the Number of Days Worked   :  ";
     cin >> user.days;
     cout << "Enter the Daily Rate              :  ";
     cin >> user.rate;

     solve = (user.days * user.rate);
     if (user.gender == 'M' || user.gender == 'm')
        {
          sex = "Male";
        }
     else if (user.gender == 'F' || user.gender == 'f')
        {
          sex = "Female";
        }
    cout << fixed;
    cout << setprecision(2);
     cout << "\n\n";
     cout << "\t ===== GENERATED REPORT =====";
     cout << "\n\n";
     cout << "\nEmployee Name : " << user.name;
     cout << "\nDeparment     : " << user.department;
     cout << "\nGender        : " << sex;
     cout << "\nSalary        : $" << solve;
     cout << "\n\n";
      system("pause");
}

No comments:

Post a Comment