Question on Classes

This is a discussion on Question on Classes within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, Can someone please review this for me I think I'm doing everything right but every time I try ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    3

    Question on Classes

    Hi everyone,
    Can someone please review this for me I think I'm doing everything right but every time I try to compile I get an error message saying fatal error C1083 this is my code:

    //program to test employee class

    #include<iostream.h>
    #include<string.h>
    #include"Employee.h"
    #include"Staff.h"
    #include"Faculty.h"

    void main(void){

    Employee *e;


    Staff s;
    Faculty f;

    s.setFirst_name("Eric"); //set first & last name and salary
    s.setLast_name("Jones");
    s.setsalary(50000.00);

    e=&s;

    //Print out name and monthly salary for salary employee

    cout<<"The staff individual's first name is: "<<e->getFirst_name()<<endl;
    cout<<"The staff individual's last name is: "<<e->getLast_name()<<endl;
    cout<<"The staff individual's pay is: "<<e->compute_monthly_pay()<<endl;

    //Print out name and monthly salary for hourly employee

    f.setFirst_name("Mary"); //set first & last name and salary
    f.setLast_name("Smith");
    f.sethourly_rate(50.00);
    e = &f;

    cout<<"The faculty individual's first name is: "<<e->getFirst_name()<<endl;
    cout<<"The faculty individual's last name is: "<<e->getLast_name()<<endl;
    cout<<"The faculty individual's pay is: "<<e->compute_monthly_pay()<<endl;

    }





    //Faculty class


    #include "Employee.h"

    class Faculty : public Employee
    {
    public:
    float compute_monthly_pay();
    Faculty();
    virtual ~Faculty();
    void sethourly_rate(float); //set salary
    float gethourly_rate();

    protected:

    float hourly_rate;


    };


    Faculty::Faculty()
    {
    }
    Faculty::~Faculty()
    {
    }

    void Faculty::sethourly_rate(float h_r) //set hourly rate
    {
    hourly_rate = h_r ;
    }

    float Faculty::gethourly_rate()
    {
    return hourly_rate;
    };

    float Faculty::compute_monthly_pay() //compute pay
    {
    return (hourly_rate*160);
    }






    //Employee class
    #include<string.h>

    class Employee {

    private:

    char* First_name;
    char* Last_name;


    public:
    virtual float compute_monthly_pay(void) = 0;
    Employee(); //default constructor
    ~Employee(); // default destructor
    const char* getFirst_name()const;
    const char* getLast_name()const;
    void setFirst_name(char*); //set first name
    void setLast_name(char*); //set last name


    };




    Employee::Employee()
    {

    }

    Employee::~Employee() //delete first and last name
    {
    delete[] First_name;
    delete[] Last_name;
    }

    const char* Employee::getFirst_name() const
    {
    return First_name;
    }

    void Employee::setFirst_name(char* fn) //set first name
    {
    First_name = new char[strlen(fn) + 1];
    strcpy(First_name,fn);
    }

    void Employee::setLast_name(char* ln) //set last name
    {
    Last_name = new char[strlen(ln) + 1];
    strcpy(Last_name, ln);
    }

    const char* Employee::getLast_name()const
    {
    return Last_name;
    }




    //Staff class

    #include "Employee.h"

    class Staff : public Employee
    {
    public:
    float compute_monthly_pay();
    Staff();
    virtual ~Staff();
    void setsalary(float); //set salary
    float getsalary();
    // float compute_monthly_pay();

    protected:
    float salary;
    };


    #include "Staff.h"


    Staff::Staff()
    {

    }

    Staff::~Staff()
    {

    }


    void Staff::setsalary(float sal)
    {
    salary = sal;
    }

    float Staff::getsalary()
    {
    return salary;
    };

    float Staff::compute_monthly_pay()
    {
    return (salary/12);

    }

  2. #2
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    1st: Use code tags (check the everyone read post above).

    2nd: Dont post a gazillion pages of code without telling us where you get the error.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    3
    I believe the error is from the employee class...

  4. #4
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Dammit i didnt mean like that post the piece of code where the error is and put a comment on the error line! Like Catfish says: Help US help YOU!

  5. #5
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    code tags!

    Code:
    Hi everyone, 
    Can someone please review this for me I think I'm doing everything right but every time I try to compile I get an error message saying fatal error C1083 this is my code: 
    
    //program to test employee class 
    
    #include<iostream.h> 
    #include<string.h> 
    #include"Employee.h" 
    #include"Staff.h" 
    #include"Faculty.h" 
    
    void main(void){ 
    
    Employee *e; 
    
    
    Staff s; 
    Faculty f; 
    
    s.setFirst_name("Eric"); //set first & last name and salary 
    s.setLast_name("Jones"); 
    s.setsalary(50000.00); 
    
    e=&s; 
    
    //Print out name and monthly salary for salary employee 
    
    cout<<"The staff individual's first name is: "<<e->getFirst_name()<<endl; 
    cout<<"The staff individual's last name is: "<<e->getLast_name()<<endl; 
    cout<<"The staff individual's pay is: "<<e->compute_monthly_pay()<<endl; 
    
    //Print out name and monthly salary for hourly employee 
    
    f.setFirst_name("Mary"); //set first & last name and salary 
    f.setLast_name("Smith"); 
    f.sethourly_rate(50.00); 
    e = &f; 
    
    cout<<"The faculty individual's first name is: "<<e->getFirst_name()<<endl; 
    cout<<"The faculty individual's last name is: "<<e->getLast_name()<<endl; 
    cout<<"The faculty individual's pay is: "<<e->compute_monthly_pay()<<endl; 
    
    } 
    
    
    
    
    
    //Faculty class 
    
    
    #include "Employee.h" 
    
    class Faculty : public Employee 
    { 
    public: 
    float compute_monthly_pay(); 
    Faculty(); 
    virtual ~Faculty(); 
    void sethourly_rate(float); //set salary 
    float gethourly_rate(); 
    
    protected: 
    
    float hourly_rate; 
    
    
    }; 
    
    
    Faculty::Faculty() 
    { 
    } 
    Faculty::~Faculty() 
    { 
    } 
    
    void Faculty::sethourly_rate(float h_r) //set hourly rate 
    { 
    hourly_rate = h_r ; 
    } 
    
    float Faculty::gethourly_rate() 
    { 
    return hourly_rate; 
    }; 
    
    float Faculty::compute_monthly_pay() //compute pay 
    { 
    return (hourly_rate*160); 
    } 
    
    
    
    
    
    
    //Employee class 
    #include<string.h> 
    
    class Employee { 
    
    private: 
    
    char* First_name; 
    char* Last_name; 
    
    
    public: 
    virtual float compute_monthly_pay(void) = 0; 
    Employee(); //default constructor 
    ~Employee(); // default destructor 
    const char* getFirst_name()const; 
    const char* getLast_name()const; 
    void setFirst_name(char*); //set first name 
    void setLast_name(char*); //set last name 
    
    
    }; 
    
    
    
    
    Employee::Employee() 
    { 
    
    } 
    
    Employee::~Employee() //delete first and last name 
    { 
    delete[] First_name; 
    delete[] Last_name; 
    } 
    
    const char* Employee::getFirst_name() const 
    { 
    return First_name; 
    } 
    
    void Employee::setFirst_name(char* fn) //set first name 
    { 
    First_name = new char[strlen(fn) + 1]; 
    strcpy(First_name,fn); 
    } 
    
    void Employee::setLast_name(char* ln) //set last name 
    { 
    Last_name = new char[strlen(ln) + 1]; 
    strcpy(Last_name, ln); 
    } 
    
    const char* Employee::getLast_name()const 
    { 
    return Last_name; 
    } 
    
    
    
    
    //Staff class 
    
    #include "Employee.h" 
    
    class Staff : public Employee 
    { 
    public: 
    float compute_monthly_pay(); 
    Staff(); 
    virtual ~Staff(); 
    void setsalary(float); //set salary 
    float getsalary(); 
    // float compute_monthly_pay(); 
    
    protected: 
    float salary; 
    }; 
    
    
    #include "Staff.h" 
    
    
    Staff::Staff() 
    { 
    
    } 
    
    Staff::~Staff() 
    { 
    
    } 
    
    
    void Staff::setsalary(float sal) 
    { 
    salary = sal; 
    } 
    
    float Staff::getsalary() 
    { 
    return salary; 
    }; 
    
    float Staff::compute_monthly_pay() 
    { 
    return (salary/12); 
    
    }
    cut him a little slack, notice he has only 3 posts, and probably doesn't know how to use code tags
    "uh uh uh, you didn't say the magic word"
    -Jurassic Park

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >void main(void){
    Big no-no, main returns an int.

    >I get an error message saying fatal error C1083
    C1083 means that the compiler can't open one or all of your header files. Make sure they are in the correct directory. You will probably also want to place inclusion guards around each header so that they aren't included more than once in the program, this tends to cause problems:
    Code:
    #ifndef HEADERNAME_H_
    #define HEADERNAME_H_
    // Header code goes here
    #endif
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes question...
    By Raigne in forum C++ Programming
    Replies: 24
    Last Post: 09-12-2006, 01:46 AM
  2. Replies: 2
    Last Post: 07-28-2006, 02:59 PM
  3. Simple Question about Classes
    By Loctan in forum C++ Programming
    Replies: 5
    Last Post: 06-26-2006, 02:40 AM
  4. Classes and Win32 API, and another Question
    By philvaira in forum Windows Programming
    Replies: 10
    Last Post: 04-10-2004, 07:21 PM
  5. Newbie question about the Private type in classes
    By Ryeguy457 in forum C++ Programming
    Replies: 1
    Last Post: 09-07-2002, 10:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21