Write and exercise a program that allows the user to compute the number of days that elapse between two dates.
Examples:
There is 1 day between 6/7/1954 and 6/8/1954
There are 366 days between 1/1/1996 and 1/1/1997
There are 35107 days between 1/1/1900 and 2/14/1996
There are 20098 days between 3/3/1941 and 3/12/1996
There are 729116 days between 1/1/0000 and 4/2/1996
int isLeap(int year); /* returns 1 if year is a leap year; 0 otherwise */ long daysBetween(int mon1, int day1, int yr1, int mon2, int day2, int yr2); /* Checks that both dates are valid, and that the second day does not precede the first. If all is ok it returns the number of days that elapse between (mon1, day1, yr1) and (mon2, day2, yr2). If not ok, it returns -1. (Extra credit part: once it tests that the dates are valid it prints the day of the week for both of the dates.) */Basic flow of the test program (pseudocode is indicated by [[....]]):
[[#include stuff like <stdio.h>, etc.]]
[[function prototypes]]
[[function definitions]]
void main(void)
{
[[definitions of local variables]]
while(1) /* endless loop */
{
[[ prompt the user and get month1, day1, year1]]
[[ exit the program if the user gives day1 == 0]]
[[ prompt the user and get month2, day2, year2]]
numberDays = daysBetween([[the two dates]]);
if( numberDays < 0 )
[[scold the user]]
else
[[print numberDays]]
} /* while */
} /* main */
Remember: A leap year is any year that is: (divisible by 4 but not
divisible by 100), or (is divisible by 400).
int daysInMonth[] = {0,31,28,31,
30,31,30,31,31,30,31,30,31};
Turn in:
This project is designed to familiarize you with using your C programming environment (for most of you this is Turbo C++ or Borland C++ .. I will just call it Turbo C below).
Start Turbo C and type in the program below very carefully ; (remember, in C every little punctuation mark is crucial. Be particularly careful about upper/lower case, and the usual confusion between 1 and l (ell), and 0 and o (oh)).
The following program in C lets you explore how a complicated mathematical function myFnc(x) varies over different ranges of its argument x. You give it two values, lo and hi, and it prints the values of myFnc( ) for a bunch of values in the range lo to hi. Using different values of lo and hi you can find:
/* Project 0, by .......... March xx, 1966, for ENGIN 191 */ #include <stdio.h> #include <math.h> #include <conio.h> #define NUM 20 double myFnc(double); /* prototype */ /* <<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>*/ void main() { double where, lo, hi, value; clrscr(); /* clear the screen */ printf("\n Welcome to the function scanner."); printf("\n to exit the program give lo greater than hi"); do{ printf("\n give lo and hi: "); scanf("%lf %lf", &lo, &hi); for(where = lo; where < hi; where += (hi - lo)/NUM) { value = myFnc(where); printf("\n myFnc(%10.6lf)=%12.8lf", where, value); } } while( lo <= hi ); printf("\n that's all, folks"); } /*<<<<<<<<<<<<<<< myFnc >>>>>>>>>>>>>>>>*/ double myFnc(double x) { return 2 * x + 8.4 * sin( 5 * x) - 7 * cos(x) - x * x; }
myFnc(x) = sin(x) * exp-(x/4)2/(.2 + (x-2)2)
and find where it reaches its overall (global) maximum).