I am writing a program and I have a .txt file that has a some information about people. I would like to write that information into an array and then display that information about the person.
The problem is that I don't know how many names will be in the .txt file, or how to write that information to the file.
Here is what I have so far.
#include <iostream>
#include "StaffEmployee.h"
#include "HourlyEmployee.h"
#include <iomanip>
#include <fstream>
using namespace std;
void upload()
{
ifstream infile;
infile.open ("hourly.txt");
while (!infile.eof())
{
}
}
int main()
{
const int size = 20;
HourlyEmployee a[size];
HourlyEmployee fellow;
HourlyEmployee person(10, 55, "Electronics", "Alan", "Good", "E1234") ;
fellow.display();
person.display();
return 0;
}
and here is my hourlyEmployee class.
#include "Employee.h"
#include <iostream>
#include <string>
using namespace std;
#ifndef HOURLYEMPLOYEE_H
#define HOURLYEMPLOYEE_H
class HourlyEmployee:public Employee
{
private:
double hourlyWage;
double hoursWorked;
string deptName;
public:
HourlyEmployee()
{
hourlyWage = 0;
hoursWorked = 0;
deptName = "unknown";
}
HourlyEmployee(double hWage, double hWorked, string dName, string first, string last, string ID) : Employee(first, last, ID)
{
hourlyWage = hWage;
hoursWorked = hWorked;
deptName = dName;
}
void set_hourlyWage(double hWage)
{
hourlyWage = hWage;
}
void set_hoursWorked(double hWorked)
{
hoursWorked = hWorked;
}
void set_deptName(string dName)
{
deptName = dName;
}
double get_hourlyWage()
{
return hourlyWage;
}
double get_hoursWorked()
{
return hoursWorked;
}
string get_deptName()
{
return deptName;
}
void compute_salary()
{
double salary = 0;
salary = hoursWorked * hourlyWage;
cout << "2 Week Salary: $" << salary;
cout << endl;
}
void display()
{
Employee::display();
double salary = 0;
salary = hoursWorked * hourlyWage;
cout << "2 Week Salary: $" << salary;
cout << endl;
cout << endl;
}
};
#endif
I don't really know how to put the .txt information into the array so if anyone could give me some idea's or any help at all that would be great.
Thanks