1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/* 1. Write a function to accept the data from the table in the order given (no $, no % entered).
2. Write a function to calculate current yearly income and new yearly income taking the wage increase into consideration
(assume 40 hr work week, 52 weeks for the year).
3. Write a function to display the data in the format given below:
Name Title Current_income New_income
Goofy Executive_Chief $xx,xxx.xx $xx,xxx.xx
Mickey Mouse VP_of_Entertainment $xx,xxx.xx $xx,xxx.xx
Donald Duck CFO $xx,xxx.xx $xx,xxx.xx
Cinderella VP of Customer Service $xx,xxx.xx $xx,xxx.xx
4. As part of the function for #3, sort the employee information by descending New Income.
Note: Use passing parameters by pointer/reference, manipulators, arrays, variables of type string, etc.
*/
#include <locale>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
void GetData( string[], string[], double[],double[]);
void CalcData(int, int, double[],double[],double[], double[]);
void PrintData(string ename[4], string etitle[4], double curr_year[], double new_year[]);
int main()
{
#ifdef _WIN32
locale loc("English_America");
#else
locale loc("en_US.UTF8");
#endif
cout.imbue(loc); // or use your ofstream object
cout << fixed << setprecision(2) << "$" << 123456789.47 << '\n';
int const hours = 40;
int const weeks = 52;
string ename[4];
string etitle[4];
double ewage[4];
double inc[4];
double curr_year[4];
double new_year[4];
GetData(ename,etitle, ewage, inc);
CalcData(hours, weeks, ewage, inc,curr_year, new_year);
PrintData(ename, etitle, curr_year, new_year);
cout<<endl; system("PAUSE");
return 0;
}
/* Function Definitions */
void GetData(string fename[], string fetitle[], double fewage[],double finc[])
{
for (int i = 0; i< 4; i++)
{
cout<<"Please enter Employee Name: "<<endl;
getline(cin,fename[i]);
cout<<"Please enter Employee Title: "<<endl;
getline(cin,fetitle[i]);
cout<<"Please enter Employee Hourly Wage: $"<<endl;
cin>>fewage[i];
cout<<"Please enter Employee Wage Increase: % "<<endl;
cin>>finc[i];
cin.ignore(80,'\n');
}
}
void CalcData(int hours, int weeks, double fewage[],double finc[],double fcurr_year[], double fnew_year[])
{
for (int i=0; i<4; i++)
{
int hours = 40;
int weeks = 52;
fcurr_year[i] = fewage[i] * hours * weeks;
fnew_year[i] = fcurr_year[i] * (( finc[i] + 100 ) / 100);
}
}
void PrintData(string fename[4], string fetitle[4], double fcurr_year[], double fnew_year[])
{
int temp, tempa;
string strtemp = "";
string strtempa = "";
cout << left << setw(20)<<"Name";
cout << left << setw(30)<<"Title";
cout << left << setw(15)<<"Current Income";
cout << left << setw(15)<<"New Income";
cout << "\n" << endl;
for (int i=0; i<4; i++)
{
for (int j= 0; j <3; j++)
{
if (fnew_year[j]<fnew_year[j+1])
{
temp=fnew_year[j];
fnew_year[j]=fnew_year[j+1];
fnew_year[j+1]=temp;
tempa=fcurr_year[j];
fcurr_year[j]=fcurr_year[j+1];
fcurr_year[j+1]=tempa;
strtemp =fename[j];
fename[j]=fename[j+1];
fename[j+1]=strtemp;
strtempa = fetitle[j];
fetitle[j]=fetitle[j+1];
fetitle[j+1]=strtempa;
}
}
}
for (int i=0; i <4; i++)
{
cout << fixed;
cout << setprecision(2);
cout << left << setw(20) << fename[i];
cout << left << setw(30) << fetitle[i];
cout << left << setw(15) << "$" << fcurr_year[i] << endl;
cout << left << setw(15) << "$" << fnew_year[i] << endl;
cout << "\n" << endl;
}
}
|