473,511 Members | 16,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Header file and code not working

9 New Member
I'm getting like, 60 some errors and I don't know what I'm doing wrong. Everything seems to be assembled like my last assignment but it doesn't work this time. Any help on what I'm doing wrong would be appreciated.

Employee.h
Expand|Select|Wrap|Line Numbers
  1. #ifndef EMPLOYEE_H
  2. #define EMPLOYEE_H
  3. #include <string>
  4.  
  5. class Employee
  6. {
  7.     private:
  8.         string first_name;
  9.         string last_name;
  10.         string employee_id;
  11.     public:
  12.         Employee();
  13.         Employee(string, string, string);
  14.         void set_first_name(string);
  15.         void set_last_name(string);
  16.         void set_employee_id(string);
  17.         string get_first_name();
  18.         string get_last_name();
  19.         string get_employee_id();
  20.         void display_e();
  21. };
  22.  
  23. #endif
Employee.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "Employee.h"
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. Employee::Employee();
  7. {    first_name = "unknown";
  8.     last_name = "unknown";
  9.     employee_id = "EEEEE"; }
  10.  
  11. Employee::Employee(string first_name, string last_name, string employee_id);
  12. {    set_first_name(first_name);
  13.     set_last_name(last_name);
  14.     set_employee_id(employee_id); }
  15.  
  16. void Employee::set_first_name(string first);
  17. {    first_name = first; }
  18.  
  19. void Employee::set_last_name(string last);
  20. {    last_name = last; }
  21.  
  22. void Employee::set_employee_id(string id);
  23. {    employee_id = id; }
  24.  
  25. string Employee::get_first_name();
  26. {    return first_name; }
  27.  
  28. string Employee::get_last_name();
  29. {    return last_name; }
  30.  
  31. string Employee::get_employee_id();
  32. {    return employee_id; }
  33.  
  34. void Employee::display_e();
  35. {    cout << "First name: " << first_name << endl;
  36.     cout << "Last name: " << last_name << endl;
  37.     cout << "Employee ID: " << employee_id << endl; }
Lab09.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "Employee.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     Employee emp("John", "Doe", "E1234");
  9.     emp.display_e();
  10.  
  11.     return 0;
  12. }
Nov 15 '07 #1
6 5461
gpraghuram
1,275 Recognized Expert Top Contributor
I saw one problem....
using namespace std; is missing in the employee.h file.
i will post again if i find other errors.

raghuram
Nov 16 '07 #2
jumpman17
9 New Member
Hmm, I didn't think you needed that in the header but it cut my errors from 60 some to 18.

Any idea what these mean?

Expand|Select|Wrap|Line Numbers
  1. employee.cpp(6) : error C2761: '{ctor}' : member function redeclaration not allowed
  2. employee.cpp(7) : error C2447: '{' : missing function header (old-style formal list?)
  3. employee.cpp(11) : error C2761: '{ctor}' : member function redeclaration not allowed
  4. employee.cpp(12) : error C2447: '{' : missing function header (old-style formal list?)
  5. employee.cpp(16) : error C2761: 'void Employee::set_first_name(std::string)' : member function redeclaration not allowed
  6. employee.cpp(17) : error C2447: '{' : missing function header (old-style formal list?)
  7. employee.cpp(19) : error C2761: 'void Employee::set_last_name(std::string)' : member function redeclaration not allowed
  8. employee.cpp(20) : error C2447: '{' : missing function header (old-style formal list?)
  9. employee.cpp(22) : error C2761: 'void Employee::set_employee_id(std::string)' : member function redeclaration not allowed
  10. employee.cpp(23) : error C2447: '{' : missing function header (old-style formal list?)
  11. employee.cpp(25) : error C2761: 'std::string Employee::get_first_name(void)' : member function redeclaration not allowed
  12. employee.cpp(26) : error C2447: '{' : missing function header (old-style formal list?)
  13. employee.cpp(28) : error C2761: 'std::string Employee::get_last_name(void)' : member function redeclaration not allowed
  14. employee.cpp(29) : error C2447: '{' : missing function header (old-style formal list?)
  15. employee.cpp(31) : error C2761: 'std::string Employee::get_employee_id(void)' : member function redeclaration not allowed
  16. employee.cpp(32) : error C2447: '{' : missing function header (old-style formal list?)
  17. employee.cpp(34) : error C2761: 'void Employee::display_e(void)' : member function redeclaration not allowed
  18. employee.cpp(35) : error C2447: '{' : missing function header (old-style formal list?)
Nov 16 '07 #3
gpraghuram
1,275 Recognized Expert Top Contributor
The issue is in the Employee.cpp file is the ; at the end of every function.
I have corrected it...echeck it
Expand|Select|Wrap|Line Numbers
  1. #include "Employee.h"
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. Employee::Employee()
  7. {   first_name = "unknown";
  8.     last_name = "unknown";
  9.     employee_id = "EEEEE"; }
  10.  
  11. Employee::Employee(string first_name, string last_name, string employee_id)
  12. {   set_first_name(first_name);
  13.     set_last_name(last_name);
  14.     set_employee_id(employee_id); }
  15.  
  16. void Employee::set_first_name(string first)
  17. {   first_name = first; }
  18.  
  19. void Employee::set_last_name(string last)
  20. {   last_name = last; }
  21.  
  22. void Employee::set_employee_id(string id)
  23. {   employee_id = id; }
  24.  
  25. string Employee::get_first_name()
  26. {   return first_name; }
  27.  
  28. string Employee::get_last_name()
  29. {   return last_name; }
  30.  
  31. string Employee::get_employee_id()
  32. {   return employee_id; }
  33.  
  34. void Employee::display_e() //dont add a ; here
  35. {   cout << "First name: " << first_name << endl;
  36.     cout << "Last name: " << last_name << endl;
  37.     cout << "Employee ID: " << employee_id << endl; }
  38.  
  39.  

Raghuram
Nov 16 '07 #4
jumpman17
9 New Member
Thank you so much. That fixed all the errors. Now I can move on and code the rest of the program.
Nov 16 '07 #5
jumpman17
9 New Member
Alright, I'm trying to add in a child class and I'm sure that the errors I'm getting have to do with me not calling the variables right or something. It started out at 15 errors and I've got it down to 6 and now I'm stuck.

Employee.h
Expand|Select|Wrap|Line Numbers
  1. #ifndef EMPLOYEE_H
  2. #define EMPLOYEE_H
  3. #include <string>
  4. using namespace std;
  5.  
  6. class Employee
  7. {
  8.     private:
  9.         string first_name;
  10.         string last_name;
  11.         string employee_id;
  12.     public:
  13.         Employee();
  14.         Employee(string, string, string);
  15.         void set_first_name(string);
  16.         void set_last_name(string);
  17.         void set_employee_id(string);
  18.         string get_first_name();
  19.         string get_last_name();
  20.         string get_employee_id();
  21.         void display_e();
  22. };
  23.  
  24. class StaffEmployee:public Employee
  25. {
  26.     private:
  27.         int annual_salary;
  28.         bool outsourced;
  29.         int tax_bracket;
  30.     public:
  31.         StaffEmployee();
  32.         StaffEmployee(string, string, string, int, bool, int);
  33.         void set_annual_salary(int);
  34.         void set_outsourced(bool);
  35.         void set_tax_bracket(int);
  36.         void display_s();
  37. };
  38.  
  39. #endif
Employee.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "Employee.h"
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. Employee::Employee()
  7. {    first_name = "unknown";
  8.     last_name = "unknown";
  9.     employee_id = "EEEEE"; }
  10.  
  11. Employee::Employee(string first_name, string last_name, string employee_id)
  12. {    set_first_name(first_name);
  13.     set_last_name(last_name);
  14.     set_employee_id(employee_id); }
  15.  
  16. void Employee::set_first_name(string first)
  17. {    first_name = first; }
  18.  
  19. void Employee::set_last_name(string last)
  20. {    last_name = last; }
  21.  
  22. void Employee::set_employee_id(string id)
  23. {    employee_id = id; }
  24.  
  25. string Employee::get_first_name()
  26. {    return first_name; }
  27.  
  28. string Employee::get_last_name()
  29. {    return last_name; }
  30.  
  31. string Employee::get_employee_id()
  32. {    return employee_id; }
  33.  
  34. void Employee::display_e()
  35. {    cout << "First name: " << first_name << endl;
  36.     cout << "Last name: " << last_name << endl;
  37.     cout << "Employee ID: " << employee_id << endl; }
  38.  
  39. StaffEmployee::StaffEmployee()
  40. {    annual_salary = 0;
  41.     outsourced = false;
  42.     tax_bracket = 1; }
  43.  
  44. StaffEmployee::StaffEmployee(string first_name, string last_name, string employee_id, int annual_salary; bool outsourced, int tax_bracket)
  45. {    set_first_name(first_name);
  46.     set_last_name(last_name);
  47.     set_employee_id(employee_id);
  48.     set_annual_salary(annual_salary);
  49.     set_outsourced(outsourced);
  50.     set_tax_bracket(tax_bracket); }
  51.  
  52. void StaffEmployee::set_annual_salary(int annual)
  53. {    annual_salary = annual; }
  54.  
  55. void StaffEmployee::set_outsourced(bool out)
  56. {    outsourced = out; }
  57.  
  58. void StaffEmployee::set_tax_bracket(int tax)
  59. {    tax_bracket = tax; }
  60.  
  61. void StaffEmployee::display_s()
  62. {    cout << "First name: " << get_first_name() << endl;
  63.     cout << "Last name: " << get_last_name() << endl;
  64.     cout << "Employee ID: " << get_employee_id() << endl;
  65.     cout << "Annual salary: " << annual_salary << endl;
  66.     cout << "Outsourced: " << outsourced << endl;
  67.     cout << "Tax bracket: " << tax_bracket << endl; }
Lab09.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "Employee.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     Employee emp("John", "Doe", "E1234");
  9.     emp.display_e();
  10.  
  11.     StaffEmployee staff("Natalie", "Simons", "E3345", 56000, true, 3);
  12.     staff.display_s();
  13.  
  14.     return 0;
Expand|Select|Wrap|Line Numbers
  1. employee.cpp(44) : error C2143: syntax error : missing ')' before ';'
  2. employee.cpp(44) : error C2761: '{ctor}' : member function redeclaration not allowed
  3. employee.cpp(44) : error C2062: type 'int' unexpected
  4. employee.cpp(44) : error C2059: syntax error : ')'
  5. employee.cpp(45) : error C2143: syntax error : missing ';' before '{'
  6. employee.cpp(45) : error C2447: '{' : missing function header (old-style formal list?)
Nov 16 '07 #6
oler1s
671 Recognized Expert Contributor
Why were you stuck? If you look at the errors, it looks like there is a problem around line 44. So you start reading a couple of lines back (line 42, say), and look closely for syntax errors. Things like a missing semicolon, misplaced brace, etc.

I found that you had a semicolon after int annual_salary, when it should be a comma.
Nov 16 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3910
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
9
4029
by: chat | last post by:
Hi, every body. I have 3 files like this: -------------------------------------------------------- file name : header.h #ifndef TEST_H #define TEST_H int a=1; double b=0.5;
0
1073
by: srikar | last post by:
Hi all, I am working on porting of code in C++, I am having the following problem. In my code The following structure has been defined static struct rwtable { /* reserved word table */...
7
2235
by: The Cool Giraffe | last post by:
Please note that i do intend to use a header file. However, i'm not sure if it's really needed or just a convention. Suppose we have the following two files. // Something.h class Something {...
14
11718
by: Jess | last post by:
Hello, I was told that if I have a template class or template function, then the definitions must be put into the header file where I put the declarations. On the other hand, it is generally...
1
2770
by: Swapnil Kale | last post by:
Hi, I'm working on a Migration project (Forte to JAVA). The forte client had a C++ dll which used to call one more FORTE dll for a complex database calculations. Now all the forte code has...
1
1482
by: araman | last post by:
I have a header file that gets included with my main pages. I moved a file to a different folder that has the header.asp fie in it but when I go to that page the header does not get included.It works...
4
5138
by: quophyie | last post by:
Hi guys I''m a new C++ programmer and I am having a few problems with some structs that I have defined in my header file and want to use in my CPP file. The struct called "deck" is defined in a...
8
4559
by: nguillot | last post by:
Hello. If I have the following classes: class B {}; typedef B tB; if A is: class A
0
1356
by: adikat | last post by:
I am trying to set up a webpage where a user can download a .PNG image. The download works fine via computer and browser but it doesn't work when I try to download it via a browser on my Android...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7353
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7508
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.