getting errors with code please help

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  /*------Header File: Employee.h-----------*/
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>

using namespace std;

#include "Date.h"
class Employee
{
	public:
		Employee ();
		Employee (string fname,string lname,int id, Date bday,Date hday, double bpay);
		void readPInfo();
		void readPayInfo();
		void printPInfo();
		void setBpay(double newBpay);
		double getBpay();
		virtual double getGpay();
		double computeTax();
		void printPayInfo();
		

	private:
		
		int idNum;
		string firstName,
		       lastName;
		Date birthDay;
		Date hireDay;
		double pay;
};

#endif

derived class

#ifndef BONUSEMPLOYEE_H
#define BONUSEMPLOYEE_H
#include <string>

using namespace std;

#include "Employee.h"
#include "Date.h"
class BonusEmployee: public Employee
{
	public:
		BonusEmployee();
BonusEmployee(string fname, string lname, int id, Date bday, Date doh, double bpay, double extrapay);
double getBonus();
void readPayInfo();
double getGpay();
double computeTax();
void printPayInfo();
private:
	double bonus;
};
#endif 

I keep getting errors on my derived class, i think its somewhere in the default constructor with parameters. anyone can help please ?
What errors? Please post the exact text.

Where is date.h?
Last edited on
BonusEmployee.cpp: In constructor `BonusEmployee::BonusEmployee(std::string, std::string, int, Date, Date, double, double)':
BonusEmployee.cpp:13: error: `stringfname' undeclared (first use this function)
BonusEmployee.cpp:13: error: (Each undeclared identifier is reported only once for each function it appears in.)
BonusEmployee.cpp:13: error: expected primary-expression before "lname"
BonusEmployee.cpp:13: error: expected primary-expression before "int"
BonusEmployee.cpp:13: error: expected primary-expression before "bday"
BonusEmployee.cpp:13: error: expected primary-expression before "doh"
BonusEmployee.cpp:13: error: expected primary-expression before "double"
Employee.h:26: error: `int Employee::idNum' is private
BonusEmployee.cpp:15: error: within this context
Employee.h:26: error: `int Employee::idNum' is private
BonusEmployee.cpp:15: error: within this context
BonusEmployee.cpp:16: error: `basePay' undeclared (first use this function)
BonusEmployee.cpp:16: error: `bPay' undeclared (first use this function)
BonusEmployee.cpp: In member function `void BonusEmployee::readPayInfo()':
BonusEmployee.cpp:24: error: `basePay' undeclared (first use this function)
BonusEmployee.cpp: In member function `virtual double BonusEmployee::getGpay()':
BonusEmployee.cpp:28: error: `getBPay' undeclared (first use this function)
BonusEmployee.cpp: In member function `double BonusEmployee::computeTax()':
BonusEmployee.cpp:33: error: `Gpay' undeclared (first use this function)
BonusEmployee.cpp: In member function `void BonusEmployee::printPayInfo()':
BonusEmployee.cpp:53: error: `basePay' undeclared (first use this function)
BonusEmployee.cpp:54: error: stray '\148' in program
BonusEmployee.cpp:54: error: `gpay' undeclared (first use this function)
BonusEmployee.cpp:54: error: stray '\' in program
BonusEmployee.cpp:54: error: stray '\148' in program
BonusEmployee.cpp:54: error: `t' undeclared (first use this function)
BonusEmployee.cpp:54: error: expected primary-expression before '.' token
BonusEmployee.cpp:55: error: stray '\148' in program
BonusEmployee.cpp:55: error: `tax' undeclared (first use this function)
BonusEmployee.cpp:55: error: stray '\' in program
BonusEmployee.cpp:55: error: stray '\148' in program
BonusEmployee.cpp:55: error: expected primary-expression before '.' token
BonusEmployee.cpp:56: error: stray '\148' in program
BonusEmployee.cpp:56: error: `net' undeclared (first use this function)
BonusEmployee.cpp:56: error: expected `;' before "pay"
BonusEmployee.cpp:56: error: stray '\' in program
BonusEmployee.cpp:56: error: stray '\148' in program
-bash-3.2$ error: expected primary-expression before "lname"
-bash: error:: command not found
-bash-3.2$ BonusEmployee.cpp:13: error: expected primary-expression before "int"
-bash: BonusEmployee.cpp:13:: command not found
BonusEmployee.cpp:13: error: expected primary-expression before "double"
Employee.h:26: error: `int Employee::idNum' is private
-bash-3.2$ BonusEmployee.cpp:13: error: expected primary-expression before "bday"
BonusEmployee.cpp:15: error: within this context
Employee.h:26: error: `int Employee::idNum' is private
-bash: BonusEmployee.cpp:13:: command not found
BonusEmployee.cpp:15: error: within this context
BonusEmployee.cpp:16: error: `basePay' undeclared (first use this function)
-bash-3.2$ BonusEmployee.cpp:13: error: expected primary-expression before "doh"
-bash: BonusEmployee.cpp:13:: command not found
-bash-3.2$ BonusEmployee.cpp:13: error: expected primary-expression before "double"
-bash: BonusEmployee.cpp:13:: command not found
-bash-3.2$ Employee.h:26: error: `int Employee::idNum' is private
> BonusEmployee.cpp:15: error: within this context
> Employee.h:26: error: `int Employee::idNum' is private
> BonusEmployee.cpp:15: error: within this context
> BonusEmployee.cpp:16: error: `basePay' undeclared (first use this function)
-bash: syntax error near unexpected token `('
-bash-3.2$ BonusEmployee.cpp:16: error: `bPay' undeclared (first use this function)
> BonusEmployee.cpp: In member function
oops im sorry here's date.h but i know there are no errors for there.
/*----------Header File:Date.h-------------*/
#ifndef DATE_H
#define DATE_H

class Date
{
public:
Date(); // default constructor
Date (int newMonth, int newDay, int newYear);
void inputDate();
void outputDate();
int getMonth();
int getDay();
int getYear();

private:
int month;
int day;
int year;
void checkDate();
};

#endif
question, does the derived class need to have different parameters than the original class ?
does the derived class need to have different parameters than the original class

No.

All the errors you posted where in BonusEmployee.cpp. Think it might be helpful to post that?
We're not mind readers.

BonusEmployee.cpp:13: error: `stringfname' undeclared

There's a space missing between between string and fname.

For the rest of the errors, I'll need to see BonusEmployee.cpp.

I asked for date.h because if I'm going to compile your program to reproduce your errors, I need ALL your include files.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
using namespace std;

#include "BonusEmployee.h"

BonusEmployee::BonusEmployee():Employee()
{
bonus=0.0;
}
BonusEmployee::BonusEmployee(string fname, string lname, int id, Date bday, Date doh, double bpay, double extrapay): Employee(string fname, string lname, int id, Date bday, Date doh, double bpay)
{
idNum = id;
basePay=bPay;
}
double BonusEmployee::getBonus()
{
return bonus;
}
void BonusEmployee::readPayInfo()
{
cin>>basePay>>bonus;
}
double BonusEmployee::getGpay()
{
return(getBPay()+bonus);
}
double BonusEmployee::computeTax()
{
double tax;
	Gpay=getGpay();
	if(Gpay>=1000)
	{
		tax=Gpay * .20;
	}
	else if(Gpay>=800)
	{
		tax=Gpay*.18;
	}
	else if(Gpay>=600)
	{
		tax=Gpay*.15;
	}
	else
		tax=Gpay*.10;
	return tax;
}
void BonusEmployee::printPayInfo()
{
cout<<endl<<bonus;
cout<<endl<<basePay;
cout<<endl<<”gpay=\t”<<Employee.getGpay();
 cout<<endl<<”tax=\t”<<Employee.computeTax();
cout<<endl<<”net pay=\t”<<(Employee.getGpay()-Employee.computeTax());  
}

SORRY HERE IS MY BonusEmployee.cpp !!!
Last edited on
BonusEmployee.cpp
------------------------
Line 13: Where you invoke the base class constructor is incorrect.
1
2
BonusEmployee::BonusEmployee(string fname, string lname, int id, Date bday, Date doh, double bpay, double extrapay) 
    : Employee(string fname, string lname, int id, Date bday, Date doh, double bpay)

Do not specify types when invoking the base class constructor. Invoking a base class constructor is just like a function call.

Line 15: You're trying to store idnum and bpay into private members of the base class. No need to do this. You're already initializing them via Employee's constructor on line 13.

Line 24,53: basePay is undefined. Did you mean pay in the base class?

Line 28: getBPay() is undefined. Did you mean getBpay (note capitialization).

Lines 33-47: gPay is undefined.

Lines 54-56: Wrong quotes used.

You have been asked to use code tags. PLEASE DO SO.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
If you're not going to make the slightest bit of effort to make your posts readable, why should we spend the slightest bit of effort helping you?
I will not respond further until you apply code tags.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
using namespace std;

#include "BonusEmployee.h"

BonusEmployee::BonusEmployee():Employee()
{
bonus=0.0;
}
BonusEmployee::BonusEmployee(string fname, string lname, int id, Date bday, Date hday, double bpay, double extrapay): Employee(fname, lname, id, bday, hday, bpay)
{
}
double BonusEmployee::getBonus()
{
return bonus;
}
void BonusEmployee::readPayInfo()
{
double bpay = getBpay();
cin>>bpay>>bonus;
}
double BonusEmployee::getGpay()
{
return(getBpay()+bonus);
}
double BonusEmployee::computeTax()
{
double tax;
	double Gpay=getGpay();
	if(Gpay>=1000)
	{
		tax=Gpay * .20;
	}
	else if(Gpay>=800)
	{
		tax=Gpay*.18;
	}
	else if(Gpay>=600)
	{
		tax=Gpay*.15;
	}
	else
		tax=Gpay*.10;
	return tax;
}
void BonusEmployee::printPayInfo()
{
double gpay=getGpay(), bpay = getBpay();
cout<<endl<<bonus;
cout<<endl<<bpay;
cout<<endl<<"gpay:\t"<< gpay;
 cout<<endl<<"tax:\t"<< computeTax();
cout<<endl<<"net pay:\t"<<(getGpay()-computeTax());  
}

hey so here are the changes I made as for your recommendations, and here are my errors now ;/

Undefined first referenced
symbol in file
main /usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/crt1.o
typeinfo for Employee /var/tmp//cc5C6Hyc.o
Employee::Employee() /var/tmp//cc5C6Hyc.o
Employee::Employee(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, Date, Date, double)/var/tmp//cc5C6Hyc.o
Employee::getBpay() /var/tmp//cc5C6Hyc.o
ld: fatal: symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

now im not getting syntax errors but unknown errors..
OMG I GOT IT TO WORK (EXECUTE) THANK YOU SO SO SOOOOO MUCH!!
Topic archived. No new replies allowed.