Write a program that inputs (from the user) the number of hours worked and hourly rate for employees and outputs the total pay. The program should process an arbitrary number of employees; the user will terminate input by entering 0 hours worked and pay rate. Use a class called worker with:
Attributes: Hours, Rate, Total
Methods: ComputeTotal ( ) and access (SetHours ( ), GetHours ( ),
SetRate ( ), GetRate ( ), and GetTotal( )) for each of the attributes
To write a program that inputs the number of hours worked and hourly rate for employees and outputs the total pay, you can follow the steps below:
1. Create a class called `Worker` with the specified attributes: `Hours`, `Rate`, and `Total`. Implement the class with appropriate accessor and mutator methods. Here's an example in Python:
```python
class Worker:
def __init__(self):
self.hours = 0
self.rate = 0
self.total = 0
def set_hours(self, hours):
self.hours = hours
def get_hours(self):
return self.hours
def set_rate(self, rate):
self.rate = rate
def get_rate(self):
return self.rate
def get_total(self):
return self.total
def compute_total(self):
self.total = self.hours * self.rate
```
2. In the main program, create an empty list to store the workers.
```python
workers = []
```
3. Use a loop to repeatedly prompt the user for input until they enter 0 hours worked and pay rate.
```python
while True:
hours_worked = float(input("Enter hours worked (0 to quit): "))
if hours_worked == 0:
break
hourly_rate = float(input("Enter hourly rate: "))
# Create a new Worker object
worker = Worker()
# Set the hours and rate for the worker
worker.set_hours(hours_worked)
worker.set_rate(hourly_rate)
# Compute the total pay for the worker
worker.compute_total()
# Add the worker to the list
workers.append(worker)
```
4. Once the user enters 0 hours worked and pay rate, iterate over the list of workers and display their total pay.
```python
for i, worker in enumerate(workers):
print(f"Total pay for worker {i+1}: {worker.get_total()}")
```
By following these steps, you can create a program that will calculate the total pay for an arbitrary number of employees based on their hours worked and hourly rate.