This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:acrowle1:portfolio:cprogproject4 [2014/03/09 20:10] – created wedge | user:acrowle1:portfolio:cprogproject4 [2014/03/23 16:58] (current) – [Reflection] acrowle1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======Project: | + | ======Project: |
- | A project for COURSENAME | + | A project for C/C++ programming, |
- | + | ||
- | This project was begun on DATE and is anticipated to take X AMOUNT OF TIME. (Upon completion you can correct this with the actual length). | + | |
+ | This project was begun on March 7, 2014 and it took nearly 3 days to complete. | ||
=====Objectives===== | =====Objectives===== | ||
- | State the purpose of this project. | + | The purpose of this project |
=====Prerequisites===== | =====Prerequisites===== | ||
In order to successfully accomplish/ | In order to successfully accomplish/ | ||
- | | + | **Resources: |
- | * resource2 | + | * http:// |
- | * resource3 | + | * http:// |
- | * 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 | + | The purpose of this project |
- | + | [[haas: | |
- | 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 |
- | + | ||
- | Providing any links to original source material, such as from a project page, is a good idea. | + | |
- | + | ||
- | You'll want to give a general overview of what is going to be accomplished (for example, if your project is about installing a web server, do a little write-up on web servers. What is it, why do we need one, how does it work, etc.) | + | |
=====Scope===== | =====Scope===== | ||
- | Give a general overview | + | The scope of the project is to write a 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 |
=====Attributes===== | =====Attributes===== | ||
- | State and justify the attributes you'd like to receive upon successful | + | |
- | + | ||
- | * 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 < | + | </ |
+ | /*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> | + | A C program |
- | /* | + | */ |
- | * hello.c - A sample " | + | |
- | * | + | |
- | * written | + | |
- | * | + | |
- | * compile with: | + | |
- | | + | |
- | * | + | |
- | * execute with: | + | |
- | | + | |
- | */ | + | |
#include < | #include < | ||
+ | #include < | ||
int main() | int main() | ||
{ | { | ||
- | | + | |
- | return(0); | + | int i; |
+ | int *p; | ||
+ | p=&i; | ||
+ | int year; | ||
+ | |||
+ | |||
+ | |||
+ | printf(" | ||
+ | scanf(" | ||
+ | |||
+ | year=i; | ||
+ | i=(float)(((i/ | ||
+ | i=(year+i)%7; | ||
+ | |||
+ | |||
+ | //leap years! | ||
+ | if(year%4==0&& | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | |||
+ | |||
+ | //not leap years! | ||
+ | | ||
+ | printf(" | ||
+ | else if(i==2&& | ||
+ | printf(" | ||
+ | else if(i==3&& | ||
+ | printf(" | ||
+ | else if(i==4&& | ||
+ | printf(" | ||
+ | else if(i==5&& | ||
+ | printf(" | ||
+ | else if(i==6&& | ||
+ | printf(" | ||
+ | else if(i==7&& | ||
+ | printf(" | ||
+ | else if(i==0&& | ||
+ | printf(" | ||
+ | |||
+ | return(0); | ||
} | } | ||
+ | |||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
</ | </ | ||
=====Execution===== | =====Execution===== | ||
- | Again, if there is associated code with the project, and you haven' | + | |
<cli> | <cli> | ||
- | lab46: | + | lab46: |
- | Hello, World! | + | lab46:~/src/ |
- | lab46: | + | lab46: |
+ | Type last two digits of year from 2001-2099; | ||
+ | 04 | ||
+ | year, 2004, is a leap year | ||
+ | Jan 1st, 2004, is on: Thursday | ||
+ | lab46: | ||
+ | January 2004 | ||
+ | Su Mo Tu We Th Fr Sa | ||
+ | | ||
+ | | ||
+ | 11 12 13 14 15 16 17 | ||
+ | 18 19 20 21 22 23 24 | ||
+ | 25 26 27 28 29 30 31 | ||
+ | |||
+ | lab46: | ||
+ | Type last two digits of year from 2001-2099; | ||
+ | 67 | ||
+ | Jan 1st, 2067, is on: Saturday | ||
+ | lab46: | ||
+ | January 2067 | ||
+ | Su Mo Tu We Th Fr Sa | ||
+ | 1 | ||
+ | | ||
+ | 9 10 11 12 13 14 15 | ||
+ | 16 17 18 19 20 21 22 | ||
+ | 23 24 25 26 27 28 29 | ||
+ | 30 31 | ||
</ | </ | ||
=====Reflection===== | =====Reflection===== | ||
- | Comments/ | + | Interestingly enough, |
+ | The criteria: | ||
+ | - If year is evenly divisible by 4, it is a leap year. | ||
+ | - If year is evenly divided by 100, it is not a leap year, except 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' | ||
+ | |||
+ | 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:// |
- | * URL2 | + | * http:// |
- | * URL3 (provides useful information on topic) | + | * [[haas: |
- | * 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.) |