Advertisement
Guest User

parallel arrays

a guest
Mar 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <fstream>
  4.  
  5. #include <iomanip>
  6.  
  7.  
  8.  
  9.  
  10. using namespace std;
  11.  
  12.  
  13. const float FEDERALWITH_TAXRATE =.18;
  14.  
  15. const float STATEWITH_TAXRATE = .045;
  16.  
  17. const float SOCIALSEC_WITHHOLD = .02;
  18.  
  19.  
  20. const int Size = 30;
  21.  
  22.  
  23. typedef long int employee[Size];
  24.  
  25. typedef int intarray[Size];
  26.  
  27. typedef float fltarray[Size];
  28.  
  29. typedef string strarray[Size];
  30.  
  31.  
  32.  
  33. int setdata(employee,strarray,intarray,fltarray,ifstream &,fltarray,fltarray,fltarray,fltarray,fltarray,int &);
  34.  
  35.  
  36. float findgross(intarray,fltarray,fltarray,int,float &);
  37.  
  38.  
  39. void printdata(const employee,const strarray,const intarray,const fltarray, const fltarray,
  40.  
  41.             const fltarray, const fltarray);
  42.  
  43.             
  44.  
  45. void findwithholding(fltarray,int,float,fltarray);
  46.  
  47.  
  48. int main()
  49.  
  50. {
  51.  
  52. employee id;
  53.  
  54. int num = 0, count;
  55.  
  56. float totalgross;
  57.  
  58. strarray name;
  59.  
  60.    intarray hours;
  61.  
  62.    fltarray rate,gross,net,taxes,social,state;
  63.  
  64.    ifstream  fin("empdata.txt");
  65.  
  66.   
  67.  
  68. count = setdata(id,name,hours,rate,fin,gross,net,taxes,social,state,num);
  69.  
  70. findgross(hours,rate,gross,count,totalgross);
  71.  
  72.    findwithholding(gross, count,FEDERALWITH_TAXRATE, taxes);
  73.  
  74.    findwithholding(gross, count, STATEWITH_TAXRATE, state);
  75.  
  76.    findwithholding(gross, count, SOCIALSEC_WITHHOLD, social);
  77.  
  78.    printdata(id,name,hours,rate,gross,net,taxes);
  79.  
  80.   
  81.  
  82.     
  83.  
  84.   return 0;
  85.  
  86. }
  87.  
  88.  
  89. int setdata(employee id,strarray name,intarray hrs,fltarray rate,ifstream & fin,
  90.  
  91.            fltarray gross,fltarray net,fltarray taxes,fltarray social,fltarray state,int &i)
  92.  
  93. {
  94.  
  95.  
  96.  
  97.  
  98.  
  99. //int i = 0;
  100.  
  101.  
  102.  
  103.  
  104.  
  105. fin>>id[i];
  106.  
  107. while(id[i]!=0){
  108.  
  109. fin.get();
  110.  
  111. getline(fin, name[i]);
  112.  
  113. fin>>hrs[i];
  114.  
  115. fin>>rate [i];
  116.  
  117. i++;
  118.  
  119. fin>>id[i];
  120.  
  121.  
  122.  
  123.  
  124.  
  125. /*for(int i = 0; i < Size; i++)
  126.  
  127.     { fin >> id[i]>>hrs[i]>>rate[i];
  128.  
  129.             calc(hrs[i],rate[i],gross[i],taxes[i],state[i],social[i],net[i]);
  130.  
  131.           }*/
  132.  
  133.  
  134.  
  135. }
  136.  
  137.     return i;
  138.  
  139. }
  140.  
  141.  
  142. float findgross(intarray hrs, fltarray rate, fltarray gross, int count,float &totalgross)
  143.  
  144. {
  145.  
  146. for (int i = 0; i < count; i++)
  147.  
  148. {
  149.  
  150. gross[i] = rate[i]*hrs[i];
  151.  
  152. totalgross += gross[i];
  153.  
  154. }
  155.  
  156. return totalgross;
  157.  
  158. }
  159.  
  160.  
  161.  
  162. void findwithholding(fltarray gross, int count, float withhold, fltarray income)
  163.  
  164. {
  165.  
  166. for (int i = 0; i < count; i++)
  167.  
  168. {
  169.  
  170. income[i] = gross[i]*withhold;
  171.  
  172. }
  173.  
  174. }
  175.  
  176.  
  177. /*void findgross(int hours, float payrate, float &grosspay,float &fedtax,float &statetax,float &soc_withhold,float &netpay)
  178.  
  179. {   grosspay = hours * payrate;
  180.  
  181.     fedtax = grosspay * FEDERALWITH_TAXRATE;
  182.  
  183.     statetax = grosspay * STATEWITH_TAXRATE;
  184.  
  185.     soc_withhold = grosspay * SOCIALSEC_WITHHOLD;
  186.  
  187.     netpay = (grosspay - (fedtax+statetax+soc_withhold));
  188.  
  189.     
  190.  
  191.  
  192. }*/
  193.  
  194.  
  195.  void printdata(const employee id,const strarray name,const intarray hrs,const fltarray rate,
  196.  
  197.              const fltarray gross,const fltarray net,const fltarray taxes)
  198.  
  199. {     //cout <<setiosflags(ios::fixed|ios::showpoint)<<setprecision(2);
  200.  
  201. for(int j = 0; j < Size; j++)
  202.  
  203.    {
  204.  
  205.    cout << setprecision(2);
  206.  
  207. cout << left  << setw(15) << "Employee ID";
  208.  
  209. cout << right << setw(20) << "Employee Name";
  210.  
  211. cout << right << setw(20) << "Employee Hours";
  212.  
  213. cout << right << setw(20) << "Employee Rate";
  214.  
  215. cout << right << setw(20) << "Employee Gross Pay";
  216.  
  217. cout << right << setw(20) << "Employee Net Pay";
  218.  
  219. cout << endl;
  220.  
  221.  
  222.  
  223. for(int j=0;j<Size;j++){
  224.  
  225. cout << left   << setw(15) <<id[j];
  226.  
  227. cout << right  << setw(20) <<name[j];
  228.  
  229. cout << right  << setw(20) <<hrs[j];
  230.  
  231. cout << right  << setw(20) <<rate[j];
  232.  
  233. cout << right  << setw(20) <<gross[j];
  234.  
  235. cout << right  << setw(20) <<net[j] <<endl;
  236.  
  237. }
  238.  
  239.   
  240.  
  241.   
  242.  
  243.   //cout <<setw(10)<< id[i]<<setw(8)<<name[i]<<setw(6)<<hrs[i]<<setw(4)<<rate[i];
  244.  
  245.           //cout << setw(10)<<gross[i] <<setw(8)<< net[i]<<endl;
  246.  
  247.           //cout << id[i] << " " << name[i] <<" " <<hrs[i] <<" " <<rate[i] << endl;
  248.  
  249.           }
  250.  
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement