Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use the C and leave comments by your code so I can understand your work. thank you for the help! #includecalendar.h /* This program

Please use the C and leave comments by your code so I can understand your work.

thank you for the help!

image text in transcribedimage text in transcribed

#include"calendar.h" /* This program gets two commands: 1. print MM/YYYY: prints the days of a month in a table 2. count MM/DD/YYYY mm/dd/yyyy: counts the number of days between two given dates. */ int main(void) { char command[MAX_COMMAND_TOKEN_LENGTH];//placeholder for a command... char lastCharacter; while (1) {//main infinite while loop... printf("Please enter a new command... "); lastCharacter = getCommandWord(command, MAX_COMMAND_TOKEN_LENGTH); if (command[0] == 'q'&& command[1] == 'u'&& command[2] == 'i'&& command[3] == 't'&& command[4] == '\0')//(!strcmp(command, "quit")) break; else if (!strcmp(command, "print")) { if (lastCharacter == ' ') printf("Too few arguments for print command! It must be in the form of print MM/YYYY. "); else handlePrint(); } else if (!strcmp(command, "count")) { if (lastCharacter == ' ') printf("Too few arguments for count command! It must be in the form of count MM/DD/YYYY mm/dd/yyyy. "); else handleCount(); } else { printf("invalid command! Your command must start either with quit, or print, or count. "); while (lastCharacter != ' ') lastCharacter = getCommandWord(command, MAX_COMMAND_TOKEN_LENGTH); } } return 0; } char getCommandWord(char command[], int maxLength) { char lastCharacter; int i; for (i = 0; i

=================================================================================

calendar.h

#include #include #define MAX_COMMAND_TOKEN_LENGTH 15 char getCommandWord(char command[], int maxLength); int getMonth(char token[]); int getDay(char token[]); int getYear(char token[]); int monthDays(int month, int year); int isValidDate(int month, int day, int year); int compareTo(int fromMonth, int fromDay, int fromYear, int toMonth, int toDay, int toYear); void handleCount(void); int count(int fromMonth, int fromDay, int fromYear, int toMonth, int toDay, int toYear); void handlePrint(void); int isLeapYear(int year);

=======================================================================

count.c

#include"calendar.h" /* This file contains count function and some relevant functions */ int count(int fromMonth, int fromDay, int fromYear, int toMonth, int toDay, int toYear) { /* Your code comes here */ return 0; } int getMonth(char token[]) { int n; if (token[0] '9' || token[1] '9') return 0;//error in retrieving the month n = 10 * (token[0] - '0') + token[1] - '0'; if (n > 12) return 0;//error, month should be from 1 and 12... return n; }

int getDay(char token[]) { int n; if (token[0] '9' || token[1] '9') return 0;//error in retrieving the day n = 10 * (token[0] - '0') + token[1] - '0'; if (n > 31) return 0;//error, month should be from 1 and 12... return n; }

int getYear(char token[]) { int n; if (token[0] '9' || token[1] '9' || token[2] '9' || token[3] '9') return 0;//error in retrieving the year n = 1000 * (token[0] - '0') + 100 * (token[1] - '0') + 10 * (token[2] - '0') + token[3] - '0'; return n; } void handleCount(void) { /* Your code comes here */ } int monthDays(int month, int year) { switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: if (isLeapYear(year)) return 29; else return 28; } return -1; } int isValidDate(int month, int day, int year) { return year >= 1 && month >= 1 && month = 1 && day

=================================================================================

Makefile

CC=gcc CFLAGS=-I. DEPS = calendar.h OBJ = calendar.o count.o print.o

%.o: %.c $(DEPS) $(CC) -c -o $@ $

calendar: $(OBJ) $(CC) -o $@ $^ $(CFLAGS) ==================================================================

print.c

#include"calendar.h" void print(int MM, int YYYY) { /* Your code comes here */ } void handlePrint(void) { /* Your code comes here */ }

In this assignment, you will write a program that has two functionalities: First, it outputs the weeks of a Gregorian month given a year number and month name. For example, if the user requests to see the weeks of 01/2021", your program should draw the following table on the screen: Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Another functionality of your program is that it should be able to count the number of days between two dates; e.g. given the dates 01/06/2021 01/12/2021, your program should prints 6 on the screen; while for input 01/12/2021 01/06/2021, you program must print -6 on the screen. 1 Program Input Commands There are two valid commands for your program: count MM/DD/YYYY mm/dd/yyyy" and print MM/YYYY where mm and MM represent months, dd and DD represent days, and yyyy and YYYY represent years. If an invalid command is entered, your program should print an error message. 2 Functions of Your Program Your program may use different functions. However, it must have the following three func- tions in separate files: int main() The main function which must be stored in calendar.c file. int count(int MM, int DD, int YYYY, int mm, int dd, int yyyy) The count func- tion gets two dates and returns the number of days between them. This function must be stored in count.c file. void print(int MM, int YYYY) The print function prints a table showing the days of a given month in a given year. This function must be stored in print.c file. 3 Submissions You need to submit a .zip file compressing the followings: calendar.c count.c print.c other .c files (if you have any) calendar.h makefile which organizes the compilation process of your program snapshot of gdb program running the main function of your program line-by-line (.jpg or .png files only)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

Distinguish between brand extension and line extension.

Answered: 1 week ago

Question

What roles have these individuals played in your life?

Answered: 1 week ago