Payroll program using classes

Hi everyone! I'm very new to C++ (this is my first semester). I have to create a payroll program using classes that will read from a file (contains employee name, ID, hours worked, and wage), calculate the salary, and display employee name, ID, and salary.

Please help me revise my code. Any suggestions/ input will be helpful. Thank you!



#include "Payroll.h"

Payroll::Payroll(string n, int i, double hours, double wage)
{
name = n;
ID = i;
hoursWorked = hours;
wages = wage;

}

void Payroll::set_name(string n)
{
name = n;
}

string Payroll::get_name()
{
return name;
}
int Payroll::get_ID()
{
return ID;
}

void Payroll::set_ID(int i)
{
ID = i;
}

double Payroll::get_hoursWorked()
{
return hoursWorked;
}
void Payroll::set_hoursWorked(double hours)
{
hoursWorked = hours;
}

double Payroll::get_wages()
{
return wages;
}
void Payroll::set_wages(double wage)
{
wages = wage;
}

double Payroll::calculate_Salary()
{
double w = wages * hoursWorked;
}

void Payroll::print_Payroll()
{
cout << "Name "<< name << "ID "<< ID << "Salary "<< wages << endl;
}


#ifndef UNTITLED5_PAYROLL_H
#define UNTITLED5_PAYROLL_H

#include <iostream>
using namespace std;


class Payroll
{
private:
string name;
int ID;
double hoursWorked;
double wages;

public:
Payroll();
Payroll(string n, int i, double hours, double wage);

double calculate_Salary (); //function call
void print_Payroll(); //function call

void set_name(string n);
string get_name();

int get_ID();
void set_ID(int i);

double get_hoursWorked();
void set_hoursWorked(double hours);

double get_wages();
void set_wages(double wage);
};


#include <iostream>
#include <fstream>
#include "Payroll.h"

using namespace std;

int main ()
{
ifstream myFile;
myFile.open("Project 3.dat");
if (myFile.fail())
{
cout <<"File not found!"<< endl;
}
else
{
int count = 0;
Payroll p;

while (!myFile.eof()) {
string foo;
switch (count) {
case 0:
p.set_name(foo);
break;
case 1:
p.set_ID(stoi(foo));
break;
case 2:
p.set_hoursWorked(stod(foo));
break;
case 3:
p.set_wages(stod(foo));
break;

}
count++;

if (count % 4 == 0)
{
count = 0;
p.print_Payroll();
}
}
}
}

I am getting this error message:

Undefined symbols for architecture x86_64:
"Payroll::Payroll()", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [untitled5] Error 1
make[2]: *** [CMakeFiles/untitled5.dir/all] Error 2
make[1]: *** [CMakeFiles/untitled5.dir/rule] Error 2
make: *** [untitled5] Error 2



You did not implement the constructor Payroll();. One way to do that:
1
2
3
4
5
6
7
Payroll::Payroll()
{
ID = 0;
hoursWorked = 0.0;
wages = 0.0;

}
Topic archived. No new replies allowed.