📄 payroll.cpp
字号:
// Tutorial 17: Payroll.cpp
// Stores employee information and calculates payroll for
// employees of various types.
#include <iostream> // required to perform C++-style stream I/O
#include <iomanip> // required for parameterized stream manipulators
using namespace std; // for accessing C++ Standard Library members
const int ARRAY_SIZE = 10; // maximum number of employees
// function prototypes
int createEmployee( SalariedEmployee * [], int );
void displayEmployees( SalariedEmployee * [], int );
// function main begins program execution
int main()
{
int count = 0; // stores the number of employees entered
int selection = 0; // stores the user's menu selection
// format output as currency
cout << fixed << setprecision( 2 );
while ( selection != 3 )
{
cout << "\nSelect one of the following options" << endl;
cout << "1 - Enter new employee information" << endl;
cout << "2 - View payroll" << endl;
cout << "3 - Exit the application" << endl;
cout << "Enter selection: ";
cin >> selection;
switch ( selection )
{
// enter employee information
case 1:
// ensure that there is space in the array
if ( count < ARRAY_SIZE )
{
count += createEmployee( employees, count );
} // end if
else
{
cout << "Error: You cannot enter any more employees."
<< endl;
} // end else
break;
// view payroll
case 2:
displayEmployees( employees, count );
break;
// exit
case 3:
break;
default:
cout << "Error: Enter a valid menu selection";
} // end switch
} // end while
return 0; // indicate that program ended successfully
} // end function main
int createEmployee( SalariedEmployee *employees[], int index )
{
// define variables
string firstName; // stores the employee's first name
string lastName; // stores the employee's last name
string SSN; // stores the employee's social security number
double salary; // stores the employee's salary
cin.ignore(); // remove newline
// prompt user for and store generic Employee information
cout << "\nEnter employee's first name: ";
getline( cin, firstName ); // get first name
cout << "Enter employee's last name: ";
getline( cin, lastName ); // get last name
cout << "Enter employee's social security number: ";
getline ( cin, SSN ); // get SSN
// prompt user for and store the salary
cout << "Enter salary: ";
cin >> salary;
return 1; // indicate that employee was created successfully
} // end function createEmployee
void displayEmployees( SalariedEmployee *employees[], int count )
{
double total = 0.0; // stores the total payroll
// ensure that employees have been entered before printing
if ( count > 0 )
{
} // end if
else
{
cout << "Error: You must enter at least one employee first."
<< endl;
} // end else
} // end function displayEmployees
/**************************************************************************
* (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
**************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -