// Native_PayrolStruct.cpp : Defines the entry point for the console application. /* _______________________________________________________ I N T R O D U C T I O N T O S T R U C T S Ron Kessler Created 1/23/2017 Native Code Version Run with CTL-F5 Structs are really User-defined types. They are a way to group related data together like an array. But unlike an array, the structure is made up of primitive data types that you put together in a way that makes sense. Then, you can use your new data type like any other variable/array. In this app I have grouped employee information into a new structure that lets me handle several related attributes of employees. */ #include "stdafx.h" #include #include #include using namespace std; //---define my new data structure here struct PayRoll { int empNumber; // Employee number string name; // Employee's name double hours; // Hours worked double payRate; // Hourly payRate double grossPay; // Gross Pay }; int main () { PayRoll employee; // employee is a PayRoll structure so create it here. //---Option: you can initialize your struct just like an array if you like //employee = {150, "Betty Ross", 40, 18.75 }; // Get the employee's number. cout << "Enter the employee's number: "; cin >> employee.empNumber; // Get the employee's name. cout << "Enter the employee's name: "; cin.ignore (); // To skip the remaining '\n' character getline (cin, employee.name); // Get the hours worked by the employee. cout << "How many hours did the employee work? "; cin >> employee.hours; // Get the employee's hourly pay rate. cout << "What is the employee's hourly payRate? "; cin >> employee.payRate; // Calculate the employee's gross pay. employee.grossPay = employee.hours * employee.payRate; // Display the employee data. cout << "Here is the employee's payroll data:\n"; cout << "name: " << employee.name << endl; cout << "Number: " << employee.empNumber << endl; cout << "hours worked: " << employee.hours << endl; cout << "Hourly payRate: " << employee.payRate << endl; cout << fixed << showpoint << setprecision (2); cout << "\n\nGross Pay: $" << employee.grossPay << endl; return 0; }