User Tools

Site Tools


user:acrowle1:portfolio:cprogproject4

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
user:acrowle1:portfolio:cprogproject4 [2014/03/09 22:33] – [Objectives] acrowle1user:acrowle1:portfolio:cprogproject4 [2014/03/23 16:58] (current) – [Reflection] acrowle1
Line 9: Line 9:
 In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved: In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:
  
-  resource1 +**Resources:** 
-  * resource2 +  * http://vpcalendar.net/when-is-the-next-leap-year.html 
-  * resource3 +  * http://www.timeanddate.com/date/leapyear.html 
-  * experience1 +  * project assignment page 
-  * experience2 +  * consultation with C/C++ programming instructor, Matt Haas 
-  * etc+**Experiences:** 
 +  * ability to obtain user input 
 +  * ability to obtain the day of the week January 1st falls on per given year
 +  * ability to use selection statements to achieve desired result 
 +  * ability to use Bitwise && to distinguish between leap year and non-leap year
 =====Background===== =====Background=====
-State the idea or purpose of the project. What are you attempting to pursue? +The purpose of this project is to use a mental math technique to programmatically compute the day on which January 1st falls per given calendar year in the 21st centuryThe "mental math" trick is used to simplify the process of computation without being dependent on calculator. To see how this particular technique works for computing the week day that January 1st falls onsee the assignment link below
- +[[haas:spring2014:cprog:projects:dayofweek|Project: MENTAL MATH (DAY OF WEEK)]] 
-Upon approval, you'll want to fill this section out with more detailed background information. DO NOT JUST PROVIDE A LINK. +To implement the program to compile and execute successfully, it is required to know how to determine leap years from non-leap years. As we experience leap years as much as every four years, simple algorithms can be used to determine the leap year. Howeverevery 100 years, a leap year is skipped to make up for the 11 minutes removed from the 365.25 day calendar year 
- +
-Providing any links to original source material, such as from project pageis a good idea+
- +
-You'll want to give a general overview of what is going to be accomplished (for exampleif your project is about installing a web serverdo little write-up on web serversWhat is it, why do we need one, how does it work, etc.)+
  
 =====Scope===== =====Scope=====
-Give general overview of your anticipated implementation of the projectAddress any areas where you are making upfront assumptions or curtailing potential detail. State the focus you will be taking in implementation. +The scope of the project is to write program that utilizes the described mental math technique (see assignment in Background section above) to compute the week day that January 1st happens to fall on for a given year in the 21st century (2000-2099). In doing so, the program should prompt the user for the last two digits of the year, perform the calculation of the day of the week that January 1st falls on for the year given by user input, and display the valueApplying pointers to enable the use of scanf() for obtaining input from the user, using if() statements, are used in the implementation of this program
 =====Attributes===== =====Attributes=====
-State and justify the attributes you'd like to receive upon successful approval and completion of this project+ Upon successful completion of this project, the following attributes are achieved.
- +
-  * attribute1: why you feel your pursuit of this project will gain you this attribute +
-  * attribute2: why you feel your pursuit of this project will gain you this attribute +
-  * etc...+
  
 +  * More familiarity with pointers and scanf: This project requires user input.
 +  * Become more exposed to selection statements: if statements are used to compute the day of the week January 1st falls on per given calendar year.
 +  * Get more comfortable with Bitwise && operators: used to differentiate between leap years and non-leap years to obtain the correct output.
 =====Procedure===== =====Procedure=====
 The actual steps taken to accomplish the project. Include images, code snippets, command-line excerpts; whatever is useful for intuitively communicating important information for accomplishing the project. The actual steps taken to accomplish the project. Include images, code snippets, command-line excerpts; whatever is useful for intuitively communicating important information for accomplishing the project.
  
 =====Code===== =====Code=====
-Upon completion of the project, if there is an applicable collection of created code, place a copy of your finished code within <nowiki><code> </code></nowiki> blocks here.+</code> 
 +/*dayofweek.c- A program using a math technique to output the day of the week; 
 +               that January 1st falls on from calender years 2001 to 2099 based; 
 +               on what year the user inputs;
  
-<code c> +program Written by: Alana Whittier for CSCS1320S14 on March 7, 2014; 
-/* +*/
- * hello.c - sample "Hello, World!" program +
- *  +
- * written by NAME for COURSE on DATE +
- * +
- * compile with: +
-   gcc -o hello hello.c +
- * +
- * execute with: +
-   ./hello +
- */+
  
 #include <stdio.h> #include <stdio.h>
 +#include <stdlib.h>
  
 int main() int main()
 { {
-    printf("HelloWorld!\n");    // Output message to STDOUT + 
-    return(0);+int i; 
 +int *p; 
 +p=&i; 
 +int year; 
 + 
 + 
 + 
 +printf("Type last two digits of year from 2001-2099;\n"); 
 +scanf("%d"p); 
 + 
 +year=i; 
 +i=(float)(((i/2)/2)); 
 +i=(year+i)%7; 
 + 
 + 
 +//leap years! 
 +if(year%4==0&&(year/4!=0)){ 
 +        printf("year, %d, is a leap year\n",2000+ year);
 +   if(i==1&&(year%4==0&&(year/4!=0))){ 
 +        printf("Jan 1st,%d, is on : Sunday\n", 2000+ year);} 
 +   if(i==2&&(year%4==0&&(year/4!=0))){ 
 +        printf("Jan 1st, %d, is on: Monday\n", 2000+year);
 +   if(i==3&&(year%4==0&&(year/4!=0))){ 
 +        printf("Jan 1st, %d, is on: Tuesday\n", 2000+year);
 +   if(i==4&&(year%4==0&&(year/4!=0))){ 
 +        printf("Jan 1st, %d, is on: Wednesday\n", 2000+year);
 +   if(i==5&&(year%4==0&&(year/4!=0))){ 
 +        printf("Jan 1st, %d, is on: Thursday\n", 2000+year);
 +   if(i==6&&(year%4==0&&(year/4!=0))){ 
 +        printf("Jan 1st, %d, is on: Friday\n", 2000+year);
 +   if(i==7&&(year%4==0&&(year/4!=0))){ 
 +        printf("Jan 1st, %d, is on Saturday\n", 2000+year);
 +   if(i==0&&(year%4==0&&(year/4!=0))){ 
 +        printf("Jan 1st, %d, is on Saturday\n", 2000+year);
 + 
 + 
 +//not leap years! 
 +    else if(i==1&&(year%4!=0)){ 
 +        printf("Jan 1st, %d, is on: Monday\n", 2000+year);
 +    else if(i==2&&(year%4!=0)){ 
 +        printf("Jan 1st, %d, is on: Tuesday\n", 2000+year);
 +    else if(i==3&&(year%4!=0)){ 
 +        printf("Jan 1st, %d, is on: Wednesday\n", 2000+year);
 +    else if(i==4&&(year%4!=0)){ 
 +        printf("Jan 1st, %d, is on: Thursday\n", 2000+year);
 +    else if(i==5&&(year%4!=0)){ 
 +        printf("Jan 1st, %d, is on: Friday\n", 2000+year);
 +    else if(i==6&&(year%4!=0)){ 
 +        printf("Jan 1st, %d, is on: Saturday\n", 2000+year);
 +    else if(i==7&&(year%4!=0)){ 
 +        printf("Jan 1st, %d, is on: Sunday\n", 2000+year);
 +    else if(i==0&&(year%4!=0)){ 
 +        printf("Jan 1st, %d, is on: Sunday\n", 2000+year);
 + 
 +return(0);
 } }
 +
 +
 +        
 +        
 +        
 +        
 +
 </code> </code>
  
 =====Execution===== =====Execution=====
-Again, if there is associated code with the project, and you haven't already indicated how to run it, provide a sample run of your code:+
  
 <cli> <cli>
-lab46:~/src/cprog$ ./hello +lab46:~/src/cscs1320nano dayofweek.
-HelloWorld! +lab46:~/src/cscs1320$ gcc -o dayofweek dayofweek.c 
-lab46:~/src/cprog+lab46:~/src/cscs1320$ ./dayofweek 
 +Type last two digits of year from 2001-2099; 
 +04 
 +year2004, is a leap year 
 +Jan 1st, 2004, is on: Thursday 
 +lab46:~/src/cscs1320cal 01 2004 
 +    January 2004 
 +Su Mo Tu We Th Fr Sa 
 +              2  3 
 +  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 
 + 
 +lab46:~/src/cscs1320$ ./dayofweek 
 +Type last two digits of year from 2001-2099; 
 +67 
 +Jan 1st, 2067, is on: Saturday 
 +lab46:~/src/cscs1320$ cal 01 2067 
 +    January 2067 
 +Su Mo Tu We Th Fr Sa 
 +                   1 
 +  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 
 </cli> </cli>
  
 =====Reflection===== =====Reflection=====
-Comments/thoughts generated through performing the projectobservations madeanalysis renderedconclusions wroughtWhat did you learn from doing this project?+Interestingly enough, the year 2000 would not be a leap year if only using the first 2 criteria.  
 +The criteria:  
 +  - If year is evenly divisible by 4it is a leap year. 
 +  - If year is evenly divided by 100it is not a leap yearexcept when  
 +  - the year is also evenly divisible by 400.
  
 +The year 2000 is a significant calendar year because it was the first instance when the third criteria was invoked since switching from the Julian calendar to the Gregorian one. The reason for leap years? This was necessary to keep our calendar in alignment with Earth's revolutions around the sun. If we did not add a day to our calendar ~every 4 years, we would lose nearly 6 hours every year, so after 100 years our calendar would be off by nearly 24 days as measured by earth's revolutions. Why is a leap year skipped every 100 years, except in special instances (like year 2000)? This is to account for the 11 minutes shaved off from the 365.25 calendar year. 
 +
 +While I wrote my code more simplistically saying if i divided by 4 equals zero, then it is a leap year and if i divided by 4 does not equal zero, not a leap year, the code worked. I could have added that i/100==0 || i/400==0 is a leap year to make my code more realistic to how the calendar interprets leap years from non-leap years, particularly in special instances such as 2000.
 =====References===== =====References=====
 In performing this project, the following resources were referenced: In performing this project, the following resources were referenced:
  
-  * URL1 +  * http://www.timeanddate.com/date/leapyear.html 
-  * URL2 +  * http://vpcalendar.net/when-is-the-next-leap-year.html 
-  * URL3 (provides useful information on topic+  * [[haas:spring2014:cprog:projects:dayofweek|Project: MENTAL MATH (DAY OF WEEK)]] 
-  * URL4+
  
-Generally, state where you got informative and useful information to help you accomplish this project when you originally worked on it (from Google, other wiki documents on the Lab46 wiki, etc.) 
user/acrowle1/portfolio/cprogproject4.1394404380.txt.gz · Last modified: 2014/03/09 22:33 by acrowle1