Below are instructions of what is required of me and i have tried to write the program. can someone point to a right direction because i have confused myself in middle and i am stuck. Please help!

Write an employee class to encapsulate a users name, wage and
hours worked.

You should have get, set, and retrieve function for each
property, and functions that calculates their net pay
and gross pay.

Read in this information from the user, and display
their gross and net pay.

#include <iostream>
#include <string>

using namespace std;

class Employee {
private:
    int usersName;
    int hoursWorked;
    int Wage;
    int grossPay;
    int netPay;
    int payRate;
    int  percenttTaxesRate;

public:

    string getusersName() {
        return usersName;
    }

    void set usersName(string name) {
        usersName = name;
    }

    int getWage() {
        int wage = hoursWaged * payRate;
        return Wage;
    }
 int grossPay= wage + percentTaxRate;
    void setwage + PayRate(string grossPay) {
        wage*PercentTaxRate = grossPay;
    }
    int netPay(){
        grossPay-Taxes = netPay
            void setgrosspay-taxes(string netPay){
                grossPay-Taxes = netPay

    void retrieve() {
        cout << "users Name: ";
        cin >> usersName;
        cout << "wage <<"hoursWorked *payRate";
        cin >>Wage;
    }  

    void print() {
        cout << usersName << " " <<usersName;
    }
};


int main() {
    Employee Sam;
    Sam.retrieve();
    Sam.print();

    return 0;
}

Recommended Answers

All 3 Replies

What is the exact problem? You seem to have a couple of erros in the code:

int getWage() {
int wage = hoursWaged * payRate;
return Wage;
}

It should probably be "hoursWorked" and not "hoursWaged" in the part above.

int grossPay= wage + percentTaxRate; //What is this? This should be included in some method
void setwage + PayRate(string grossPay) //it's probably better if grossPay was a //numeric type, also, you can't use '+' and spaces in a method name. Perhaps you'd //better tell what you want each method to do.
{
  wage*PercentTaxRate = grossPay;
} 
int netPay()
{
  grossPay-Taxes = netPay
  void setgrosspay-taxes(string netPay){
  grossPay-Taxes = netPay
//Looks like you tried to fit two methods into one. Besides, unless I'm mistaken, you //can't write stuff like a-b=c, it should be a=c+b.

Maybe you better write what you want each method to do? Because it's a bit hard to understand that from the code.

Yes George is right.. I wrote this sample code for you. The formula might not be correct and it is missing functions, plus you have to change the variable types if you want to.... Now run this program, you will understand what you have to do.

#include <iostream>
#include <string>

using namespace std;
#define SIZE 2
/*Write an employee class to encapsulate a users name, wage and 
hours worked. 

You should have get, set, and retrieve function for each
property, and functions that calculates their net pay
and gross pay.

Read in this information from the user, and display
their gross and net pay.*/
public class employee 
{
	string _username;
	int _hours;
	int _wages;
         int Gross_Pay1;
public:
	string username_get()const{return _username;}
	void username_set(string value){ _username = value;}

	int hours_get()const{return _hours;}
	void hours_set(int value){ _hours = value;}

	int wages_get()const{return _wages;}
	void wages_set(int value){ _wages = value;}
     
	void Gross_Pay(int w,int h){
	
	Gross_Pay1 = h * w;
	
	}
        int Gross_Pay_Get()
	{ return Gross_Pay1;}

};

int main()
{
  
  employee Employees[SIZE];
  int i,h,w;
  string temp;

  for(i=0;i<SIZE;i++)
  {
	  cout<<"\nEnter the name:";
	  cin>>temp;
	  Employees[i].username_set(temp);

           cout<<"\nEnter number of hours:";
	  cin>>h;
	  Employees[i].hours_set(h);

	  cout<<"\nEnter wages:";
	  cin>>w;
	  Employees[i].wages_set(w);
      
	  Employees[i].Gross_Pay(Employees[i].wages_get(),Employees[i].hours_get());


  }

   for(i=0;i<SIZE;i++)
   {
	   cout<<"Name: "<<Employees[i].username_get()<<endl;
	   cout<<"Hours: "<<Employees[i].hours_get()<<endl;
	   cout<<"Rate:  "<<Employees[i].wages_get()<<endl;
	   cout<<"Gross Pay: "<<Employees[i].Gross_Pay_Get()<<endl;
            cout<<"========================================="<<endl;
   }



return 0;
}

Hope this helps

Note: Properties in C# are so much easier than in C++

Thank you very much. I see where i got stuck and should be back to you with clean code to scrutinize again.

Yes George is right.. I wrote this sample code for you. The formula might not be correct and it is missing functions, plus you have to change the variable types if you want to.... Now run this program, you will understand what you have to do.

#include <iostream>
#include <string>

using namespace std;
#define SIZE 2
/*Write an employee class to encapsulate a users name, wage and 
hours worked. 

You should have get, set, and retrieve function for each
property, and functions that calculates their net pay
and gross pay.

Read in this information from the user, and display
their gross and net pay.*/
public class employee 
{
	string _username;
	int _hours;
	int _wages;
         int Gross_Pay1;
public:
	string username_get()const{return _username;}
	void username_set(string value){ _username = value;}

	int hours_get()const{return _hours;}
	void hours_set(int value){ _hours = value;}

	int wages_get()const{return _wages;}
	void wages_set(int value){ _wages = value;}
     
	void Gross_Pay(int w,int h){
	
	Gross_Pay1 = h * w;
	
	}
        int Gross_Pay_Get()
	{ return Gross_Pay1;}

};

int main()
{
  
  employee Employees[SIZE];
  int i,h,w;
  string temp;

  for(i=0;i<SIZE;i++)
  {
	  cout<<"\nEnter the name:";
	  cin>>temp;
	  Employees[i].username_set(temp);

           cout<<"\nEnter number of hours:";
	  cin>>h;
	  Employees[i].hours_set(h);

	  cout<<"\nEnter wages:";
	  cin>>w;
	  Employees[i].wages_set(w);
      
	  Employees[i].Gross_Pay(Employees[i].wages_get(),Employees[i].hours_get());


  }

   for(i=0;i<SIZE;i++)
   {
	   cout<<"Name: "<<Employees[i].username_get()<<endl;
	   cout<<"Hours: "<<Employees[i].hours_get()<<endl;
	   cout<<"Rate:  "<<Employees[i].wages_get()<<endl;
	   cout<<"Gross Pay: "<<Employees[i].Gross_Pay_Get()<<endl;
            cout<<"========================================="<<endl;
   }



return 0;
}

Hope this helps

Note: Properties in C# are so much easier than in C++

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.