Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

# C++ Program With Classes

1 reply to this topic

### #1 berni2k

berni2k

• Members
• 18 posts
• OFFLINE
•
• Local time:02:00 PM

Posted 17 June 2007 - 06:45 PM

Hi,

How could i code this fast in C++ by using classes:
I want to output the work days between two dates (start and end date input by user).

I thought through it but dont know how to code it.

My thoughts:
1) calculate (count up) the absolute days between the two dates (with using time.h and week modulo)
2) make a class with holidays
3) calculate the holidays with the Gauss easter algorithm (found it on wikipedia and some other site, see bottom of post)
4) substract the holidays from the abolute days
5) cout the absolute days and the count up of holidays and the final work days

Carl Friedrich Gauß (1777 - 1854):

a = Y mod 19
b = Y mod 4
c = Y mod 7
d = (19a + M) mod 30
e = (2b + 4c + 6d + N) mod 7

Y: year with 4 digits

M and N:
for 1583 - 1599 -> M=22, N=2
1600 - 1699 -> 22, 2
1700 - 1799 -> 23, 3
1800 - 1899 -> 23, 4
1900 - 1999 -> 24, 5
2000 - 2099 -> 24, 5
2100 - 2199 -> 24, 6
2200 - 2299 -> 25, 0
2300 - 2399 -> 26, 1
2400 - 2499 -> 25, 1

taking the above easter sunday should be: (22 + d + e).March or (d + e - 9).April
and there are 2 annomalies:
1) if the result of the above falls on the 26th of April -> easter sunday will be held on the 19th of April instead
2) If a > 10 and d = 28 and the result the 25. April, -> easter sunday be corrected to the 18. April.

but how to code this?
HELP

thx a lot

### #2 Lathrup_Baseball

Lathrup_Baseball

• Members
• 8 posts
• OFFLINE
•
• Local time:03:00 PM

Posted 03 August 2007 - 10:20 PM

Hello berni2k, I am not sure if you still need help with this, but I would like to offer some. I am new to the board or else I would have responded sooner. First, of course I know you probably don't want to hear this, I have some questions and comments. The comments:

1) C++ has some new and complex topics like classes that are hard for new and experienced programmers to grasp. Even still, there are several ways of implementing solutions to problems in C++ and you may find a class is not necessary to gain a solution.
2) Looking at the problem at hand, it would appear a class is a good way.
3) Do not expect to code anything FAST in C++, particularly with such an intermediate/advanced aspect of C++ like classes.

Now, on to the questions. Why did you chose to use a class to solve this problem? When thinking about a class, outside of the obvious like classname, you will need to think about what libraries/operations you need to perform and want to have, constructor(s) to initialize private member variables, destructors, member, private, and free functions. Why do you think you need a class for Holidays specifically?

Did you check online resources, tutorials, etc. for solutions to similar problems? This sounds pretty familiar although I have never programmed anything like this before.

I want to output the work days between two dates (start and end date input by user).
To output information, you will use the "cout << _____;", but may have to overload it for your class. Reading input in from a user can be done with "cin >> _____;" You would have two separate "cin" statements, one for reading in the start date and one for the end date. This would take place in your main function, not in the class declaration or implementation.

I thought through it but dont know how to code it.
How much experience do you have in C++? If you are just learning the language, then of course it would be hard to know where to start. If you are a novice, but have some experience with C++, then you should be familar with what I am telling you and at least be able to write/provide some pseudo code of what it is you are trying to do. You seem to have a good idea of where to go with this, but you need to really review classes and nail down what you are trying to accomplish because I suspect you can do this without the use of classes, but it would take several functions and that could get messy.

I hope this helps you out some.

Lathrup-Baseball

Edited by Lathrup_Baseball, 03 August 2007 - 10:46 PM.

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users