-2

a) Program code is often written using procedures. Give THREE advantages of using procedures in
programming.
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.

5
Contributors
6
Replies
34
Views
2 Years
Discussion Span
Last Post by rubberman
Featured Replies
  • > 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 … Read More

  • 1

    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) else if (year is not divisible by 100) then (it is a … Read More

1

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.

Votes + Comments
i understand and sory
2

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?

Votes + Comments
1

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)
    else
    if (year is not divisible by 100) then (it is a leap year)
    else
    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
    }
    else
    {
        date is bogus
    }
}

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

Edited by rubberman

Votes + Comments
thanks
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.