Logical Expressions and If Statements

Logical Expressions and If Statements

<p>CS150 Lab 4</p><p>Lab 4 Logical Expressions and If Statements</p><p>Date: Tuesday, September 16, 2003 Total Points: 20</p><p>For this lab, you are to write your own program that solves the following problem: for an inputted year, the program prints out if it is a leap year. Here are the rules:</p><p>1. A year is a leap year if it is divisible by 4. The only exception to this is if it is a century year. Then it is a leap year only if it is divisible by 400. In case you’re wondering, these are the rules for the Gregorian calendar, which began to be adopted in 1582 when they realized that having a leap year every 4 years resulted in the days of the year being very off after a several centuries. (The actual length of a year is 365.24219 days, not an even 365.25 days). It’s amazing what information you can find on the Internet if you look!</p><p>2. You need to determine a single logical expression that represents the above rules. You should think about this before you start programming.</p><p>3. When you think you are ready to program, create a CodeWarrior project called ‘xxxxx-lab4’ replacing ‘xxxxx’ with your last name. </p><p>4. In your program, you need to use a Boolean variable to which you assign the logical expression.</p><p>5. Then, you should use an ‘if’ statement with the Boolean variable as the condition. If the condition is true, print out a message that it’s a leap year. This message should look like something like this: 2000 is a leap year! If it’s not a leap year then a message that looks like this should print out: 1999 is not a leap year!</p><p>6. Your program should do error checking. If the user enters a negative value for the year, you should print the following message: You’ve entered an invalid year. Run the program again!</p><p>7. When you are done, show one of us that your program works. We will also look at how your code is written this time. Make sure to make a backup copy of your lab.</p><p>8. If you do not finish in lab, then place your completed program AND backup copy in the ‘CS150-01’ folder. It is due by the start of lab next Tuesday.</p><p>4/7/2018 1</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    1 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us