By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,385 Members | 1,913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,385 IT Pros & Developers. It's quick & easy.

C++ program to calculate gross pay in dollars

P: 1
Develop a program that will determine the gross pay for each
of several employees. The company pays "straight time" for the first
40 hours worked by each employee and pays "time-and-a-half" for all
hours worked in excess of 40 hours. You are given a list of the
employees of the company, the number of hours each employee worked
last week and the hourly rate of each employee. your program should
input this information for each employee, and should determine and
display the employee's gross pay.
Mar 6 '17 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 9,731
What have you done so far to implement this program?
Have you designed and implemented an "employee" class?
Have you declared an array or list of employees that you will iterate through to calculate their gross pay?

Once you get started, post what you have done so far and explain the problem that you are having so we can help you.

The experts here will give you a hand with any problems you are having but it's unfair to ask them just to write your program for you. Its also unfair to you for them to do so because you won't learn anything if you don't do it yourself.
Mar 6 '17 #2

Expert 100+
P: 203
Well, I coded this as simple as possible. But I agree with @Frinavale.
Post your problem/ code after trying, as directly asking will not help you learning and building logics in programming.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. char name[10]; //For name of the employee
  6. int hours; //No. of hours an employee worked last week
  7. float rate; //Hourly rate of an employee
  8. float gross_pay;
  9. float extra; // Extra amount added to pay
  10. int num; // For number of employees
  11. //Declared variables in separate lines just for explaining purpose
  12. cout<<"Enter the number of employees: ";
  13. cin>>num;
  14. //Loop to input employee data and calculating gross salary
  15. for(int i=1; i<=num; i++)
  16. {
  17. cout<<"\n Enter the details of employee: "<<i;
  18. cout<<"\n Enter name";
  19. cin>>name;
  20. cout<<"\n Enter the number of hours worked last week: ";
  21. cin>>hours;
  22. cout<<"\n Enter the hourly rate: ";
  23. cin>>rate;
  24. extra=0;
  25. if( hours>40)
  26. {
  27.  extra=((hours-40) * (rate + (0.5*rate)));
  28. }
  30. gross_pay=(hours*rate)+extra;
  32. cout<<"\n Gross pay of the employee is: "<<gross_pay<<"\n";
  33. }
  35. return 0;
  36. }
Mar 6 '17 #3

Expert Mod 5K+
P: 9,731
See, part of the reason why I asked the original poster to reply with details about what they did is because they are using C++ to do this and C++ is an object oriented programing language.

The solution posted does not make use of objects. Is the point of doing this exercise to learn about objects? Or is it is the poster at a point in their learning journey where they are still learning how to input and output details?

Does the poster have problems with class design? Implementation?

Its really not fair to post anything in response until the original poster provides us with more details about their approach so that they can get help with the concepts or errors they need help with....instead of guessing and providing something that may or may not be helpful.
Mar 6 '17 #4

Post your reply

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