0% found this document useful (0 votes)
19 views4 pages

Payroll System

This C++ program implements a payroll system with user accounts. It includes functions to create accounts, log in, calculate salaries, and display a dashboard. The createAccount() function prompts the user to enter a username and password and writes it to a file. The login() function checks the entered username and password against the file. If valid, it returns true. The calculateSalary() function prompts the user to enter employee details and calculates their gross pay, deductions, additional income, and net pay.

Uploaded by

jayceelunaria7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Payroll System

This C++ program implements a payroll system with user accounts. It includes functions to create accounts, log in, calculate salaries, and display a dashboard. The createAccount() function prompts the user to enter a username and password and writes it to a file. The login() function checks the entered username and password against the file. If valid, it returns true. The calculateSalary() function prompts the user to enter employee details and calculates their gross pay, deductions, additional income, and net pay.

Uploaded by

jayceelunaria7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <iostream>

#include <iomanip>
#include <string>
#include <fstream>
#include <limits>
#include <cstdlib>

using namespace std;

void clearScreen() {
system("cls");
}

struct Account {
string username;
string password;
};

bool isAlphabetic(const string& str) {


for (char c : str) {
if (!isalpha(c)) {
return false;
}
}
return true;
}

void createAccount() {
ofstream file("accounts.txt", ios::app);
Account acc;
cout << "Enter username: ";
getline(cin, acc.username);

if (!isAlphabetic(acc.username)) {
cout << "Please enter alphabetic characters only." << endl;
return;
}

cout << "Enter password: ";


getline(cin, acc.password);
file << acc.username << " " << acc.password << endl;
file.close();
cout << "Account created successfully!" << endl;
}

bool login() {
ifstream file("accounts.txt");
if (!file) {
cerr << "Error: Unable to open file." << endl;
return false;
}

string username, password;


cout << "Enter username: ";
getline(cin, username);
cout << "Enter password: ";
getline(cin, password);

string stored_username, stored_password;


while (file >> stored_username >> stored_password) {
if (stored_username == username && stored_password == password) {
file.close();
cout << "Login successful!" << endl;
return true;
}
}

file.close();
cout << "Invalid username or password." << endl;
return false;
}

void calculateSalary() {
string surname, firstname, middlename, occ, dept;
int emp, Absence;
float tax, SSS, Pb, Ph, Rh, noh, grosspay, Netpay, TotalDeduct, Allowance, Ot, Bonus, monthpay, Totaladdincome;

cout << "PAYROLL SYSTEM \n";


cout << "Emp no.: ";
cin >> emp;
cout << "Surname: ";
cin >> surname;
cout << "Firstname: ";
cin >> firstname;
cout << "Middlename: ";
cin >> middlename;
cout << "Occupation: ";
cin >> occ;
cout << "Department: ";
cin >> dept;
cout << "Rate per Hour: ";
cin >> Rh;
cout << "No. of Hours work: ";
cin >> noh;
grosspay = Rh * noh;

cout << "Grosspay: "<< fixed << setprecision(2) << grosspay;


cout << "\n\nDEDUCTION";
cout << "\nTax: ";
cin >> tax;
cout << "SSS: ";
cin >> SSS;
cout << "Pag-Ibig: ";
cin >> Pb;
cout << "Philhealth: ";
cin >> Ph;
cout << "Absences: ";
cin >> Absence;

TotalDeduct = tax + SSS + Pb + Ph + Absence;

cout << "Total Deduction: "<< fixed << setprecision(2) << TotalDeduct;

cout << "\n\nADDITIONAL INCOME";


cout << "\nAllowance: ";
cin >> Allowance;
cout << "OT: ";
cin >> Ot;
cout << "Bonus: ";
cin >> Bonus;
cout << "13th Month pay: ";
cin >> monthpay;

Totaladdincome = Allowance + Ot + Bonus + monthpay;

cout << "Total Additional Income: " << fixed << setprecision(2) << Totaladdincome;

Netpay = grosspay + Totaladdincome - TotalDeduct;

cout << "\n\nTOTAL NETPAY: " << fixed << setprecision(2) << Netpay;
}

void displayDashboard() {
calculateSalary();
}

int main() {
int choice;
bool loggedIn = false;

while (true) {
cout << "PAYROLL SYSTEM" << endl;
cout << "1. Create Account" << endl;
cout << "2. Login" << endl;
cout << "3. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;
cin.ignore();

switch (choice) {
case 1:
clearScreen();
createAccount();
break;
case 2:
clearScreen();
loggedIn = login();
break;
case 3:
clearScreen();
cout << "Are you sure you want to exit? (Y/N): ";
char confirmExit;
cin >> confirmExit;
if (toupper(confirmExit) == 'Y') {
cout << "Exiting program..." << endl;
return 0;
}
clearScreen();
break;
default:
cout << "Invalid choice. Please try again." << endl;
break;
}

if (loggedIn) {
clearScreen();
displayDashboard();
loggedIn = false;
break;
}
}

return 0;
}

You might also like