sfsd
dfasfa
Syntax:
No syntax
#include <iostream>
#include <new>
#include <fstream>
using namespace std;
//Create global variables
int num_empl;
//Prototypes
void getInfo(int*, double*, char*, double*);
void toFile(int*, double*, char*, double*);
int main()
{
//Ask for number of employees
cout << "Enter the number of employees: ";
cin >> num_empl;
cout << "\n\n";
//Create arrays
int *idNums = new int [num_empl];
double *years = new double [num_empl];
char *sex = new char [num_empl];
double *wage = new double [num_empl];
//Run function getInfo
getInfo(idNums, years, sex, wage);
toFile(idNums, years, sex, wage);
//Delete arrays
delete[] idNums, years, sex, wage;
return 0;
}
//Function gets information for employees
void getInfo(int *id, double *yr, char *sx, double *wg)
{
//Go through employees one at a time to get info
for (int i = 0; i < num_empl; i++)
{
//Get ID, Gender, Wage, and Years with company
cout << "For Employee #" << i + 1 << endl;
cout << "ID: ";
cin >> *(id + i);
cout << "Gender: ";
cin >> *(sx + i);
cout << "Hourly Wage: ";
cin >> *(wg + i);
cout << "Years w/ Company: ";
cin >> *(yr + i);
cout << "\n\n";
}
}
//Function writes employee info to file
void toFile(int *id, double *yr, char *sx, double *wg)
{
//Open output stream
ofstream outputFile;
//Open file for output
outputFile.open("Employee_List.txt");
//Check if connection is made
if (outputFile.fail())
{
//Quit if no connection is made
cout << "The output file failed to open.\n";
exit(1);
}
cout << "The file opened successfully\n\n";
//Go through employee list one at a time
for (int i = 0; i < num_empl; i++)
{
//Output ID, Gender, Wage, and Years to external file
outputFile << "For Employee #" << i + 1
<< "\nID: "
<< *(id + i)
<< "\nGender: "
<< *(sx + i)
<< "\nHourly Wage: "
<< *(wg + i)
<< "\nYears w/ Company: "
<< *(yr + i)
<< "\n\n";
}
outputFile << "END";
cout << "The file was written to successfully\n\n";
//Close file
outputFile.close();
}