Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Ansi -iso > IsLeapYear (was...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 17 of 19 Topic 189 of 215
Post > Topic >>

IsLeapYear (was: Konvalina/Wileman exercises)

by "Chris Burrows" <cfbsoftware@[EMAIL PROTECTED] > Apr 25, 2007 at 09:05 AM

"Richard Heathfield" <rjh@[EMAIL PROTECTED]
> wrote in message 
news:4NmdnVQw8NGTJLHbnZ2dnUVZ8vmdnZ2d@[EMAIL PROTECTED]
>I recently picked up "Programming with Pascal", by Konvalina and
> Wileman, McGraw-Hill, 1987 (ISBN 0-07-100536-6). I have no idea whether
> this book is considered good by the Pascal community, but it seems
> reasonably well-written, at least.
>
> By chapter 3, the authors are ready to start setting exercises for which
> the solution is a complete Pascal program. There are eleven such
> exercises at the end of that chapter.
>
> I have coded solutions for these exercises, which include the problem
> specification in the introductory comment for each exercise.
>
> Since my home unaccountably lacks a resident Pascal expert, I would
> appreciate feedback on whether these are good answers.
>
> All eleven of them may be found here:
>
> http://www.cpax.org.uk/prg/****table/pascal/pwp/exercises/ch03/index.php
>
> (Could you please direct any responses to this newsgroup rather than to
> email, so that they can be peer-reviewed? Thanks.)
>

The isleapyear function in example 10 is implemented as:

  function isleapyear(year:integer):boolean;
  var leap:boolean;
  begin
    leap := false;
    if year mod 4 = 0 then
    begin
      leap := true;
      if year mod 100 = 0 then
      begin
        leap := false;
        if year mod 400 = 0 then
        begin
          leap := true;
        end
      end
    end;
    isleapyear := leap;
  end;

This could be alternatively implemented as follows:

function IsLeapYear(year: integer): boolean;
begin
   IsLeapYear := (year mod 4 = 0) and ((year mod 100 <> 0) or (year mod
400 
= 0))
end;

By way of explanation, consider this hypothetical Pascal example
(logically 
correct, but exaggerated to illustrate the point):

var
   a, b: boolean;
....
....
if (a <> true) then
   begin
      b := true
   end
else begin
  if a = true then
    begin
      b := false
    end
end;

This simplifies to:

  if a then b := false else b := true;

which further simplifies to:

  b := not a;

--
Chris Burrows
CFB Software
http://www.cfbsoftware.com/gpcp
 




 19 Posts in Topic:
Konvalina/Wileman exercises
Richard Heathfield <rj  2007-04-23 13:49:56 
Re: Konvalina/Wileman exercises
scott moore <nospam@[E  2007-04-23 09:37:19 
Re: Konvalina/Wileman exercises
CBFalconer <cbfalconer  2007-04-23 15:14:56 
Re: Konvalina/Wileman exercises
Richard Heathfield <rj  2007-04-23 20:57:34 
Re: Konvalina/Wileman exercises
CBFalconer <cbfalconer  2007-04-23 19:57:30 
Re: Konvalina/Wileman exercises
Richard Heathfield <rj  2007-04-24 11:36:06 
Re: Konvalina/Wileman exercises
"Chris Burrows"  2007-04-24 22:19:26 
Re: Konvalina/Wileman exercises
Richard Heathfield <rj  2007-04-24 13:59:58 
Re: Konvalina/Wileman exercises
CBFalconer <cbfalconer  2007-04-24 14:38:35 
Re: Konvalina/Wileman exercises
Richard Heathfield <rj  2007-04-24 21:49:47 
Re: Konvalina/Wileman exercises
CBFalconer <cbfalconer  2007-04-24 18:58:17 
Re: Konvalina/Wileman exercises
Richard Heathfield <rj  2007-04-25 06:03:14 
Re: Konvalina/Wileman exercises
CBFalconer <cbfalconer  2007-04-25 09:01:10 
Re: Konvalina/Wileman exercises
Richard Heathfield <rj  2007-04-25 13:47:57 
Re: Konvalina/Wileman exercises
CBFalconer <cbfalconer  2007-04-25 11:03:27 
Re: Konvalina/Wileman exercises
Richard Heathfield <rj  2007-04-25 16:57:07 
IsLeapYear (was: Konvalina/Wileman exercises)
"Chris Burrows"  2007-04-25 09:05:24 
Re: IsLeapYear (was: Konvalina/Wileman exercises)
CBFalconer <cbfalconer  2007-04-24 20:14:39 
Re: IsLeapYear (was: Konvalina/Wileman exercises)
Richard Heathfield <rj  2007-04-25 06:12:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 0:22:28 CDT 2008.