Pointers are widely used in C for a number of purposes, including being able to modify...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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:\n"); PrintDate(&d1); PrintDate(&d2); if (CompareDates (&d1, &d2) > 0) SwapDates (&d1, &d2); printf("\nAfter compare and swap: \n"); PrintDate(&d1); PrintDate(&d2); keypress (); return e; 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:\n"); PrintDate(&d1); PrintDate(&d2); if (CompareDates (&d1, &d2) > 0) SwapDates (&d1, &d2); printf("\nAfter compare and swap: \n"); PrintDate(&d1); PrintDate(&d2); keypress (); return e;
Expert Answer:
Answer rating: 100% (QA)
include include struct Date int year int month int day print date in daymonthyear format void pr... View the full answer
Related Book For
Financial Management Principles and Applications
ISBN: 978-0134417219
13th edition
Authors: Sheridan Titman, Arthur J. Keown, John H. Martin
Posted Date:
Students also viewed these computer engineering questions
-
A firm's cash flows are risky for a number of reasons. Identify and discuss five sources of risk or volatility in firm cash flows.
-
For a number of years, nearly all Americans say that they would vote for a woman for president IF she were qualified, and IF she were from their own political party. But is America ready for a female...
-
For a number of years, Nina was a mechanical engineer for a chemical company. She always enjoyed working around her home in her spare time, doing necessary repairs and maintenance. However, she was...
-
How many vector::push_back() operations are performed between lines 8 and 13 when this code is executed? The size of the input is the number of elements n in the vector v. Replace the question marks...
-
Stem-and-leaf displays can be used to compare distributions for two groups using a back-to-back stem-and-leaf display. In such a display, one group is shown on the left side of the stems, and the...
-
Two parallel 60-N forces are applied to a lever as shown. Determine the moment of the couple formed by the two forces (a) By resolving each force into horizontal and vertical components and adding...
-
Use the data in Short Exercise 16-12 to prepare Little People Learning Center's (LPLC) statement of cash flows for the year ended June 30, 2005. LPI.C uses the direct method for operating activities....
-
When a dispute arises between an audit client and its auditor regarding the proper accounting treatment for a transaction or other item, the audit client will sometimes retain another accounting firm...
-
You are a Board of Management (BoM) member in an investment company, managing assets of several mutual funds. You consider the segments of financial markets where your funds invest to be mostly...
-
The Digital Guardian Company issues policies that protect clients from downtime costs due to computer system failures. It is very important to process the policies quickly because long cycle times...
-
Test case 3: 2 images
-
Lewis County had the following transactions for its General Fund for the current fiscal year. LEWIS COUNTY TRANSACTIONS FOR GENERAL FUND FOR CURRENT FISCAL YEAR (1) Salaries and wages incurred during...
-
2. You are the owner of a small business where you sell handmade face masks. When the pandemic started you were able to purchase materials cheaper, but as demand increased for masks the cost of...
-
Cash Accounts Payable $ 3 8 , 4 0 0 $ 1 7 , 6 0 0 Inventory 3 9 , 3 6 0 Interest Payable 3 2 0 Prepaid Insurance 7 . 6 8 0 Notes Payable 6 4 . 0 0 0 Equipment 4 8 , 6 4 0 Owner's Capital 5 2 , 1 6 0...
-
Reynoso Corporation manufactures titanium and aluminum tennis racquets. Reynoso's total overhead costs consist of assembly costs and inspection costs. The following information is available regarding...
-
On January 1 , 2 0 2 4 , Nath - Langstrom Services, Incorporated, a computer software training firm, leased several computers under a two - year operating lease agreement from ComputerWorld Leasing,...
-
Given P(x)=325 + 2x + 85x3 + 42x2 (as a product of linear factors). 8282-1080, and that 6i is a zero, write P in factored form
-
If the annual fixed costs are 54,000 dinars, the occupation expense represents 20%, the contribution margin is 25%, and the unit selling price is 40 dinars. Required: Calculate the closing point of...
-
What is the objective of project risk analysis, and why is it critical to the investment decision-making process?
-
Why is a stable dividend payout policy popular from the viewpoint of the corporation? Is it also popular with investors? Why?
-
What is the time value of money? Give three examples of how the time value of money might take on importance in business decisions.
-
Which of the following is the reason preliminary estimates of materiality should be made by the auditor? a. Materiality guidelines cannot be adjusted after the audit procedures are conducted. b....
-
Which of the following is not a part of the audit risk model? a. Inherent risk. b. Control risk. c. Materiality risk. d. Detection risk.
-
Which of the following is a correct statement? a. There is an inverse relationship between risk levels and the amount of necessary audit effort. b. There is a direct relationship between risk levels...
Study smarter with the SolutionInn App