need help need help in calculations

need help in calculation with functions at bottom after the end of the main program. mine only calculates one person. and also need help with the bubble sort (need to arrange employees through their lastname)

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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int SZ = 55;
void tellUser();
int readData( string [], string [], string [], double [], double []);
double regular(int);
double overtime(int);
double grossPay(int);
int main()
{
   string firstname[SZ], lastname[SZ];
   stirng empids[SZ];
   double hours[SZ];
   double rates[SZ];
   ofstream outputFile;
   bool swapmade = false;
   bool screenonly = false;
   char yesno;
   
   numemp = readData(firstname, lastname, empids, hours, rates);
   for (i = 0; i < numemp; i++)
   {
     cout << firstname[i] << lastname[i] << empids[i], hours[i],
        << rates[i] << endl; 
   }
   return 0;
 }

  int readData{string firstn[], string lastn[], string empID[];
  double hrs[], double rate[];
  { 
     int numemp;
     ifstream inputFile;
     int i = 0;
     tellUser();  
     // open file and read inputs from employees.txt
     inputFile.open("employees.txt");
     if (inputFile.fail())
     {
        cout << "Error opening file employees.txt \n\n";
        cout << "end of program\n\n";
     }
     else
     {
       while ((inputFile >> hrs[i]) && (i < SZ))
       {
         inputFile >> rate[i];
         inputFile >> empID[i];
         inputFile >> firstn[i];
         inputFile >> lastn[i];
         i++;
       } //end while
       cout << "There were " << i << " employess\n\n";
       numemp = i;
       inputFile.close();
       //************* close input file ****************//
       cout << "input file closed\n\n";
       cout << "sorting golfer\n";
       lastpos = numemp;
       do
       {
         lastpos--;
         swapmade = false;
         for ( i = 0; i < lastpos; i++)
         {
            swap(firstn[i], firstn[i+1]);
            swap(lastn[i], lastn[i+1]);
            swap(empID[i], empID[i+1]);
            swap(hrs[i], hrs[i+1]);
            swap(rate[i], rate[i+1]);
            swapmade - true;
         }
       } while(swapmade);

       cout << "Payroll being written to file payroll.txt\n";
       outputFile.open("payroll.txt"); // output file
       if (outputFile.fail())
       {
          screenonly = true;
          cout <<" output file did not open\n";
          cout <<" output file will only be sent to the screen\n";
       } 
       cout <<"First   Last   Employee   Hours    Rate   Regular  Overtime   Gross\n";
       cout <<"Name    Name   Number     Worked  of Pay    Pay     Pay        Pay\n";
      cout <<"===================================================================\n";
                
      for ( i=0; i < numemp; i++)
      {
          cout<< setw(7) <<  firstn[i] << setw(13) << lastn[i];
          cout<< setw(12) << empID[i] << " " << setw(10) << hrs[i] << " ";
          cout<< setw(11) << rate[i] << " " << setw(11) << regular <<  " ";
          cout<< setw(11) << overtime << " " << setw(11) << grossPay << " \n";
          if (!screenonly)
          {
              outputFile << setw(7) << left << firstn[i] << " ";
              outputFile << setw(7) << left << lastn[i] << " ";
              outputFile << setw(4) << fixed << right << empID << " "; 
              outputFile << setw(4) << fixed << right << hrs[i] << " ";
              outputFile << setw(4) << fixed << right << rate[i] << " \n";
          }
      }
      if (!screenonly)
      { 
         outputFile.close(); cout << "Output file closed\n\n";}
   } // end else
} //end main
/*
 *function
 *
 */
void tellUser()
{
   cout <<"\nThis program reads a file called employees.txt,\n";
   cout <<"and it calculates the regular pay, overtime pay\n";
   cout <<"and grosspay and total for grosspay for each employee and\n";
   cout <<"sorts the from last name.\n";
   cout<<"output is written to the screen. \n\n"; //tell user what program does
}
/*
 *kkk
 *
 */
double regular(int &)
{
  double grossPay;
  double hours, rate;
  if(hours <= 40)
      grossPay = hours * rate;
}
/*
 *ll
 *
 */
double overtime(int &)
{
  double hours, rate;
 // const int emp_hrs = 40;
 // const double emp_over = 1.5;
  if (hours >= 40) 
     overtime = (hours - 40) * rate * 1.5;
}
/*
 *dd
 */
double grossPay(int &)
{
  double hours, rate; 
  if (hours <= 40)
     grossPay = hours * rate;
  else
     grossPay = regular + overtime;
}
Last edited on
need help
int readData( string [], string [], string [], double [], double []);

I don't think all compilers support that.

I don't know what you mean by sorting it by last name. Alphabetically?

1
2
3
4
5
6
7
8
double grossPay(int &)
{
  double hours, rate; 
  if (hours <= 40)
     grossPay = hours * rate;
  else
     grossPay = regular + overtime;
}
You didn't initialize those variables. That will result in undefined behavior.

You also have to return a double.
Last edited on
@ Lumpkin (956) imeant this:
Write a function to read the input file and store the data in arrays.
Write a function to calculate regular pay.
Write a function to calculate overtime pay
Write a function to calculate gross pay.
Write a function to bubble sort the employees into order by last name, first name.
Write any swap functions that are needed.
Write a function to write output to a file called payroll.txt

Format of file is EMPLOYEES.TXT[/b]

1
2
3
4
5
6
7
8
9
10
Hours Pay Rate Employee Number First Name Last name
40.0   10.00         A1234                    Jane      Adams
50.0   10.00         L8765                     Mary      Lincoln
25.5   10.85         W7654                   Martha    Washington
52.0   15.75         A9876                     John     Adams
45.0   25.00         W1235                   George   Washington
40.25  55.00         L9087                     Abraham   Lincoln
30.0    9.75         T9876                     William    Tell
42.5   12.50         M7654                    Missy    Muffett
30.0   10.00         P8765                        Peter     Piper

need help
Topic archived. No new replies allowed.