(Solved) : Include Include Include Task 1 Declare New Struct Type Called Date Structure Could Used St Q30661176 . . .
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
// (Task 1) Declare a new struct type called Date. Thisstructure
// could be used to store a calendar date in an application whichrequires
// timekeeping on a daily basis.
//
// Members:
// Year – an int which records the year.
//
// Month – an int which records the month, with valid valuesranging
// from 1 to 12.
//
// Day – an int which records the day in the month, ranging from 1to
// 31, subject to the rules set out in the documentation comment ofthe
// Date_Valid function.
typedef struct Date
{
// (Task 1.1) Declare the fields of the struct in the order listedabove.
} Date;
// (Task 2) Define a function called Date_Read which uses scanfto get the
// data for a Date. Fields are to be entered as three separate intvalues
// in the format “%d/%d/%d”.
//
// Parameters:
// date_ptr – the address of a Date which must be populated bythe
// function call.
//
// Returns:
// The function must return a boolean value indicating the statusof the
// I/O operation. The status is true if and only if three integervalues
// have been successfully parsed and saved in date_ptr.
//
// Do not try to perform other data validation in thisfunction.
INSERT RETURN_TYPE FUNCTION_NAME ( PARAMETER_LIST )
{
// (Task 2.1) Insert logic to read three integer values fromstandard input
// and save them in the appropriate fields of date_ptr. Use scanf,but do
// NOT use printf or any other output function.
}
// (Task 3) Define a function called Date_Write which usesprintf to
// display the value of a Date structure.
//
// Parameters:
// date – a Date structure that will be displayed.
//
// Returns:
// Nothing.
INSERT RETURN_TYPE FUNCTION_NAME ( PARAMETER_LIST )
{
// (Task 3.1) Print the horizontal and vertical position ofSCREEN-POS_VAR
// with format string “%d/%d/%d”. Do NOT insert a linefeed.
}
// (Task 4) Define a function called Date_Compare which comparestwo
// Date values. Your implementation may assume that these valuesare
// valid dates.
//
// Parameters:
// date1 – a Date structure.
// date2 – a Date structure.
//
// Returns:
// An int which is:
// -1 if the date represented by date1 is before that representedby
// date2;
// 0 if the two values represent the same date;
// +1 otherwise.
INSERT RETURN_TYPE FUNCTION_NAME ( PARAMETER_LIST )
{
INSERT CODE HERE
}
// (Task 5) Implement the Date_Valid function which determines ifthe
// supplied date is valid:
// * Year must be greater than or equal to 1.
// * Month must between 1 and 12 inclusive.
// * Day must be at least 1, with upper limits given below:
// 30 days: September, April June, and November.
// 31 days: January, March, May, July, August, October,December.
// 28 or 29: February (usually 28, but 29 in a leap year).
//
// A year is a leap year if it is divisible by 400, or if itis
// divisible by 4 but not divisible by 100.
//
// Parameters:
// date – a Date value.
//
// Returns:
// Returns true if and only if the supplied date is valid accordingto
// the definition listed above.
INSERT RETURN_TYPE FUNCTION_NAME ( PARAMETER_LIST )
{
INSERT CODE HERE
}
// (Task 6) Define a function called Date_Match which compares aquery date to
// the elements of an array of Date objects. The function returnsthe
// address of the first object in the list which satisfies adesignated criterion.
//
// Parameters:
// query – a Date structure.
// dates – an array of Date structures.
// num_dates – an int which tells the function how many elementsthere
// are in the array.
// criterion – an int (guaranteed to be -1, 0, or 1) which definesthe
// matching criterion.
//
// Returns:
// A pointer to a Date object.
// If num_dates is equal to or less than 0: this value will beNULL.
// If the query is not valid: this value will be NULL.
// If there is no valid element x in the array which
// Date_Compare(x,query) == criterion
// then this value will be NULL.
// Otherwise: the return value will be the address of the firstvalid
// Date x in the array for which
// Date_Compare(x,query) == criterion.
INSERT RETURN_TYPE FUNCTION_NAME ( PARAMETER_LIST )
{
INSERT CODE HERE
}
#define MAX_ITEMS (100)
int main(void)
{
Date query;
printf(“Input query date using format %s, with year first and daylast: “, “%d/%d/%d”);
Date_Read(&query);
Date ref_dates[MAX_ITEMS] = { {0,0,0} };
int num_items;
// Get number of ref_dates.
printf(“Please enter number of items (up to %d) that will beprocessed: “, MAX_ITEMS);
scanf(“%d”, &num_items);
// if number of ref_dates exceeds array size, restrict it tothat value.
if (num_items > MAX_ITEMS)
{
num_items = MAX_ITEMS;
}
for (int i = 0; i < num_items; i++)
{
printf(“Please enter item %d of %d using format %s, with year firstand day last: “, (i + 1), num_items, “%d/%d/%d”);
Date_Read(&ref_dates[i]);
}
for (int i = 0; i < num_items; i++)
{
Date_Write(ref_dates[i]);
if (!Date_Valid(ref_dates[i]))
{
printf(” is not valid.n”);
continue;
}
int cmp = Date_Compare(ref_dates[i], query);
if (cmp < -1 || cmp > 1)
{
printf(“Error!!! Date_Compare is broken.n”);
exit(1);
}
char * labels[] = { “less than”, “equal to”, “greater than”};
printf(” is %s “, labels[cmp + 1]);
Date_Write(query);
printf(“n”);
}
const int criterion = -1;
Date * cmp = Date_Match(query, ref_dates, num_items,criterion);
if (cmp)
{
printf(“The first valid date matching the search criterion is”);
Date_Write(*cmp);
}
else
{
printf(“There is no valid date matching the searchcriterion.n”);
}
return 0;
}
C Language. Complete the type definition for a struct type called Date, and then implement the following functions which perform meaningful operations on objects of this type. Date_Read – Read three integers into a Date object reference d by a pointer. Date Write – Display the value of a Date object. Date_Valid -Determine whether a Date object represents a valid date in the standard calendar Date Compare- Determine the ordering relationship (i.e. one value is before, the same, or after another) between two Date objects Date_Match – Search an array of Date objects to find the first date having a specified relationship to a query date Instructions are included as in-line comments in the test driver below. Show transcribed image text
Expert Answer
Answer to Include Include Include Task 1 Declare New Struct Type Called Date Structure Could Used St Q30661176 . . .
OR