Homework 2 — Calendar
CS110/EIE110
Macau university of Science and Technology Instructor: Zhiyao Liang
1 Introduction
We will write a C program that can print the calendar of month and year. For example, the calendar of November 2020 looks the picture shown above.[1]
The important knowledge aspects of this homework include the following:
Input and output functions.
Friendly interaction between the computer and the user.
Pretty information printing
Clear input queue before the next input. Loop statements
Branching statements (if and switch)
Implementing a menu of choices of user’s operations. Design data storage
Function design and implementation
2 Computation process of the program
The behavior of the program is as follows:
1. Print some welcome information. 2. Repeat:
Print the menu of choices and ask the user to choose one.
Respond according to the user’s choice if the choice is ‘q’, end the program.
2.1 The user menu
When the program is running, the user will see a menu the choices like the following:
Please type a character to make a choice
a: Print the calendar of a month
b: Print the calendar of a year
c: Tell the weekday for a given day.
d: Record a holiday.
e: Print all the holidays of the year
q: Quit the program.
Once a user provide a character, then the program responds accordingly. For example, when a user type a followed by Enter, then the choice of a is activated. The program is should deal with irregular inputs. For example, if the user type followed by Enter, then the choice of a should also be activated, and the extra part should not remain in the input queue to affect the next input.
2.2 Responses to menu choices
The responses of different choices are described in details here.
a: Let the user provide a month of a year, then print the calendar of the year. Especially, if a day is a holiday, then it should be printed with a * symbole. For example, when the user’s answer is November 2020 (User’s input has some indent) , the screen play could like the following. Especially, suppose Nov 1 is a holiday.
Apple
pple \n
b: Ask the user provide a year, then print the calendar of each month of the year.
c: Ask the user to provide a date, (day month year), then answer the day in a week. For example
Which month?
11 2020
—– November 2020 —– Sun Mon Tue Wed Thu Fri Sat 1* 2 3 4 5 6 7 8 9 1011121314 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ————————–
Which day you want to ask?
27 11 2020
It is Friday
d: Ask the user a date (day month year), so the program will remember it as a holiday. For example.
Next time, when a user print the calendar of November 2020, there will be a * appearing with Nov 26.
[Think] You have to find a way to record all the holidays provided by the user.
e: Print all the recorded holidays, following some order. For example, suppose only two days are recorded as holidays, then:
q: Saying Good bye and quit the program.
3 Other requirements
You should define proper functions to handle different tasks. Putting all code in the main() function will be ugly for a program that is complex enough.
Always make your code easy to understand and well organized.
4 Submission
Upload your files at the webpage address of this homework on Moodle. The uploaded files can include only the following:
The source files (.c and .h files),
An optional document file (.txt, .md, .docx) describing your work, like: what features of the homework are achieved; what are the remaining problems; how did you solve the difficulties that you met, some screen record of compiling and running the program …
About homework submission in a group:
at most 3 students can form a group to submit the homework. You can surely do the homework alone.
One group only need to submit the homework by once by one student. The other members do not need to submit anything, or just submit one .txt file saying who are the members of the group and who submitted the homework.
In each file that you submit, record the names in Chinese (if you are not an international student) and English letters, classes of each student, last 5 digits of student ID, as comments. For example:
Which day is a holiday?
26 11 2020
Ok, 26 November 2020 is a holiday.
01 11 2020
26 11 2020
Deadline: 10 days after today. Nov 21 2020 11:00pm
/* homework 1. Group members:
Li, Bai CS110 D1
*/
Du, Fu EIE110 D2
Li, Qingzhao CS110 D3
1. https://sanjomonthly.com/files/calendar-for-november-2020.jpg
↩
照清李 甫杜 白李