Apr 24, 2020 at 4:51am UTC
I'm trying to figure out how to get my changeSalary function to work as well as my listSalary, my professor told us to use the setRating function but this error keeps popping up
Undefined symbols for architecture x86_64:
"Job::setRating(double)", referenced from:
changeSalary(std::__1::vector<Job, std::__1::allocator<Job> >&) in joblist-a3fae5.o
[code]
#include <iostream>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include<vector>
using namespace std;
class Job {
private:
string position;
double salary;
int id;
public:
Job();
Job(string position, double salary, int id);
string getPosition() const;
double getSalary() const;
int getId() const;
void setPosition(string position);
void setSalary(double salary);
void setId(int id);
void print();
void read();
double setRating(double salary);
};
Job::Job() {
salary = 0;
id = 0;
}
Job::Job(string position, double salary, int id) {
this->position = position;
this->salary = salary;
this->id = id;
}
string Job::getPosition() const {
return position;
}
double Job::getSalary() const {
return salary;
}
int Job::getId() const {
return id;
}
void Job::setPosition(string position) {
this->position = position;
}
void Job::setSalary(double salary) {
this->salary = salary;
}
void Job::setId(int id) {
this->id = id;
}
void Job::read() {
cout << "Adding a new job:" << endl;
cout << "Enter the job position: ";
cin >> position;
cout << "Enter the job salary: ";
cin >> salary;
cout << "Enter the unique job id: ";
cin >> id;
}
void Job::print() {
cout<<setw(30)<<left<<position;
cout<<setw(15)<<right<<salary<<setw(15)<<id<<"\n";
}
void addJob(vector<Job>& jobs);
void listJobs(vector<Job>& jobs);
void deletejob(vector<Job>& jobs);
void changeSalary(vector<Job>& jobs);
void listSalary(vector<Job>& jobs);
int main() {
vector<Job> jobs(3);
Job artist;
Job singer;
Job engineer("Software Engineer", 4000, 3);
artist.setPosition("Artist");
artist.setSalary(3000);
artist.setId(2);
singer.setPosition("Singer");
singer.setSalary(10000.0);
singer.setId(1);
jobs[0] = engineer;
jobs[1] = artist;
jobs[2] = singer;
cout<<setw(30)<<left;
cout.precision(2);
std::cout.setf(std::ios::fixed);
cout<<setw(15)<<right<<setw(15);
int choice = 1;
while (choice != 0) {
cout << "\n0. Exit program\n"
<< "1. List Jobs\n"
<< "2. Add a Job\n"
<< "3. Delete a Job\n"
<< "4. Change a Job Salary\n"
<< "5. List by salary range\n"
<< "Choice (0-5):_ ";
cin >> choice;
if (choice == 1) {
listJobs(jobs);
} else if (choice == 2) {
addJob(jobs);
}else if (choice == 3) {
deletejob(jobs);
}else if (choice == 4) {
changeSalary(jobs);
}else if (choice == 5) {
listSalary(jobs);
} else if (choice != 0) {
cout << "\nInvalid choice!\n";
}
}
cout << "\nGoodbye!\n";
return 0;
}
void listJobs(vector<Job>& jobs) {
cout << "\nJob List:\n";
for (unsigned num = 0; num < jobs.size(); num++) {
cout << (num ) << " ";
jobs[num].print();
}
}
void addJob(vector<Job>& jobs) {
Job tempJob;
tempJob.read();
jobs.push_back(tempJob);
}
void deletejob(vector<Job>& jobs) {
cout << "Deleting a job: ";
listJobs(jobs);
int pos = 0;
cout << "Enter the item number (#): " ;
cin >> pos;
for (unsigned i = pos; i < jobs.size() - 1; i++) {
jobs[i] = jobs[i+1];
}
jobs.pop_back();
}
void changeSalary (vector<Job>& jobs) {
cout << "Change salary for a job:";
listJobs(jobs);
int pos = 0;
double newSal = 0.0;
cout << "Enter the item number (#): " ;
cin >> pos;
cout << "Enter the new salary: ";
cin >> newSal;
jobs[pos].setRating(newSal);
}
void listSalary (vector<Job>& jobs) {
double minSal = 0.0;
double maxSal = 0.0;
cout << "Searching by Salary: " << endl;
cout << "Enter minimum Salary: ";
cin >> minSal;
cout << "Enter maximum Salary: "
cin >> maxSal;
}
Apr 24, 2020 at 5:39am UTC
Yes the function Job::setRating(double) is missing. You need to ask your professor about it.
Maybe it's your task to write it.
Maybe it was just forgotten.
Apr 24, 2020 at 5:42am UTC
this is due at 11:30 tonight it might be a litte too late, do you have an idea on how to do that? I'm so lost on these last two functions and I'm having a big brainfart