1. Define an Employee class.
a) has data members EmpNum and Pay.
b) EmpNum has format XXX-Y where each X is a digit in {0-9} and
Y is a letter in {A-M}.
c) Pay is in {1000-7000}.
d) member function SetEmpNum to validate and assign value to EmpNum.
e) member function SetPay to validate and assign value to Pay.
f) constructor to accept values for EmpNum and Pay.
g) exception InvalidEmpNum to be thrown from constructor when an
invalid value for EmpNum is received.
h) exception InvalidPay to be thrown from constructor when an
invalid value for Pay is received.
2. Write a test program to demonstrate the exceptions.
If an error is found, the exception should be thrown by the invalid object. So you'll have to split EmpNum outside (thanks to the OO properties of C++)
We can define an f-coalgebra to describe your program. But to incorporate exceptions, we need to adjust the state space, which is undesirable, because it complicates the space. We can however choose to adjust the codomain, creating an coalgebra:
S -> S x E
This has some drawbacks, but keeps our state space nice and simple.
In C++ we have the concept of a loop or a computation that doesn't terminate. To fully describe your system we need the following adjustment:
S -> Sb x E, where Sb = bottom U S
With this structure, we can describe your specification on a more rationale basis. So is E = {InvalidEmpNum, InValidPay} and S is a copointed functor with arrows Pay : S -> N and Empnum : S -> N x Char and a natural transformation S -> Sb.
Following this line, you could create a suitable model of computation, which you can transfer back to C++. I hope it helps.
Seems that he tries to use coalgebras to structure the computation, but he fails to some extent. He claims that C++ throws an exception at every computation step.
A f(unctor)-coalgebra is a mathematical structure with a endofunctor F : C -> C (this is a map between Categories, (which are maps between objects). In this case C contains the state space, the variables of your program.
And a morphism t : a -> F b (which represent the stateful computations). If you want to fit an algorithm, it should have this form.
Only algorithms that use state are nicely modelled with coalgebras, others are rather cumbersome.
Name:
Anonymous2013-07-23 16:15
>>21
Can't Haskell be modeled with a less gay math known as Abstract Algebra?
Because he is an idiot, who cannot find work. If you need to sage a post, put sage in the email field.
Name:
Anonymous2013-07-25 16:58
>>30
No, just someone who notices patterns easily. I've never seen him using sage.
Name:
Anonymous2013-07-25 17:04
>>32
Well I suppose either Walmart or Safeway would hire him if he told them that he was mentally retarded. This is because both of these firms hire retards all the time. Presumably because that is the one group that the management can look "smart" in front of or what nit.
Name:
Anonymous2013-07-25 17:06
>>34
By the way, I know this from personal experience because wasted three years of my life working as an associate at Walmart. And like, uh, right now, I work for Safeway.
Name:
Anonymous2013-07-28 14:45
What happened OP? You got your homework done in time?
Name:
Anonymous2013-07-29 0:56
>>36
Not yet, but he got an extension so it's fine.
The reason that people are hardly helping, is that it is extremely simple and thus boring.
recipe:
Make three stub classes (Employee, InvalidPay, InvalidEmpNum)
The last two should derive from exception.
Add your members to your employee class, make the protected: empNum and pay
Add your functions to your employee class, make them public: SetEmpNum, SetPay. Check the input they receive. Throw the appropiate exception if the input is not correct. Else modify the member field.
Done with this shit. Now show the 4 cases, which can happen:
Input of
Payment EmpNum
correct correct
incorrect correct
correct incorrect
incorrect incorrect
Describe what happens for each one. Done. Why does he need an extension for this?