Write a program that inputs (from the user) the number of hours worked and hourly pay rate for employees and outputs their total pay. There should be processed an arbitrary number of employees; the user will terminate input by entering 0 for hours worked and rate of pay. If we use a class called Worker : How should this look like in any program language
Attributes: Hours, Rate, Total
Compute Total and access methods for each of the attributes
13 replies to this topic
#1
Posted 15 January 2011 - 08:06 PM
|
|
|
#2
Posted 15 January 2011 - 11:25 PM
What have you gotten so far? Where are you having trouble writing it?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 16 January 2011 - 05:54 AM
Given that some of us are studying esoteric languages, that is a dangerous request (any language).
Given that the nature of this problem is procedural, rather than OOP, why do you call it an OOP programming question?
Given that the nature of this problem is procedural, rather than OOP, why do you call it an OOP programming question?
#4
Posted 16 January 2011 - 07:13 AM
I have no idea what OOP language you have in mind. But since it's for any language, then I'll use UML. At least it is a language for modelling OO software project. :)
Below is an UML class diagram of how I think you should design these classes. Note that between Worker and Task there should be a collection of task. I did not put it there just to make it a bit clearer.
oop-programing-question.png 7.83K
36 downloads
Below is an UML class diagram of how I think you should design these classes. Note that between Worker and Task there should be a collection of task. I did not put it there just to make it a bit clearer.
oop-programing-question.png 7.83K
36 downloads
#5
Posted 18 January 2011 - 07:17 AM
Well I'm learning from a programming book, however I can only give an example for this problem which I found:
Class Tax
Income As Real
TaxDue As Real
Subprogram SetIncome(NewIncome)
Set Income = NewIncome
End Subprogram
Subprogram ComputeTax()
If Income <= 50000 Then
Set TaxDue = .05 * Income
Else
If Income > 50000 And Income < 100000 Then
Set TaxDue = 2500 + .07 (Income - 50000)
Else
Set TaxDue = 6000 + .11 * (Income - 100000)
End If
End If
End Subprogram
Function GetTax() As Real
Set GetTax = TaxDue
End Function
End Class
Main
Declare Tax1 As Tax
Declare Income As Real
Write “Enter an income; this program will compute the tax due.”
Write “To quit, enter 0.”
Input Income
While Income > 0
Call Tax1.SetIncome(Income)
Call Tax1.ComputeTax()
Write “Tax due = $”, GetTax()
Write “Enter an income; enter 0 to quit.”
Input Income
End While
End Program
Class Tax
Income As Real
TaxDue As Real
Subprogram SetIncome(NewIncome)
Set Income = NewIncome
End Subprogram
Subprogram ComputeTax()
If Income <= 50000 Then
Set TaxDue = .05 * Income
Else
If Income > 50000 And Income < 100000 Then
Set TaxDue = 2500 + .07 (Income - 50000)
Else
Set TaxDue = 6000 + .11 * (Income - 100000)
End If
End If
End Subprogram
Function GetTax() As Real
Set GetTax = TaxDue
End Function
End Class
Main
Declare Tax1 As Tax
Declare Income As Real
Write “Enter an income; this program will compute the tax due.”
Write “To quit, enter 0.”
Input Income
While Income > 0
Call Tax1.SetIncome(Income)
Call Tax1.ComputeTax()
Write “Tax due = $”, GetTax()
Write “Enter an income; enter 0 to quit.”
Input Income
End While
End Program
#6
Posted 18 January 2011 - 07:21 AM
Ok Thanks so much, this looks like a start I'll try to put this into a program list
#7
Posted 18 January 2011 - 07:34 AM
I'm not sure but I believe I must start with this format can you tell me if I pointed in the right direction. Methods: computTotal and access methods (sethours, GetHours, setRate, GetRate, SetTotal and getTotal) for each of the attributes.
#8
Posted 18 January 2011 - 07:36 AM
If i can get the correct line format this will work: Methods: computTotal and access methods (sethours, GetHours, setRate, GetRate, SetTotal and getTotal) for each of the attributes.
#9
Posted 19 January 2011 - 03:14 AM
You can go a few routes with this, the two obvious ones I see are as follows.
Worker is a complete class containing both data and functions to modify.
class Worker
{
float Hours, Rate, Total;
get/set Hours, Rate, Total;
}
Or worker can be a pure data class exposing itself to be used and modified as it will.
class Worker
{
float Hours, Rate, Total;
}
class PayRoll
{
vector<Worker> Employees;
get/set Hours, Rate, Total;
}
The question is solved by looking at the overall design and deciding which is more transparent, secure, and in general works best.
Worker is a complete class containing both data and functions to modify.
class Worker
{
float Hours, Rate, Total;
get/set Hours, Rate, Total;
}
Or worker can be a pure data class exposing itself to be used and modified as it will.
class Worker
{
float Hours, Rate, Total;
}
class PayRoll
{
vector<Worker> Employees;
get/set Hours, Rate, Total;
}
The question is solved by looking at the overall design and deciding which is more transparent, secure, and in general works best.
#10
Posted 19 January 2011 - 07:28 AM
This seems like Java to me... Is that the language you are using?
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]
#11
Posted 19 January 2011 - 07:29 AM
Thanks, I'm doing a flow chart and this looks good I'm going to try a few different directions, to get the best results thanks for the input.
#12
Posted 20 January 2011 - 05:41 AM
geno53 said:
If i can get the correct line format this will work: Methods: computTotal and access methods (sethours, GetHours, setRate, GetRate, SetTotal and getTotal) for each of the attributes.
Yes, sure. For each attribute you need getter and setter methods.
Quote
Thanks, I'm doing a flow chart and this looks good I'm going to try a few different directions, to get the best results thanks for the input.
If you are really into OOP, better start learning UML now. There is a diagram in UML that resembles flow chart, btw.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









