Project and Homework Assignments, Engin191 Spring, 1996

The Extra Credit project: Primes and Hailstones for the course can be found here. 
The Project #3 assignment : Poker Pleasures for the course can be found here. 
The Project #2 assignment: Character Capers for the course can be found here.

Project #1, Count the Days

Due Thursday, April 4, 1996 

Count the Days


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

Requirements:

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 &ltstdio.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).
Also note that the number of days in each month 1..12 are conveniently recorded in the array:
int daysInMonth[] = {0,31,28,31,

30,31,30,31,31,30,31,30,31};
Turn in:

Extra Credit ( 5 points max.)

Each time the user gives a date the program prints the day of the week for that date; 
NOTE: Any viruses on your diskette, and BOOM, -50 points

Project #0, Searching for your Roots

Due Thurs., March 14, 1996

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  &ltstdio.h>
#include &ltmath.h>
#include &ltconio.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;
}
  1. Using the program:
  2. Alter myFnc(x) so that it computes the value of:
  3. myFnc(x) = sin(x) * exp-(x/4)2/(.2 + (x-2)2)

    and find where it reaches its overall (global) maximum).

Things to be handed in:
  1. Cover page: your name, date, project title, e-mail address, the computer and the C compiler you used.
  2. A brief description of the project (~ 1 paragraph).
  3. Highlight any special features of your program that we should look out for.
  4. A clean printed listing of the final version of your program; (the one that uses the second version of myFnc() above).
  5. The plot described above, and your results as to roots, local maxima and minima for myFnc, and the global maximum for the second incarmation of myFnc above.
  6. A diskette containing your source code; call it scanner.c and your executable code: call it scanner.exe
  7. Print on the label of the diskette: your name, and whether it's formatted for IBM PC or Macintosh, (or whatever).
  8. If your disk contains a virus, automatic 50% deducted from your project grade!! (It's part of life: you have to have virus protection software on any machine you use. Explore the internet to get the latest free version for your machine.)
The neatness and professionalism of your report does matter. Make it clear and easy to read. Remember: a very busy person will be grading your work.