Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++, Throwing and Catching

Name: Anonymous 2005-03-04 15:26

PROGRAM 6                EXCEPTION HANDLING            
        
------------------------------------------------------------------------- 

 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.
 
 
 -------------------------------------------------------------------------

Submit Source Code listing your solution and results

Discuss

Name: Anonymous 2013-07-23 9:47

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.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List