Sunday, May 31, 2015

Payroll System Using Text File in C++

One of the most interesting aspect of computer programming is how to store or save the information that we process in a text file or database for future reference. In this article I would like to share with you a program that I wrote a long time ago in my class to teach my students in C++ programming how to store the processed information in a text file in C++. The code is very straight forward and easy to understand.  I hope many people will able to use this code as their basis in their learning how to program in C++.

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

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

Thank you very much and Happy Programming.


Sample Program Output

Program Listing

#include <iostream>
#include <fstream>

 using namespace std;

 struct employee {
     string name,job;
     int age, rate, days;
     int solve_salary;
 };


 main() {
     employee user;
     ofstream myfile("result.txt");
     cout << "\t\t XYZ Payroll System";
     cout << "\n\n";
     cout << "Enter Name : ";
     getline(cin,user.name);
     cout << "Enter Job : ";
     getline(cin,user.job);
     cout << "Enter Age : ";
     cin >> user.age;
     cout << "Enter Rate Per Day : ";
     cin >> user.rate;
     cout << "Enter No. of Days Work : ";
     cin >> user.days;

      user.solve_salary = (user.days * user.rate);

       myfile << "\n=========================";
       myfile << "\t\n  XYZ PAYROLL SYSTEM ";
       myfile << "\n=========================";
       myfile << "\n Name    : " << user.name;
       myfile << "\n Job     : " << user.job;
       myfile << "\n Age     : " << user.age;
       myfile << "\n Salary  : $" << user.solve_salary;
       myfile.close();
       cout << "\n\n";
       system("pause");
 }




No comments:

Post a Comment