User Tools

Site Tools


notes:cprog:fall2024:projects:mmf0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:cprog:fall2024:projects:mmf0 [2024/09/24 15:57] – [else] tkastne1notes:cprog:fall2024:projects:mmf0 [2024/09/29 03:52] (current) – [If it is a leap year subtract 1 more] mwinter4
Line 1: Line 1:
 ======MMF0====== ======MMF0======
 +In this project we are to determine, given a year as input, which day of the week the January 1st of that year falls on. We can determine this with an algorithm known as <wrap hi>Zeller's congruence.</wrap> Once we have compiled our project, we will be able to test different cases with the <wrap hi>mmf0verify</wrap> file. 
 =====Process===== =====Process=====
  
Line 11: Line 11:
 </code> </code>
  
 +The ampersand above is necessary to assign the inputted value to our variable. The ampersand tells the fscanf function where our variable is stored in memory, so that we may access and modify the value based on the input we receive from the verify script. 
 ====Obtain the last two digits of this input value==== ====Obtain the last two digits of this input value====
  
 +To obtain the last 2 digits of our inputted year, we can take our year and mod (%) it by 100. Because we are using Zeller's congruence, we must subtract 1 from the year beforehand since we're dealing with January, which is considered a part of the previous year. 
 ====Quarter the value==== ====Quarter the value====
  
 ====Add quartered value back to two digit year==== ====Add quartered value back to two digit year====
 ====Subtract best fitting multiple of seven==== ====Subtract best fitting multiple of seven====
 +To subtract the best fitting multiple of seven the % operator can be used
 +  * Do note that % is the remainder operator and not a modulo operator
 +    * Modulo and remainder are primarily the same but they handle negative numbers differently
 ====If it is a leap year subtract 1 more ==== ====If it is a leap year subtract 1 more ====
 +However, if we are using Zeller's congruence this is an unnecessary step as this is handled implicitly by Christian Zeller's algorithm. This is why we January is considered a part of the previous year and is labeled as the thirteenth month rather than the first month.
 ====Look up day in table==== ====Look up day in table====
  
Line 38: Line 43:
 |  Sunday  |  0  | |  Sunday  |  0  |
 ====Edge case: leap years==== ====Edge case: leap years====
 +Subtracting 1 because it is a leap year may result in a value either less than the variables range or outside of the expected range of outputs
  
 +An underflow can be remedied in many ways.
 +  * Adding 7 to the number when it is outside of the expected range
 +  * When the result would be outside of the expected add 6 instead of subtracting 1
 +  * etc
 =====SELECTION===== =====SELECTION=====
  
Line 69: Line 79:
 fprintf(stdout, "The value of myVariable is 7\n"); fprintf(stdout, "The value of myVariable is 7\n");
 } else if(myVariable >= 7){ } else if(myVariable >= 7){
-fprintf(stdout, "The value of myVariavle is greater than 7\n");+fprintf(stdout, "The value of myVariable is greater than 7\n");
 } }
 </code> </code>
Line 84: Line 94:
 fprintf(stdout, "The value of myVariable is 7\n"); fprintf(stdout, "The value of myVariable is 7\n");
 } else{ } else{
-fprintf(stdout, "The value of myVariavle is not 7\n");+fprintf(stdout, "The value of myVariable is not 7\n");
 } }
 +</code>
 +The line The Value of myVariable is not 7 will always print unless myVariable == 7 results to true
 +
 +The else function allows simple construction of an if than else statement.
 ====RELATIONAL OPERATORS==== ====RELATIONAL OPERATORS====
  
notes/cprog/fall2024/projects/mmf0.1727193452.txt.gz · Last modified: 2024/09/24 15:57 by tkastne1