Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > class organization (very elementary)

Reply
Thread Tools

class organization (very elementary)

 
 
pauldepstein@att.net
Guest
Posts: n/a
 
      12-04-2005
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

 
Reply With Quote
 
 
 
 
Ian
Guest
Posts: n/a
 
      12-04-2005
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
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      12-04-2005
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

 
Reply With Quote
 
Neil Cerutti
Guest
Posts: n/a
 
      12-06-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Module/Class Organization Trans Ruby 7 06-15-2007 01:35 PM
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
How to Deploy .NET across an organization Bryan Linton ASP .Net 1 01-21-2005 04:03 PM



Advertisments