473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

class organization (very elementary)

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 '05 #1
3 1440
Ian
pa**********@att.net 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
Dec 4 '05 #2
Ian wrote:
pa**********@att.net 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

Dec 4 '05 #3
On 2005-12-04, pa**********@att.net <pa**********@att.net> 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
Dec 6 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Tee | last post by:
Hi, I have a base usercontrol with a method (blank method, no code), I have another few usercontrols that will inherit this base usercontrol, but I want to force all the usercontrol that...
23
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
21
by: Mark Broadbent | last post by:
Consider the following statements //------- Item i = Basket.Items; //indexer is used to return instance of class Item Basket.Items.Remove(); //method on class item is fired item i = new...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
13
by: bob | last post by:
If you were designing a class to represent very large integers in C++, what kind of internal representation would be best?
32
by: Matias Jansson | last post by:
I come from a background of Java and C# where it is common practise to have one class per file in the file/project structure. As I have understood it, it is more common practice to have many...
41
by: Chris Lasher | last post by:
A friend of mine with a programming background in Java and Perl places each class in its own separate file in . I informed him that keeping all related classes together in a single file is more in...
10
by: HCB | last post by:
Hello: The book "Code Complete" recommends that you put only one class in a source file, which seems a bit extreme for me. It seems that many classes are small, so that putting several of them...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.