My first issue was getting it to open and read the text file contents... Woot it does that.
Compiles fine, no errors.
However... When it gets to the CalcRate, GrossPay, Display... it goes down hill and display mem locations.
Any advice...
And I still have another program to code... I suppose if I get this one in working order then all should be well.
I am suppose to use a class... I figure I could just have it read the text file, display it there... then just have it show the gross pay overall... but I think I may have to set it so that it shows the totalpay for each employee before the overall gross pay.
But either way... something is going screwy somewhere...
I hate programming... I'm not going to be a programmer... but I'm stuck in this class...
Any advice... PLEASE! Oh and it's due tomorrow!
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct NameType
{
string last;
string first;
char middle;
};
struct DateType
{
int month;
int day;
int year;
};
struct RecType
{
int ID;
NameType name;
DateType dob;
float rate;
float totalpay;
int hours;
DateType start_date;
NameType Supervisor;
};
class ListType
{
public:
ListType( );
void Insert(RecType);
bool GetNext(RecType &);
void Reset( );
private:
RecType DB[20];
int current;
int noemp;
};
ListType::ListType()
{
current = 0;
noemp = 0;
}
void ListType::Insert(RecType rec)
{
DB[current] = rec;
current++;
noemp++;
}
bool ListType::GetNext(RecType& rec)
{
if (current > noemp || noemp >= -1)
return false;
else
{
rec = DB[current];
current++;
return true;
}
}
void ListType::Reset()
{
current = 0;
}
void Read_Input(ifstream&, ListType&);
float GrossPay(RecType&);
float CalcRate(RecType&);
void Display(RecType);
int main(){
ifstream inF;
inF.open("employee.txt");
if (!inF)
{
cout <<"**Can't open input file**"<< endl;
return 1;
}
ListType Empl;
RecType Emp;
Read_Input(inF, Empl);
cout<<"you are here 1"<<endl;
CalcRate(Emp);
cout<<"you are here2"<<endl;
Display(Emp);
cout<<"you are here 3"<<endl;
cout<<"the gross pay is "<<GrossPay(Emp);
cout<<"you are here 4"<<endl;
return 0;
}
float CalcRate(RecType& M)
{
float totalpay=0.0;
totalpay=M.rate*M.hours;
return totalpay;
}
float GrossPay(RecType& M)
{
float gross=0.0;
gross=gross+M.totalpay;
return gross;
}
void Display(RecType M)
{
cout<<"you made it to the display"<<endl;
cout<<M.ID<<" "<< endl;
cout<<M.name.last<<" "<<M.name.first<<" "<<M.name.middle<<" "<< endl;
cout<<M.dob.month<<" "<<M.dob.day<<" "<<M.dob.year<<" "<< endl;
cout<<M.rate<<" "<<M.hours<<" "<< endl;
cout<<M.start_date.month<<" "<<M.start_date.day<<" "<<M.start_date.year<<" "<< endl;
cout<<M.Supervisor.last<<" "<<M.Supervisor.first<<" "<<M.Supervisor.middle<<" "<< endl;
}
void Read_Input(ifstream& inF, ListType& List)
{
int i;
RecType M;
i=0;
while(!inF.eof())
{
inF>>M.ID;
inF>>M.name.last>>M.name.first>>M.name.middle;
inF>>M.dob.month>>M.dob.day>>M.dob.year;
inF>>M.rate>>M.hours;
inF>>M.start_date.month>>M.start_date.day>>M.start_date.year;
inF>>M.Supervisor.last>>M.Supervisor.first>>M.Supervisor.middle;
//display onto screen
cout<<M.ID<<" "<< endl;
cout<<M.name.last<<" "<<M.name.first<<" "<<M.name.middle<<" "<< endl;
cout<<M.dob.month<<" "<<M.dob.day<<" "<<M.dob.year<<" "<< endl;
cout<<M.rate<<" "<<M.hours<<" "<< endl;
cout<<M.start_date.month<<" "<<M.start_date.day<<" "<<M.start_date.year<<" "<< endl;
cout<<M.Supervisor.last<<" "<<M.Supervisor.first<<" "<<M.Supervisor.middle<<" "<< endl;
}
i++;
List.Insert(M);
inF.ignore(100,'\n');
cin.get();
}