-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathExercise 16.3
63 lines (35 loc) · 1.67 KB
/
Exercise 16.3
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
1. (Program) Write a C++ function named days() that determines the number of days since
January 1, 1900 for any date passed as a structure. Use the Date structure:
struct Date
{
int month;
int day;
int year;
};
In writing the days() function, follow the convention that all years have 360 days and each
month consists of 30 days. The function should return the number of days for any Date structure
passed to it.
2. (Program) Write a C++ function named difDays() that calculates and returns the difference
between two dates. Each date is passed to the function as a structure by using the following
global data type:
struct Date
{
int month;
int day;
int year;
};
The difDays() function should make two calls to the days() function written for
Exercise 1.
3. (Modify) a. Rewrite the days() function written for Exercise 1 to receive a reference to a
Date structure rather than a copy of the structure.
b. Redo Exercise 3a, using a pointer rather than a reference.
4. (Program) a. Write a C++ function named larger() that returns the later date of any two
dates passed to it. For example, if the dates 10/9/2010 and 11/3/2012 are passed to larger(),
the second date is returned.
b. Include the larger() function written for Exercise 4a in a complete program. Store the
Date structure returned by larger() in a separate Date structure and display the member
values of the returned Date.
5. (Modify) a. Modify the days() function written for Exercise 1 to account for the actual number
of days in each month. Assume, however, that each year contains 365 days (that is, don’t
account for leap years).
b. Modify the function written for Exercise 5a to account for leap years.