CSCI 102 - Fall 2023 Fundamentals of Computation

HW 5

The Program

Your program should ask the user to enter:

Your program should then output how many days are in that month. The main challenge of this program is to correctly output the days in February based on the year (leap-years). The rules for whether a year is a leap-year are given as:

There is a leap year every year whose number is perfectly divisible by four - except for years which are both divisible by 100 and not divisible by 400. The second part of the rule affects century years. For example; the century years 1600 and 2000 are leap years, but the century years 1700, 1800, and 1900 are not. (source https://www.wwu.edu/skywise/leapyear.html )

Examples:

  1. The input: 2 2016 should output 29
  2. The input: 1 2017 should output 31
  3. The input: 11 2017 should output 30

Using Functions

To help decompose the problem, the skeleton we provide has a blank function defined that you will need to fill in:

bool isLeapYear(int year);

Think of this as just a component of your overall program that should return true or false depending on whether year is truly a leap year or not.

By solving that small task separately, it should make writing the overall program easier. You must write this function and then call it in main() as part of your overall solution.

Idioms Used

Study and consider how to use some or all of the following idioms:

Hint: Think about the order to assign your variables and how to swap variables.

Other Requirements

  1. You can prompt the user however you like (with any message) but your output should be on a separate line and be the last line of output. Our auto-grader/checker looks at the last line you produce from your program and expects to find the number of days on that line.
  2. The user should type in the month and year with a space separating them. You may assume the user will do this.
  3. If the user types in a month outside of the range 1-12 you should output -1.
  4. You should indent your code properly (i.e. one additional indentation level for the code inside each new set of {...}) and add some basic comments as to certain sections of code are trying to do at a high level. This commenting and indenting will be worth a few points on the assignment.

Please post any questions about using Vocareum on EdStem.

This assignment will be submitted through Vocareum.

When you start the assignment in Vocareum you should see a file months.cpp in the work area in the left hand window pane. Click months.cpp to open the file in the editor. You should see some comments in the editor. Enter your name and email in the indicated lines. From there you can read the other comments and then either delete them or simply leave them and start your program code beneath the comments.

Write your program (it will save automatically when you click outside of the editor window). When you’re ready to test it, you can:

Repeat the build and run process until you believe your code works. Then click the Submit button. This will submit your code. You are allowed to submit as many times as you like. When you click Submit, our scripts will automatically run a few (not all) of our grading test cases through your program and report the results. Look at those results to ensure your code is passing these basic tests. If everything passes, you are done! Your code is submitted. If something fails, you can simply go back edit, build, run, and submit again (as much as you like).

If you have submitted on Vocareum at this point you are done! The instructions below are only if you want to use some other editor/compiler to write your code.

You can write your program using any editor and compiler (if you have one installed on your machine) but will eventually need to upload your code in a file named months.cpp to Vocareum. In addition, you may also write and test your code on an online editor/compiler such as:

cpp.sh Website

CodingGround Website

Leave your browser window open with your code since it is not permanently saved anywhere.

When you believe your program is finished leave that browser tab/window open and in a new tab/window, login to Vocareum, start the HW5 assignment (LeapYear Part), and in the upper-left of the resulting window, click New..File. A textbox will appear where you can type in the filename (leave the work/ portion there and) just type months.cpp. In the left window pane you should now see months.cpp appear (it must be named months.cpp) and you can click on it to open it. A blank window should appear on the right. Cut/paste your code from your other tab/window to this window and you can click Submit. When you click submit it should run a few automated tests to let you know if it compiled and passed some basic sanity checks. Look at the output to ensure things are working. If not, you’ll need to modify your code in Vocareum or back in your other tab/window and then cut/paste back to Vocareum.

Be sure you click submit otherwise your code will just be saved, but not submitted!!