📄 pc2_15.cpp
字号:
// Chapter 2 of C++ How to Program
// Programming Challenge 15 (Solution)
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
using std::fixed;
#include <iomanip>
using std::setprecision;
int main()
{
int paycode;
int numManagers = 0; // number of managers paid
int numHourly = 0; // number of hourly workers paid
int numCommission = 0; // number of commision workers paid
int numPiece = 0; // number of piece workers paid
double salary; // total salary
cout << "Enter paycode (-1 to end): " << fixed
<< setprecision( 2 );
cin >> paycode;
while( paycode != -1 ) {
switch( paycode ) {
case 1:
numManagers++;
cout << "Manager Selected." << endl;
cout << "Enter Weekly Salary: ";
cin >> salary;
cout << "Manager's pay is $ "
<< salary << endl;
break;
case 2:
double wage;
int hours;
numHourly++;
cout << "Hourly worker Selected." << endl;
cout << "Enter the hourly salary: ";
cin >> wage;
cout << "Enter the total hours worked: ";
cin >> hours;
if ( hours <= 40 )
salary = hours * wage;
else
salary = 40.0 * wage + ( hours - 40 ) * wage * 1.5;
cout << "Hourly worker's pay is $ "
<< salary << endl;
break;
case 3:
int sales;
numCommission++;
cout << "Commission Worker Selected." << endl
<< "Enter gross weekly sales: ";
cin >> sales;
salary = sales * .057 + 250;
cout << "Commission worker's pay is $ "
<< salary << endl;
break;
case 4:
int pieces;
double wagePerPiece;
numPiece++;
cout << "Piece worker Selected." << endl
<< "Enter number of pieces: ";
cin >> pieces;
cout << "Enter wage per piece: ";
cin >> wagePerPiece;
salary = pieces * wagePerPiece;
cout << "Piece worker's pay is $ "
<< salary << endl;
break;
default:
break;
} // end switch
cout << "\nEnter paycode (-1 to end): ";
cin >> paycode;
} // end while
cout << "\n\nTotal number of managers paid : "
<< numManagers << endl
<< "Total number of hourly workers paid : "
<< numHourly << endl
<< "Total number of commission workers paid: "
<< numCommission << endl
<< "Total number of piece workers paid : "
<< numPiece << endl;
return 0;
} // end main
/**************************************************************************
* (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
* Hall. 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 + -