Lab Chapter 5, Procedures—The Gregorian Calendar11/3/2018
Objectives of this Lab
The purpose of this lab is to:
- teach you how to use structured programming to make a program simple to create and understand;
- give you practice declaring functions and procedures;
- give practice using If-Blocks and Select-Case blocks
- let you practice the elements of good coding style, including commenting, proper indentation, and descriptive variable naming.
Programming Assignment
The instructions for your assignment are below. Please read each one carefully and thoroughly before you begin; this will end up saving you time. Hand in copies of your program code and any print-outs that were requested.
- Learn about the Gregorian calendar. The Calendar FAQ is an excellent reference about different calendars which have been used by different civilizations throughout the ages. In this assignment, we will be making a program which uses the Gregorian calendar (the one popularly used today) to decide what day of the week a given date falls on.
- For example, our program will tell the user that October 12, 1999 was a Tuesday.
- Although it is not necessary, you may wish to learn a little bit about how the Gregorian calendar works, and how it differs from other calendars. You will need to understand how to compute the day of the week on which a given date falls; this is covered in Section 2.5 of the FAQ. (This is attached to your assignment.)
- Here is a sample of the form you might create. Be sure to set the default date as the first day of the 20th century.
- Get to work! This is a fairly easy program to write, once you understand the formula for deciding which day of the week a particular date lands on. However, this assignment is not meant to teach you about the Gregorian calendar; rather, its purpose is to give you practice writing functions and procedures. Therefore, your solution must include declarations for the following functions:
- A function called DayName which returns the name of a day, e.g., "Sunday", when supplied with an integer between 0 and 6. Just as in the Calendar FAQ, we will assign 0 to Sunday, 1 to Monday, and so on. Use a Select ... Casestatement to implement this function.
- A function called CalculateDay which takes in the three integer numbers in a date (the month number, the day number, and the year number), and applies the formula in Section 2.5 of the FAQ. It should return an integer number that corresponds to the day of the week on which the supplied date falls.
- A procedure called ReadFormData which has three integer parameters: one for each field on the form. This procedure should read the form values, convert them to integers, and "communicate" these values to the procedure which calls it: ComputeDay_Click().
- A procedure called WriteAnswerToForm which has one string parameter: the name of the day which should be printed to the form.
- Try out your program. Once you think you've got it working, try it out on today's date. If that works, try it out on tomorrow's date. Once that works, tell me on what day January 1, 2000 falls.
- Turn in your assignment. Please hand in your homework assignment and program code for this assignment.
Homework Assignment
Think carefully about each of the following questions. Hand your answers typed with the programming assignment. You may discuss the questions with your partner, but you must write the answers yourself.
- Did you have any difficulties in completing the programming assignment? If so, please tell me about them, and any solutions you may have found.
- What are the benefits of structured programming?
- On the printout of your program code, identify and label each occurrence of:
- local variables (name and type)
- modular variables (name and type)
- function and procedure invocations/calls (name and where are the called from)
- parameters passed by reference (where, name and type)
- parameters passed by value (where, name and type)
- values being returned by functions (what value is returned by your function on each date submitted, try 5 dates, make a table to show your date, results, and if the computation correct)