class organization (very elementary)

Discussion in 'C++' started by pauldepstein@att.net, Dec 4, 2005.

  1. Guest

    I am writing a program to calculate prices of commodity options as part
    of my Masters degree in Finance. (Absolutely no prior knowledge of
    computer programming was assumed.)

    I am representing dates as integers. It's important to be able to
    derive the month from the date so I have programmed this using mod 365
    arithmetic.

    I have several classes that use dates as private objects.

    How do I set up my get_month function (which gives the month of any
    date) so that different classes can all make use of it without me
    needing to copy and paste the code separately in each class?

    Yes, I know it's a standard problem...

    Actually, it now occurs to me that I will probably simply have a date
    class and have other classes contain a variable of the type date.

    However, there still must be a way of building functions which work on
    a variety of classes.

    I suppose I'm really asking for a good classes_for_beginners tutorial
    or website.

    Thank you,

    Paul Epstein
    , Dec 4, 2005
    #1
    1. Advertising

  2. Ian Guest

    wrote:
    > I am writing a program to calculate prices of commodity options as part
    > of my Masters degree in Finance. (Absolutely no prior knowledge of
    > computer programming was assumed.)
    >
    > I am representing dates as integers. It's important to be able to
    > derive the month from the date so I have programmed this using mod 365
    > arithmetic.
    >

    And leap years?

    How about looking up the date/time API for your platform? Doing so
    could save you a lot of unnecessary work.

    Ian
    Ian, Dec 4, 2005
    #2
    1. Advertising

  3. Ian wrote:
    > wrote:


    > > I am writing a program to calculate prices of commodity options as part
    > > of my Masters degree in Finance. (Absolutely no prior knowledge of
    > > computer programming was assumed.)
    > >
    > > I am representing dates as integers. It's important to be able to
    > > derive the month from the date so I have programmed this using mod 365
    > > arithmetic.

    >
    > And leap years?
    >
    > How about looking up the date/time API for your platform? Doing so
    > could save you a lot of unnecessary work.


    hence locking your program to a particular platform. There is the
    venerable
    time.h (or as its spelled in C++ ctime). It's a little clunky but it
    could be
    wrapped up in a class to make it a little friendlier. There is also a
    boost
    library that handles time see www.boost.org


    --
    Nick Keighley
    Nick Keighley, Dec 4, 2005
    #3
  4. Neil Cerutti Guest

    On 2005-12-04, <> wrote:
    > I am writing a program to calculate prices of commodity options
    > as part of my Masters degree in Finance. (Absolutely no prior
    > knowledge of computer programming was assumed.)
    >
    > I have several classes that use dates as private objects.
    >
    > How do I set up my get_month function (which gives the month of
    > any date) so that different classes can all make use of it
    > without me needing to copy and paste the code separately in
    > each class?


    Create a date class with the interface your classes need, and
    have your classes that need them contain dates.

    --
    Neil Cerutti
    Neil Cerutti, Dec 6, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    472
    Raymond Hettinger
    Jul 27, 2003
  2. shanx__=|;-

    very very very long integer

    shanx__=|;-, Oct 16, 2004, in forum: C Programming
    Replies:
    19
    Views:
    1,616
    Merrill & Michele
    Oct 19, 2004
  3. Abhishek Jha

    very very very long integer

    Abhishek Jha, Oct 16, 2004, in forum: C Programming
    Replies:
    4
    Views:
    418
    jacob navia
    Oct 17, 2004
  4. Peter

    Very very very basic question

    Peter, Feb 8, 2005, in forum: C Programming
    Replies:
    14
    Views:
    513
    Dave Thompson
    Feb 14, 2005
  5. olivier.melcher

    Help running a very very very simple code

    olivier.melcher, May 12, 2008, in forum: Java
    Replies:
    8
    Views:
    2,287
Loading...

Share This Page