Lexington High School Mathematics Math Dept. Front Page  | Student Links  | Family Links 
Introduction to C++, Kevin Kelly Kelly Front Page  | C++ Course Guide | C++ Assignments | C++ Info

Assignment 15: Month name function

due Wednesday 3/20

Write a function monthname that returns the name of a month, based on the number of the month. For example, monthname(10) would return "October".

Your function must use a switch statement as its decision-making structure.

To test your function, write a main program that prompts the user for a date in numerical form (for example, "3 20 2002"), then outputs that date using the name of the month ("March 20, 2002").


Extensions

For 3 pts.: Make your program display an error message if the month number is outside the valid range of 1 through 12.

For 10 pts.: Without requesting any additional information from the user, also calculate the correct day of the week to be included in the output ("Wednesday, March 20, 2002"). You may research how to calculate the day of the week on the web or in a reference book. Include a comment in your program citing the source of the calculation procedure you use.