Assignment 1 FAQ

Assignment 1 Extended Until Wednesday, 1st December, 12:00 Noon. Other submission details as before.

This FAQ is written in response to the various questions I have been receiving regarding this assignment. If you read the responses and hints here, you should get a better idea of how to complete the assignment. Again, I strongly recommend you PLAN your assignment on paper BEFORE you begin coding.

For those of you advanced along the path of this assignment, don't get annoyed at the amount of info I am giving away. Your hard work and effort will pay off. Trust me on this

1. How do I calculate if it is a leap year or not?

I suggest that you make use of the DATE class given to you in lectures. There was a function in that class that would tell you if the year in the DATE object was a leap year or not. I suggest you change this function to work for a given year and use the algorithm given below:

leap_year(y:integer):boolean is

do

if y is a century and y is divisible by 400 then

Result := True

elseif y is divisible by 4 then

Result := True

else

Result := False

end --if

end --leap_year

2. How do I use the DATE class in my assignment?

The suggestion given above is a good one, as is the suggestion I have made to many people to change the days_in_month feature of the DATE class so that it works for any month, not just the month in the DATE object. i.e.

days_in_month(m:integer):integer is

do

inspect m

when …

end--inspcet

end --days_in_month

To use the DATE class in another class, you must first declare a DATE object. I suggest you use two DATE objects here, a DOB (date of birth) DATE object and a DOI (date of interest) DATE object. To do this you must first declare the objects (remember in my genie analogy, you must have the lamps before you can rub them):

DOB : DATE

DOI : DATE

Once declared, the object must be created (rub the lamp) with the parameters required by the make procedure in the DATE class:

!!DOB.make(22, 3, 80)

!!DOI.make(25, 12, 99)

Once the objects are created, you can utilise the features of the DATE class, such as working out if it is a leap year, or how many days in a month.

3. What other functions do we need to write?

The tutorial and practical questions should provide a good guide for this. Working out how many days between two dates is very important in this assignment, so writing a function which will do this would be useful. You may also wish to write functions or procedures that work out various biorhythm characteristics, but these might belong to a different class.

4. How do I calculate the number of days since the DOB?

If you worked this out on paper first, then you wouldn't have to ask. One possible algorithm for this is:

1. Work out the number of days from the DOI until the beginning of the year.

2. Work out the number of days from the DOB until the end of the year.

3. Multiply the number of years between the (DOI year-1) and (the DOB year +1) by 365

4. Calculate the number of leap years between the years in step 3.

5. Add up the results of Steps 1-4.

5. Did the Great and Powerful David actually make a mistake with the number of days between the two dates in the example given in the assignment?

Yes, this number is wrong. It currently reads 20527, when it should say 20529. This was due to a bug in my program. The biorhythm calculations are subsequently incorrect, since they are based on the 20527. I would like to say that this was included to test if you were paying attention, but it wasn't. It was due to a minor typo in my code. I was able to track it down easily by comparing my algorithm to my code.

I suggest you do some serious testing of your program with dates such as 1/1/2000 and 1/1/1999, which should give 365 days, and 31/12/2000 and 31/12/1999 which should give 366 days.

6. How can I calculate the biorhythm thing?

There are two ways of approaching this. The first way is to use the SINGLE_MATH class and work with SINE waves. This is more difficult, but much more robust. An example of using the SINGLE_MATH class is included here for your entertainment (these classes work out if you have made the perfect cup of tea or not depending on whether you jiggle or dangle, and for how long! Use BAGGBREUER as the root class and main as the creation procedure. Note that no creation procedure is called to create the SINGLE_MATH object. This is because the SINGLE_MATH class has no creation procedure recorded in it. This is extremely bad programming practice. If I ever see any of you doing this, then …!).

baggbreuer.e

cupper.e

The second way is to know a few facts about the cycles, which can be easily coded (if you had of done your own research, you would have found this out yourselves).

 

Physical Cycle

Emotional Cycle

Intellectual Cycle

Length

23 days

28 days

33 days

Peak Days

5, 6

7

8

Critical Days

11, 23

14, 28

16, 33

Lowest Days

17

21

24, 25

 

7. What is this ascending and descending thing?

Some texts on biorhythms say that anything above the zero line of the sine wave is ascending, while anything below is descending. Other texts say that if the slope of the wave is positive, it is ascending, while if the slope is negative, it is descending. Since biorhythms are far from being a science, I will let you choose. There will be no penalties for using one method over another on this point. For those using the SINGLE_MATH class, it would probably be easier to use the second method.

8. Can you PLEASE give me some more help?

Here is a pretty good DATE class for you and a test class to show you how to use it. Unfortunately, I think I am going to see this code regurgitated too many times. I haven't done everything for you and I haven't included any comments. Work through it yourself, I will expect comments in your code. PLEASE think for yourselves. This is not the only or the best way of doing things. Add, delete, modify as you see fit. If you have already written your own code for this, then use that, not mine. I would rather see some original thinking and will be actively looking for it.

date.e

test_date.e