The program is all working now, but I'm worried because on the last linked lists assignment I got a C because I did not do the link correctly. My prof said that I did not create the links up correctly just used a stack to get descending in the last assignment. I want to make sure I did not do that this time.
Here's the code, can someone just tell me if I did it correctly.
Thanks!
#include "applicant.cpp"
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
struct Employeelink
{
int id;
int yearsWorked;
char skillLevel;
Applicant item;
Employeelink *next, *before;
};
class Promosion
{
protected:
float value;
Employeelink *start;
Employeelink *lastone;
public:
Promosion(void);
void linkup(Employeelink, Applicant);
int best(void);
};
Promosion::Promosion()
{
start = NULL;
lastone = NULL;
}
void
Promosion::linkup(Employeelink applicant, Applicant app)
{
Employeelink *another, *last, *here;
another = new Employeelink;
another->id = applicant.id;
another->skillLevel = applicant.skillLevel;
another->yearsWorked = applicant.yearsWorked;
another->item = app;
another->next = lastone;
lastone = another;
if(start == NULL)
{
start = another;
start->before = NULL;
}
}
int
Promosion::best()
{
float best[18];
int i = 0;
float largest = 0;
float totalBest;
char bestSkill[18];
int bestID[18];
int bestYears[18];
int bYears;
int bID;
char bSkill;
//boolean once = false;
Employeelink *point = lastone;
while(point != NULL)
{
best[i] = point->item.return_value();
bestSkill[i] = point->item.return_skill();
bestID[i] = point->item.return_id();
bestYears[i] = point->item.return_years();
//cout << point->item.return_value() << endl;
point = point->next;
i++;
}
for(int x = 0; x < i; x++)
{
if(best[x] > largest)
{
largest = best[x];
bYears = bestYears[x];
bID = bestID[x];
bSkill = bestSkill[x];
}
}
cout << "ID: " << bID << " Sill Level: " << bSkill << " Years worked: " << bYears << " Value: " << largest << endl;
}
int
main()
{
int x = 0;
ifstream partin;
Employeelink emp, temp;
Promosion applicant;
partin.open("applicnt.dat");
if(partin.fail())
{
cout << "Error: Unable to open file!" << endl;
partin.clear();
}
while(partin >> emp.id >> emp.skillLevel >> emp.yearsWorked)
{
Applicant app;
app.store_id(emp.id);
app.store_skill(emp.skillLevel);
//cout << app.return_skill() << endl;
app.store_years(emp.yearsWorked);
applicant.linkup(emp, app);
}
applicant.best();
system("pause");
return EXIT_SUCCESS;
}