Hey, This is the same code as my other forum for those of you who were helping me there. It is all working now, but when I go to call return_value from applicant.cpp(it has to be .cpp not .h because thats how the prof made it) Its coming up with just 0's.
#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);
int best(void);
};
Promosion::Promosion()
{
start = NULL;
lastone = NULL;
}
void
Promosion::linkup(Employeelink applicant)
{
Employeelink *another, *last, *here;
another = new Employeelink;
another->id = applicant.id;
another->skillLevel = applicant.skillLevel;
another->yearsWorked = applicant.yearsWorked;
another->next = lastone;
lastone = another;
if(start == NULL)
{
start = another;
start->before = NULL;
}
}
int
Promosion::best()
{
float bestValue;
float best[18];
int i = 0;
float totalBest;
Employeelink *point = lastone;
while(point != NULL)
{
best[i] = point->item.return_value();
point = point->next;
i++;
}
for(int x = 0; x < i; x++)
{
for(int y = 0; y < i; y++)
{
if(best[x] > best[y])
totalBest = best[x];
}
}
}
int
main()
{
int x = 0;
ifstream partin;
Employeelink emp, temp;
Promosion applicant;
Applicant app;
partin.open("applicnt.dat");
if(partin.fail())
{
cout << "Error: Unable to open file!" << endl;
partin.clear();
}
while(partin >> emp.id >> emp.skillLevel >> emp.yearsWorked)
{
app.store_id(emp.id);
app.store_skill(emp.skillLevel);
app.store_years(emp.yearsWorked);
applicant.linkup(emp);
}
applicant.best();
system("pause");
return EXIT_SUCCESS;
}
And here is the class it is calling:
/*----------------------------------------------------------------
this file includes the class Applicant and a constant of 3.4
used to calculate an applicant's value
filename: applicant.cpp
----------------------------------------------------------------*/
#include <iostream>
using namespace std;
const float indexnumber = 3.4;
class Applicant
{
protected:
int id;
char skill;
int years;
float value;
public:
Applicant(void);
void store_id(int);
void store_skill(char);
void store_years(int);
void calc_value(void);
int return_id(void);
char return_skill(void);
int return_years(void);
float return_value(void);
};
Applicant::Applicant()
{
id = 0;
skill = '@';
years = 0;
value = -1;
}
void
Applicant::store_id(int who)
{
id = who;
}
void
Applicant::store_skill(char level)
{
skill = level;
}
void
Applicant::store_years(int howlong)
{
years = howlong;
}
void
Applicant::calc_value()
{
float skillvalue, yearsvalue;
switch(skill)
{
case 'D': skillvalue = indexnumber;
break;
case 'C': skillvalue = 1.3 * indexnumber;
break;
case 'B': skillvalue = 1.7 * indexnumber;
break;
case 'A': skillvalue = 2.1 * indexnumber;
break;
default: skillvalue = 0;
}
if (years <= 5)
yearsvalue = years;
else
yearsvalue = 5 + (years - 5) * 0.5;
value = skillvalue + yearsvalue;
}
int
Applicant::return_id()
{
return id;
}
char
Applicant::return_skill()
{
return skill;
}
int
Applicant::return_years()
{
return years;
}
float
Applicant::return_value()
{
if (value == -1)
calc_value();
return value;
}
And applicnt.dat:
14101 A 6
11100 C 2
20056 D 10
15594 D 8
23231 B 12
16649 A 5
22334 B 13
19876 C 10
22435 A 9
14231 B 8
16767 C 5
17890 D 11
19045 C 16
10001 A 4
20341 B 7
14578 C 23
20011 D 20
15560 B 10