Header file and code not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jumpman17
    New Member
    • Sep 2007
    • 9

    #1

    Header file and code not working

    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
    [code=cpp]#ifndef EMPLOYEE_H
    #define EMPLOYEE_H
    #include <string>

    class Employee
    {
    private:
    string first_name;
    string last_name;
    string employee_id;
    public:
    Employee();
    Employee(string , string, string);
    void set_first_name( string);
    void set_last_name(s tring);
    void set_employee_id (string);
    string get_first_name( );
    string get_last_name() ;
    string get_employee_id ();
    void display_e();
    };

    #endif[/code]

    Employee.cpp
    [code=cpp]#include "Employee.h "
    #include <string>
    #include <iostream>
    using namespace std;

    Employee::Emplo yee();
    { first_name = "unknown";
    last_name = "unknown";
    employee_id = "EEEEE"; }

    Employee::Emplo yee(string first_name, string last_name, string employee_id);
    { set_first_name( first_name);
    set_last_name(l ast_name);
    set_employee_id (employee_id); }

    void Employee::set_f irst_name(strin g first);
    { first_name = first; }

    void Employee::set_l ast_name(string last);
    { last_name = last; }

    void Employee::set_e mployee_id(stri ng id);
    { employee_id = id; }

    string Employee::get_f irst_name();
    { return first_name; }

    string Employee::get_l ast_name();
    { return last_name; }

    string Employee::get_e mployee_id();
    { return employee_id; }

    void Employee::displ ay_e();
    { cout << "First name: " << first_name << endl;
    cout << "Last name: " << last_name << endl;
    cout << "Employee ID: " << employee_id << endl; }[/code]

    Lab09.cpp
    [code=cpp]#include "Employee.h "
    #include <iostream>
    #include <string>
    using namespace std;

    int main()
    {
    Employee emp("John", "Doe", "E1234");
    emp.display_e() ;

    return 0;
    }[/code]
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    I saw one problem....
    using namespace std; is missing in the employee.h file.
    i will post again if i find other errors.

    raghuram
    Last edited by gpraghuram; Nov 16 '07, 12:53 AM. Reason: Removed the code..

    Comment

    • jumpman17
      New Member
      • Sep 2007
      • 9

      #3
      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?

      Code:
      employee.cpp(6) : error C2761: '{ctor}' : member function redeclaration not allowed
      employee.cpp(7) : error C2447: '{' : missing function header (old-style formal list?)
      employee.cpp(11) : error C2761: '{ctor}' : member function redeclaration not allowed
      employee.cpp(12) : error C2447: '{' : missing function header (old-style formal list?)
      employee.cpp(16) : error C2761: 'void Employee::set_first_name(std::string)' : member function redeclaration not allowed
      employee.cpp(17) : error C2447: '{' : missing function header (old-style formal list?)
      employee.cpp(19) : error C2761: 'void Employee::set_last_name(std::string)' : member function redeclaration not allowed
      employee.cpp(20) : error C2447: '{' : missing function header (old-style formal list?)
      employee.cpp(22) : error C2761: 'void Employee::set_employee_id(std::string)' : member function redeclaration not allowed
      employee.cpp(23) : error C2447: '{' : missing function header (old-style formal list?)
      employee.cpp(25) : error C2761: 'std::string Employee::get_first_name(void)' : member function redeclaration not allowed
      employee.cpp(26) : error C2447: '{' : missing function header (old-style formal list?)
      employee.cpp(28) : error C2761: 'std::string Employee::get_last_name(void)' : member function redeclaration not allowed
      employee.cpp(29) : error C2447: '{' : missing function header (old-style formal list?)
      employee.cpp(31) : error C2761: 'std::string Employee::get_employee_id(void)' : member function redeclaration not allowed
      employee.cpp(32) : error C2447: '{' : missing function header (old-style formal list?)
      employee.cpp(34) : error C2761: 'void Employee::display_e(void)' : member function redeclaration not allowed
      employee.cpp(35) : error C2447: '{' : missing function header (old-style formal list?)

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        The issue is in the Employee.cpp file is the ; at the end of every function.
        I have corrected it...echeck it
        [code=cpp]
        #include "Employee.h "
        #include <string>
        #include <iostream>
        using namespace std;

        Employee::Emplo yee()
        { first_name = "unknown";
        last_name = "unknown";
        employee_id = "EEEEE"; }

        Employee::Emplo yee(string first_name, string last_name, string employee_id)
        { set_first_name( first_name);
        set_last_name(l ast_name);
        set_employee_id (employee_id); }

        void Employee::set_f irst_name(strin g first)
        { first_name = first; }

        void Employee::set_l ast_name(string last)
        { last_name = last; }

        void Employee::set_e mployee_id(stri ng id)
        { employee_id = id; }

        string Employee::get_f irst_name()
        { return first_name; }

        string Employee::get_l ast_name()
        { return last_name; }

        string Employee::get_e mployee_id()
        { return employee_id; }

        void Employee::displ ay_e() //dont add a ; here
        { cout << "First name: " << first_name << endl;
        cout << "Last name: " << last_name << endl;
        cout << "Employee ID: " << employee_id << endl; }

        [/code]


        Raghuram

        Comment

        • jumpman17
          New Member
          • Sep 2007
          • 9

          #5
          Thank you so much. That fixed all the errors. Now I can move on and code the rest of the program.

          Comment

          • jumpman17
            New Member
            • Sep 2007
            • 9

            #6
            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
            [code=cpp]#ifndef EMPLOYEE_H
            #define EMPLOYEE_H
            #include <string>
            using namespace std;

            class Employee
            {
            private:
            string first_name;
            string last_name;
            string employee_id;
            public:
            Employee();
            Employee(string , string, string);
            void set_first_name( string);
            void set_last_name(s tring);
            void set_employee_id (string);
            string get_first_name( );
            string get_last_name() ;
            string get_employee_id ();
            void display_e();
            };

            class StaffEmployee:p ublic Employee
            {
            private:
            int annual_salary;
            bool outsourced;
            int tax_bracket;
            public:
            StaffEmployee() ;
            StaffEmployee(s tring, string, string, int, bool, int);
            void set_annual_sala ry(int);
            void set_outsourced( bool);
            void set_tax_bracket (int);
            void display_s();
            };

            #endif[/code]

            Employee.cpp
            [code=cpp]#include "Employee.h "
            #include <string>
            #include <iostream>
            using namespace std;

            Employee::Emplo yee()
            { first_name = "unknown";
            last_name = "unknown";
            employee_id = "EEEEE"; }

            Employee::Emplo yee(string first_name, string last_name, string employee_id)
            { set_first_name( first_name);
            set_last_name(l ast_name);
            set_employee_id (employee_id); }

            void Employee::set_f irst_name(strin g first)
            { first_name = first; }

            void Employee::set_l ast_name(string last)
            { last_name = last; }

            void Employee::set_e mployee_id(stri ng id)
            { employee_id = id; }

            string Employee::get_f irst_name()
            { return first_name; }

            string Employee::get_l ast_name()
            { return last_name; }

            string Employee::get_e mployee_id()
            { return employee_id; }

            void Employee::displ ay_e()
            { cout << "First name: " << first_name << endl;
            cout << "Last name: " << last_name << endl;
            cout << "Employee ID: " << employee_id << endl; }

            StaffEmployee:: StaffEmployee()
            { annual_salary = 0;
            outsourced = false;
            tax_bracket = 1; }

            StaffEmployee:: StaffEmployee(s tring first_name, string last_name, string employee_id, int annual_salary; bool outsourced, int tax_bracket)
            { set_first_name( first_name);
            set_last_name(l ast_name);
            set_employee_id (employee_id);
            set_annual_sala ry(annual_salar y);
            set_outsourced( outsourced);
            set_tax_bracket (tax_bracket); }

            void StaffEmployee:: set_annual_sala ry(int annual)
            { annual_salary = annual; }

            void StaffEmployee:: set_outsourced( bool out)
            { outsourced = out; }

            void StaffEmployee:: set_tax_bracket (int tax)
            { tax_bracket = tax; }

            void StaffEmployee:: display_s()
            { cout << "First name: " << get_first_name( ) << endl;
            cout << "Last name: " << get_last_name() << endl;
            cout << "Employee ID: " << get_employee_id () << endl;
            cout << "Annual salary: " << annual_salary << endl;
            cout << "Outsourced : " << outsourced << endl;
            cout << "Tax bracket: " << tax_bracket << endl; }[/code]

            Lab09.cpp
            [code=cpp]#include "Employee.h "
            #include <iostream>
            #include <string>
            using namespace std;

            int main()
            {
            Employee emp("John", "Doe", "E1234");
            emp.display_e() ;

            StaffEmployee staff("Natalie" , "Simons", "E3345", 56000, true, 3);
            staff.display_s ();

            return 0;
            } [/code]

            Code:
            employee.cpp(44) : error C2143: syntax error : missing ')' before ';'
            employee.cpp(44) : error C2761: '{ctor}' : member function redeclaration not allowed
            employee.cpp(44) : error C2062: type 'int' unexpected
            employee.cpp(44) : error C2059: syntax error : ')'
            employee.cpp(45) : error C2143: syntax error : missing ';' before '{'
            employee.cpp(45) : error C2447: '{' : missing function header (old-style formal list?)

            Comment

            • oler1s
              Recognized Expert Contributor
              • Aug 2007
              • 671

              #7
              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.

              Comment

              Working...