a) Program code is often written using procedures. Give THREE advantages of using procedures in
b) Write an algorithm (pseudocode or flowchart) for a procedure to validate the input of a date in
February in any year.
The date should be input in the form ddmmyyyy e.g. 07021998
You will need to store each numeric part of the date separately and validate each part.
Include a calculation to determine whether the year entered is a leap year and then check that day is
within the allowed range – in a leap year there are 29 days in February otherwise there are only 28 days in
February - e.g. 29021983 is not valid as there are normally only 28 days in February, however 29021984
is valid because it is a leap year.
Leap years are determined in the following way:
If the year is a century year (such as 1800, 1900, 2000) it is a leap year if it can be divided by 400.
If the year is not a century year then it is a leap year if it can be divided by 4.

Recommended Answers

All 6 Replies

What do you have so far? Don't expect to get ready-made solutions here.

if you cant help so please @priteas so please staw away from other buisness

That's not going to happen. This is not a website where you post your problem and you get an answer. This is a place where you come to with questions about an answer and we will help you with it. You get what you put in. Putting in nothing gets you nothing.

commented: i understand and sory +0

if you cant help so please @priteas so please staw away from other buisness

I think you need to rephrase that. Try something like this:

I need to give three advantages of using procedures. I'm not sure exactly what the question is asking. I think that a procedure is XXX XXX XXX (you fill in the XXX); is that correct? If that is correct, can anyone give me a hint of what kind of thing to think about to help me work out the answer?

commented: thnk +0

Really?!? A downvote because you can't come up with an answer?

As for the validation of February dates, this is a simple leap year calculation (easily found in Wikipedia):

boolean isleap(year)
    boolean leapyear = false;
    if (year is not divisible by 4) then (it is a common year)
    if (year is not divisible by 100) then (it is a leap year)
    if (year is not divisible by 400) then (it is a common year)
    else (it is a leap year)
    return leapyear;

This is a better algorithm than yours as it is generic and applicable to any year. Then, you just need to decide:

if (month == February)
    if ((isleap(year) and day <= 29) or (day <= 28)) then
        date is ok
        date is bogus

Do note that this is pseudo-code, but easily translatable into either C or C++.

commented: thanks +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.