| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Classes - Got 4 erros and have no idea whats wrong. Please take a look and give me some advice
Okay here is the problem,
The workers have won a 7.6% pay increase, effective 6 months retroactively. This program is to accept the previous annual salary, then outputs the retroactive pay due the employee, the new annual salary, and the new monthly salary. Allow user to repeat as desired. The appropriate formulae are: const double INCREASE = 0.076; newSalary = salary * (1 + INCREASE); monthly = salary / 12; retroactive = (salary – oldSalary)/2; here is my first .cpp file "not the main" Code:
#include <iostream>
#include <iomanip>
using namespace std;
const double INCREASE = 0.076;
class Salary
{
public:
void setSal(float sal);
float newSal();
float getRetroactive(float num);
private:
float newSalary;
float oldSalary;
float retroactive;
};
void Salary::setSal(float sal)
{
oldSalary = sal;
}
float Salary::newSal()
{
newSalary = oldSalary * (1 + INCREASE);
return newSalary;
}
float Salary::getRetroactive(float num)
{
retroactive = (num - oldSalary) / 2;
return retroactive;
}
"Here is my main .cpp file" Code:
#include <iostream>
#include <iomanip>
#include "newSalary.cpp"
using namespace std;
int main()
{
Salary ss;
float oSal, nSal, ret, monthly, nMonthly;
cout << "Enter current salary: ";
cin >>oSal;
monthly = oSal / 12;
ss.setSal(oSal);
nSal = ss.newSal();
nMonthly = nSal / 12;
ret = ss.getRetroactive(oSal);
cout << "Old Monthly is: " << monthly << endl;
cout << "New Monthly is: " << nMonthly << endl << endl;
cout << "Old Salary is: " << oSal << endl;
cout << "New Salary is: " << nSal << endl << endl;
cout << "Retroactive is: " << ret << endl;
return 0;
}
And the errors i get are: ary.obj : error LNK2005: "public: void __thiscall Salary::setSal(float)" (?setSal@Salary@@QAEXM@Z) already defined in main.obj 1>newSalary.obj : error LNK2005: "public: float __thiscall Salary::newSal(void)" (?newSal@Salary@@QAEMXZ) already defined in main.obj 1>newSalary.obj : error LNK2005: "public: float __thiscall Salary::getRetroactive(float)" (?getRetroactive@Salary@@QAEMM@Z) already defined in main.obj 1>E:\Project 4\Debug\Project 4.exe : fatal error LNK1169: one or more multiply defined symbols found |
|
#2
|
||||
|
||||
|
#include "newSalary.cpp"
There's your problem. Create a file newSalary.h, move the Salary class definition to it: Code:
class Salary
{
public:
void setSal(float sal);
float newSal();
float getRetroactive(float num);
private:
float newSalary;
float oldSalary;
float retroactive;
};
and #include that file from both newSalary.cpp and main.cpp
__________________
Quote:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Classes - Got 4 erros and have no idea whats wrong. Please take a look and give me some advice |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|