0% found this document useful (0 votes)
19 views

Code

The document defines arrays to store employee data including name, ID, address, wage. It prints the employee data, calculates payroll for an employee based on hours worked and wage, and allows login verification by ID and password to view payroll amount.

Uploaded by

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

Code

The document defines arrays to store employee data including name, ID, address, wage. It prints the employee data, calculates payroll for an employee based on hours worked and wage, and allows login verification by ID and password to view payroll amount.

Uploaded by

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

#include <iostream>

#include <string>
#include <array>

const int EMPLOYEE_COUNT = 9;


const int EMPLOYEE_DATA_SIZE = 9;

std::array<std::array<std::string, EMPLOYEE_DATA_SIZE>, EMPLOYEE_COUNT>


employeeData = {{
{"JONES", "JAMES", "JJONES", "JJ1234", "10th Ave", "Tuscaloosa", "AL", "FT",
"25.55"},
{"SMITH", "ROBERT", "SROBERT", "SR1234", "6th Street", "Atlanta", "GA", "PT",
"10.22"},
{"BROWN", "WILLIAM", "BWILL", "BW889", "7th Ave", "Birmingham", "AL", "FT",
"26.55"},
{"WHITE", "CHARLES", "WCHARL", "WC099", "4th Street", "Tuscaloosa", "AL", "FT",
"30.55"},
{"CARLSON", "MATHEW", "CMATT", "CM9893", "8th Ave", "Atlanta", "GA", "PT",
"15.22"},
{"FALCON", "DANIEL", "FDANN", "FC98349", "5th Street", "Birmingham", "AL",
"FT", "31.55"},
{"FEAK", "ANTHONY", "FANTH", "FA93934", "6th Ave", "Tuscaloosa", "AL", "FT",
"35.55"},
{"PARIS", "MARK", "PMARK", "PM3934", "3rd Street", "Atlanta", "GA", "PT",
"20.22"},
{"TAYLOR", "DONALD", "TDON", "TD3033", "12th Ave", "Birmingham", "AL", "FT",
"36.55"}
}};

void printEmployeeData() {
std::cout << "EMPLOYEE DATA:" << std::endl;
for (const auto& employee : employeeData) {
for (const auto& data : employee) {
std::cout << data << " ";
}
std::cout << std::endl;
}
std::cout << std::endl;
}

double calculatePayroll(const std::array<std::string, EMPLOYEE_DATA_SIZE>&


employee, double hoursWorked) {
double hourlyRate = std::stod(employee[8]);
double regularPay = hourlyRate * (hoursWorked <= 40 ? hoursWorked : 40);
double overtimePay = hoursWorked > 40 ? (hoursWorked - 40) * 1.5 * hourlyRate :
0;
return regularPay + overtimePay;
}

int main() {
printEmployeeData();

std::string userId, password;


std::cout << "Enter User ID: ";
std::cin >> userId;
std::cout << "Enter Password: ";
std::cin >> password;

for (const auto& employee : employeeData) {


if (employee[2] == userId && employee[3] == password) {
std::cout << "User logged in successfully!" << std::endl;

double hoursWorked;
std::cout << "Enter hours worked: ";
std::cin >> hoursWorked;

double payroll = calculatePayroll(employee, hoursWorked);


std::cout << "Payroll for " << employee[1] << " " << employee[0] << "
is: $" << payroll << std::endl;

return 0;
}
}

std::cout << "Invalid login attempt. Please try again." << std::endl;

return 0;
}

You might also like