SHARE
TWEET

Untitled

a guest Oct 9th, 2019 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "../include/myheader.h"
  4. /*
  5. *
  6. *Programmer: Antony Zheng
  7. *Class: CIS 1057
  8. *Date: Oct. 2, 2019
  9. *
  10. */
  11.  
  12. //submit header file, driver.c, lab6.c, lab6_script.txt
  13. //cat ../include/myheader.h driver.c lab6.c lab6_script.txt | mail -s "Lab 6 Antony" labwork@temple.edu
  14.  
  15. int is_a_leap_year(int *year);
  16. int is_a_validate_date(int *month, int *day, int *year);
  17. void get_date(int *month, int *day, int *year);
  18. int ordinal_date(int *month, int *day, int *year);
  19. void print_US_date(int *month, int *day, int *year);
  20. void print_ordinal_date(int countDays, int *year);
  21.  
  22.  
  23. int main ()
  24. {
  25.     int month, day, year, countDays;
  26.  
  27.     get_date(&month, &day, &year);
  28.     countDays = ordinal_date(&month, &day, &year);
  29.     countDays = is_a_validate(&month, &day, &year);
  30.     countDays = get_date(&month, &day, &year);
  31.     countDays = print_US_date(&month, &day, &year);
  32.     countDays = print_ordinal_date(&month, &day, &year);
  33. }
  34.  
  35. //Part 1 //
  36. int is_a_leap_year(int *year){
  37.  
  38.     if (*year%100 == 0)&&(*year%400 == 0)
  39.         return 1;
  40.     else if (*year%4 == 0)
  41.         return 1;
  42.     else
  43.         return 0;
  44.     }
  45.  
  46.  
  47. // Part 3 is_a_validate_date( ) //
  48. int is_a_validate_date( int *month, int *day, int *year)
  49. {
  50.  
  51.     if(*year >= 1990 && *year <= 2200)
  52.     {
  53.         if((*month>= 1) && (*month <=12))
  54.         {
  55.             if (*day>=1 && *day<= 31) && (*month==1 || *month==3 || *month== 5 || *month==7 ||
  56. *month==8
  57. ||*month==10||*month=12)
  58.             //printf("This seems legit.");
  59.             return 1;
  60.             else if (*day>=1 && *day<=30)&& (*month==4 || *month==6 || *month==9 ||*month==11)
  61.             //printf("This seems true.");
  62.             return 1;
  63.             else if (*day>=1 && ((*day<=28)||(*day <= 29)) && (*month==2)
  64.             //printf("This is a real date.");
  65.             return 1;
  66.         }
  67.             else
  68.                 exit(0);
  69.         }
  70. }
  71.  
  72.  
  73. // Part 4  get_date( ) //
  74.  
  75. void get_date(int *month, int *day, int *year)
  76. {
  77.     printf(" Enter a month, day, year ");// &month, &day, &year)
  78.     scanf("%d%d%d", month, day, year);
  79. }
  80.  
  81. // Part 5 //
  82.  
  83. int ordinal_date(int *month, int *day, int *year)
  84. {
  85.     int countDays = 0;
  86.     int leap = is_a_leap_year(*year);
  87.         if(*month == 1);
  88.         countDays = *day;
  89.  
  90.         else if(*month==2);
  91.         countDays = *day + 31;
  92.  
  93.         else if(*month==3);
  94.         countDays = *day + 59;
  95.  
  96.         else if(*month==4);
  97.         countDays = *day +90;
  98.  
  99.         else if(*month==5);
  100.         countDays = *day +120;
  101.  
  102.         else if(*month==6);
  103.         countDays = *day + 151;
  104.  
  105.         else if(*month==7);
  106.         countDays = *day + 181;
  107.  
  108.         else if(*month==8);
  109.         countDays = *day + 212;
  110.  
  111.         else if(*month==9);
  112.         countDays = *day + 243;
  113.  
  114.         else if(*month==10);
  115.         countDays = *day + 273;
  116.  
  117.         else if(*month==11);
  118.         countDays = *day + 304;
  119.  
  120.         else if(*month==12);
  121.         countDays = *day + 334;
  122.  
  123.     if (leap == 1)
  124.         countDays = countDays + 1;
  125.     return countDays;
  126. }
  127.  
  128. //Part 6//
  129.  
  130. void print_US_date(int *month, int *day, int *year){
  131.     printf("%02d/%02d/%d", *month, *day, *year);
  132. }
  133.  
  134. void print_ordinal_date(int *year, int *day){
  135.     printf("%d/%d", *year, *day);
  136. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top