Lab2-Quiz Date: 06/03/2013 Instructor: Dr. Hacer

Lab2-Quiz
Date: 06/03/2013
Instructor: Dr. Hacer Yalım Keleş
Problem:
Define a table of the names of months of the year and the number of days in each month. Do
this using an array of structures, with each structure holding the name of a month and the
number of days in it.
(a) Write out that table ( to the console). (for month names, use first three characters of
the month name, ex: Jan,Feb, etc.)
(b) Write a function which searches a month within this table given the month name and
outputs the number of days in that month (month names will be specified as they are
stored in month table. ex: Jan, Feb, etc.). if name is not found, the function returns -1.
(c) Read continuously from the console the name of a month and and using the function
defined in (b) output the days in that month to the console.
( ‘>>’ below represents the console)
Ex:
>>please write a month name: May
>>May has 31 days
If a given name can not be found (i.e. when your function in (b) returns -1), print out:
“No such month: ”<input string>
Ex:
>>please write a month name: Monday
>>No such month: Monday
(d) When user inputs “quit” from the console, end your program
Hint: Month table
Month Name
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Number of Days
31
28
31
30
31
30
31
31
30
31
30
31
Consider the snaphot of the sample program shown below.
1
Sample run:
2