Structures and Pointers – Geometry – Problem #2
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Consider a date calculator that performs the following operations as per the following C functions - i leap year(date) - checks if the date belongs to a leap year or not, returns 1 if date is in leap year, returns 0 otherwise. ii day identify (date) - identify the day of the date i.e., Monday, Tuesday. . . It does not return anything, prints the day within the function. iii diff(date1, date2) - calculates the difference between two dates passed as arguments in the number of days and returns it. iv date identify(date1, n)- identify the date that is after n days from the given date. This returns the final date. Write a program that performs all the above operations as per the menu selected by the user (see example below). For storing the date, use a structure named date that contains three members of integer type: namely day, month and year. You must declare a function for each of the above mentioned operations. For taking input the dates, you can follow the example shown below. No need to keep a separate logic that checks whether the input date is valid or not, you 3 may assume that the user always enters a valid date. Example 1: Input: − − − − − − −−MENU− − − − − − −− 1. Check leap year 2. Identify corresponding day of a given date 3. Compute difference between two dates 4. Calculate the next date after n days from a given date Enter your option: 1 Enter date: Day -12 Month -5 Year - 2022 Output: The given date is does not belongs to a leap year Example 2: Input: − − − − − − −−MENU− − − − − − −− 1. Check leap year 2. Identify corresponding day of a given date 3. Compute difference between two dates 4. Calculate the next date after n days from a given date Enter your option: 2 Enter date: Day - 12 Month - 1 Year - 2022 Output: The corresponding day of the given date is Wednesday Example 3: Input: − − − − − − −−MENU− − − − − − −− 1. Check leap year 2. Identify corresponding day of a given date 3. Compute difference between two dates 4. Calculate the next date after n days from a given date Enter your option: 3 Enter first date: Day - 12 Month - 2 Year - 2022 Enter second date: Day - 29 Month - 1 Year - 2022 [NOTE:- The first date need not necessarily always be before the second date as per calendar order. Please consider this fact] Output: There are 14 days between the given two dates. Example 3: Input: − − − − − − −−MENU− − − − − − −− 1. Check leap year 2. Identify corresponding day of a given date 3. Compute difference between two dates 4. Calculate the next date after n days from a given date Enter your option: 3 Enter first date: Day - 12 Month - 2 Year - 2022 Enter second date: Day - 29 Month - 1 Year - 2022 [NOTE:- The first date need not necessarily always be before the second date as per calendar order. Please consider this fact] Output: There are 14 days between the given two dates. Example 4: Input: − − − − − − −−MENU− − − − − − −− 1. Check leap year 2. Identify corresponding day of a given date 3. Compute difference between two dates 4. Calculate the next date after n days from a given date Enter your option: 4 Enter date: Day - 28 Month -1 Year - 2022 Enter number of days: 12 Output: The corresponding date after 12 days is 9/2/2022 [Print in format dd/mm/yyyy]