class organization (very elementary)

P

pauldepstein

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
 
I

Ian

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
 
N

Nick Keighley

Ian said:
(e-mail address removed) wrote:

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
 
N

Neil Cerutti

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top