Split string variable.

I have to split fullname string variable into First name and Last name.
And write function that write the converted employee's full name, grosspay, net pay to an external file. This is what i have done so far. I could creat sequential file but I don't how to make function that writes converted employee's full name, gross pay, and net pay to external file that I already created.
I don't know what to do after that. Is there anyone who can help me???
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

#include <iostream>
#include <iomanip>
#include <limits>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <string>


using namespace std;

void displayWelcomeMessage();
void getInput(int &, double &, double &, char &, string &);
double calculateGrossPay(double , double , double, double, double);
double calculateFederalTax(double, double, double);
double calculateNetPay(double, double, double, double);
double calculateUnionDues(double, char);
void displayPayrollSummaryInfo(double , double , double , double , double , double);
void displayTerminationMessage();
void displayLowGrossID(double LowAverageID[], double GrossPay[]);

int main() 
{
int EmployIdentificationNumber[5];
double Hours[5];
double PayRate[5];
char UnionCode[5];
double RegularPay[5];
double OvertimePay[5];
double GrossPay[5];
double FederaltaxRate[5];
double FederalTax[5];
double UnionDues[5];
double NetPay[5];
double LowAverageID[6];
int NumEmployees = 0;
double TotalGrossPay;
double HighestGrossPay = -999;
double HighestGrossPayEmployee = 0;
double LowestGrossPay = 999;
double LowestGrossPayEmployee = 0;
double AverageGrossPay = 0;
string EmployeeName[6];
string FName;
string LName;

ofstream outEmployeeFile( "employee_payroll_check.txt" , ios::out);

if ( !outEmployeeFile )
{
	cerr << "File could not be opened" << endl;
	exit ( EXIT_FAILURE);
}

displayWelcomeMessage ();

for (int x = 0; x < 5; x++)
{
	
getInput(EmployIdentificationNumber[x], Hours[x], PayRate[x], UnionCode[x], EmployeeName[x]);


GrossPay[x] = calculateGrossPay(GrossPay[x], Hours[x], RegularPay[x], PayRate[x], OvertimePay[x]);
FederalTax[x] = calculateFederalTax(GrossPay[x], FederaltaxRate[x], FederalTax[x]);
NetPay[x] = calculateNetPay(NetPay[x], GrossPay[x], FederalTax[x], UnionDues[x]);
UnionDues[x] = calculateUnionDues(UnionDues[x], UnionCode[x]);



NumEmployees++;
 TotalGrossPay += GrossPay[x];
 AverageGrossPay = TotalGrossPay / NumEmployees;
 if( GrossPay[x] > HighestGrossPay )
 {
 HighestGrossPay = GrossPay[x];
 HighestGrossPayEmployee = EmployIdentificationNumber[x];
 }
 if( GrossPay[x] < LowestGrossPay )
 {
 LowestGrossPay = GrossPay[x];
 LowestGrossPayEmployee = EmployIdentificationNumber[x];
 }
 


}//FOR LOOP

for(int x = 0; x < 5; x++)
{
	if (GrossPay[x] < AverageGrossPay)
	{
		LowAverageID[x] = EmployIdentificationNumber[x];
	}

}
displayPayrollSummaryInfo(NumEmployees, TotalGrossPay, HighestGrossPay, HighestGrossPayEmployee, LowestGrossPay, LowestGrossPayEmployee);
displayLowGrossID(LowAverageID, GrossPay);
displayTerminationMessage ();
return 0;
}//end of main 



void displayWelcomeMessage()
{
	cout << "Payment Calculator" << endl;
}

void getInput(int &EmployIdentificationNumber, double &Hours, double &PayRate, char &UnionCode, string &EmployeeName)
{

    cout << endl;
	cout << "Put Your Information" << endl;	
	cout << "Employ Identification Number : "; cin >> EmployIdentificationNumber;
	cout << "Employee Name                : "; cin >> EmployeeName;



	cout << "Hours                        : "; cin >> Hours;	
	while ( Hours > 60 || Hours < 0 )
	{
    cout << "you entered :"; cout << Hours;
    cout << endl;
	cout << "it has to be 1 to 60";
	cout << endl;
	cout << "Input Different Number";
	cout << endl;
	cout << "Hours       : ";     cin >> Hours;

	}
	cout << "Pay Rate                     : "; cin >> PayRate;
	while ( PayRate > 45  || PayRate < 7.5 )
	{
    cout << "you entered : "; cout << PayRate;
    cout << endl;
	cout << "it has to be $7.50 to $45.00";
	cout << endl;
	cout << "Input Different Number";
	cout << endl;
	cout << "PayRate     : ";     cin >> PayRate;

	}
	cout << "Union Code                   : "; cin >> UnionCode;
	while ( UnionCode != 'A' && UnionCode != 'B' && UnionCode != 'C')
	{
    cout << "you entered  "; cout << UnionCode;
    cout << endl;
	cout << "it has to be A, B or C";
	cout << endl;
	cout << "Union Code                      : ";     cin >> UnionCode;

	cout << endl;
	cout << endl;
	}
}//end of getinput

double calculateGrossPay(double GrossPay, double Hours, double RegularPay, double PayRate, double OvertimePay)
{
	if (Hours <= 40)
	{
		RegularPay = Hours * PayRate;
	}
	if (Hours > 40 )
	{
		RegularPay = 40 * PayRate;
		OvertimePay = (Hours - 40) * (PayRate * 1.5);
	}
		return GrossPay = RegularPay + OvertimePay;	
}//end of calcultage grosspay

double calculateFederalTax(double GrossPay, double FederaltaxRate, double FederalTax)
{
	if (GrossPay > 2000)
		FederaltaxRate = 0.25;
	else if (GrossPay > 1000)
		FederaltaxRate = 0.15;	
	else if  (GrossPay <= 1000)
		FederaltaxRate = 0.10;

	return FederalTax = GrossPay * FederaltaxRate;		
}//end of calculate federaltax

double calculateUnionDues(double UnionDues, char UnionCode)
{

	switch (UnionCode){
	case 'A':
		UnionDues = 25;
		break;
	case 'B':
		UnionDues = 50;
		break;
	case 'C':
		UnionDues = 75;
		break;
	default:
		cout << "The Code has to be A, B, or C";
		cout << endl;

	}//end of switch
}//end of calculate UnionDues

double calculateNetPay(double NetPay, double GrossPay, double FederalTax, double UnionDues)
{
	return NetPay = GrossPay - (FederalTax + UnionDues);
}
void displayPayrollSummaryInfo(double NumEmployees, double TotalGrossPay, double HighestGrossPay, double HighestGrossPayEmployee, double LowestGrossPay, double LowestGrossPayEmployee)
{
cout << endl;
cout << endl;
cout << fixed;
cout << "The Numbers of Employees you input   : " << setprecision(2)  << NumEmployees << endl;
cout << "Total Gross Pay                      : " << setprecision(2)  << TotalGrossPay << endl;
cout << "The Highest Gross Pay                : " << setprecision(2)  << HighestGrossPay << endl;
cout << "Employee with the highest Gross Pay  : " << HighestGrossPayEmployee << endl;
cout << fixed;
cout << "The lowest Gross Pay                 : " << setprecision(2)  << LowestGrossPay << endl;
cout << "Employee with the lowest Gross Pay   : " << LowestGrossPayEmployee << endl;
cout << fixed;
cout << "Average Gross Pay                    : " << setprecision(2)  << TotalGrossPay/NumEmployees << endl;

}
void displayLowGrossID(double LowAverageID[], double GrossPay[])
{
cout << endl; 
cout << endl; 
cout << "Employee with below Average Gross Pay " << endl; 
cout << endl;                 
  for (int x = 0; x < LowAverageID[x]; x++)
    { 
       cout <<"EmployeeNumber : " << LowAverageID[x]<<"   "<<"GrossPay  :  " << GrossPay[x] << endl;                                       
    }
}  

void displayTerminationMessage()
{
cout << endl;
cout << endl;
cout << endl;
cout << "End of System." << endl;



Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>

int main()
{
    constexpr char seperators[] = " ,.\t" ;

    const std::string full_name = "Nicolai M. Josuttis" ;
    std::cout << "full name: " << full_name << '\n' ;

    auto pos = full_name.find_first_of(seperators) ;
    if( pos != std::string::npos )
    {
        const std::string first_name = full_name.substr(0,pos) ;
        std::cout << "first name: " << first_name << '\n' ;
    }

    pos = full_name.find_last_of(seperators) ;
    if( pos != std::string::npos )
    {
        const std::string last_name = full_name.substr(pos+1) ;
        std::cout << "last name: " << last_name << '\n' ;
    }
}

http://ideone.com/He7XyA
Topic archived. No new replies allowed.