Hey,
I am having problems with this code, I think it is not linking up the whole file, because when I run it it only says "hi" 3 times. And also it keeps crashing because of best = point->item->return_value();
#include "applicant.cpp"
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
struct Employeelink
{
int id;
int yearsWorked;
char skillLevel;
Applicant *item;
Employeelink *next;
};
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 employee)
{
Employeelink *another;
another = new Employeelink;
another->id = employee.id;
another->skillLevel = employee.skillLevel;
another->yearsWorked = employee.yearsWorked;
lastone = another;
//start = another;
}
int
Promosion::best()
{
float value[18];
Employeelink *point;
float best[18];
point = start;
int i = 0;
float totalBest;
//point = point->next;
while(point != NULL)
{
cout << "hi" << endl;
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()
{
ifstream partin;
Employeelink emp, temp;
Promosion applicant;
partin.open("applicnt.dat");
if(partin.fail())
{
cout << "Error: Unable to open file!" << endl;
partin.clear();
}
partin >> temp.id;
while(!partin.eof())
{
emp.id = temp.id;
partin >> emp.skillLevel;
partin >> emp.yearsWorked;
applicant.linkup(emp);
}
applicant.best();
system("pause");
return EXIT_SUCCESS;
}
here is the class it calls:
/*----------------------------------------------------------------
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 here is the data in the file it reads:
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