Question: Pointers are widely used in C for a number of purposes, including being able to modify data that is outside the scope of a
Pointers are widely used in C for a number of purposes, including being able to modify data that is outside the scope of a function and to save computing time and memory by not copying large data sets to functions. When a pointer to a structure is used, the members of the structure are accessed using the member by ("->") operator instead of the dot operator ("."). Note that all functions below are using a pointer to a Date structure. Assignment 1. Using the Date structure from previous homework, write a function to print the date in a format of your choosing (must include day, month, and year), given a pointer to a Date as a parameter. Use the following function declaration. void PrintDate(Date d) { // your code here 2. Using the same Date structure, write a swap function to swap two Dates. Use the following function declaration and implement the body of the function. void SwapDates(Date* a, Date* b) { // your code here 3. Write a function to compare two dates. The function should return -1 if the first date is earlier than the second date, O if the dates are equal, and 1 if the second date is earlier than the first. Use the following function declaration and implement the body of the function. int CompareDates (Date* a, Date* b) // your code here 4. Use the following code in main() to test your functions: int main() Date di - ( 2021,4,2 ), d2 = { 1983, 12, 31 }; printf("Compare dates and print the earliest one first: "); PrintDate(&d1); PrintDate(&d2); if (CompareDates (&d1, &d2) > 0) SwapDates (&d1, &d2); printf(" After compare and swap: "); PrintDate(&d1); PrintDate(&d2); keypress (); return e;
Step by Step Solution
3.46 Rating (166 Votes )
There are 3 Steps involved in it
include include struct Date int year int month int day print date in daymonthyear format void pr... View full answer
Get step-by-step solutions from verified subject matter experts
