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

Then kick your professor in the shins for it. Place the declaration in a header, and link the definitions.

will that solve my problem?

like i pointed out in the thread below this, where are you assigning anything to 'Applicant item;', ok so you changed it from a pointer to an object but where are the values? the 'app' object you create in main, should be created inside the while loop, then passed by value and assigned to another->item.

I'm not really sure what I am supposed to put in item.

Are you saying that in linkup() i have a line that says another->item = app?

Cool that worked. I dont fully understand why I needed to do that though, could you explain it?

Lets see, you have a structure Employeelink which has a data member 'Applicant item;' . Just like all the other members of this struct, you need to assign a value to this one also. Because its of type 'Applicant' you have to assign to it an instance of 'Applicant', which you are creating in the while loop. so every time you create a new(local) instance, set the proper values on the object and then pass it to the function where you populate 'item' with this instance.

Infact, you don't need to do that either, you can declare this instance inside the 'linkup' function itself and assign it to 'item' that ways you save the unnecessary pass-by-value part.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.