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 15:19] – acrowle1 | user:acrowle1:portfolio:cprogproject4 [2014/03/23 16:58] (current) – [Reflection] acrowle1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Project: | ||
- | portfolio » cprogproject4 | + | A project for C/C++ programming, |
- | -------------------------------------------------------------------------------- | + | This project was begun on March 7, 2014 and it took nearly 3 days to complete. |
- | < | + | =====Objectives===== |
- | <html lang=" | + | The purpose of this project |
- | < | + | =====Prerequisites===== |
- | <meta charset=" | + | In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved: |
- | < | + | |
- | < | + | |
- | <meta name=" | + | |
- | <meta name=" | + | |
- | <meta name=" | + | |
- | <meta name=" | + | |
- | <link rel=" | + | |
- | <link rel=" | + | |
- | <link rel=" | + | |
- | <link rel=" | + | |
- | <link rel=" | + | |
- | <link rel=" | + | |
- | <link rel=" | + | |
- | <link rel=" | + | |
- | <link rel=" | + | |
- | <script type=" | + | |
- | / | + | |
- | <script type=" | + | |
- | <meta name=" | + | |
- | <link rel=" | + | |
- | <link rel=" | + | |
- | </ | + | |
- | < | + | **Resources: |
- | <!--[if lte IE 7 ]>< | + | * http:// |
- | < | + | * http:// |
+ | * project assignment page | ||
+ | * consultation with C/C++ programming instructor, Matt Haas | ||
+ | **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===== | ||
+ | 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 century. The "mental math" | ||
+ | [[haas: | ||
+ | To implement the program to compile and execute successfully, | ||
- | | + | =====Scope===== |
- | <!-- ********** HEADER ********** --> | + | 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 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 value. Applying pointers to enable the use of scanf() for obtaining input from the user, using if() statements, are used in the implementation of this program. |
- | <div id=" | + | =====Attributes===== |
+ | Upon successful completion of this project, the following attributes are achieved. | ||
- | | + | * 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===== |
- | </ | + | 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> |
+ | /*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; | ||
- | <div class=" | + | A C program Written by: Alana Whittier for CSCS1320S14 on March 7, 2014; |
- | <!-- USER TOOLS --> | + | */ |
- | <div id=" | + | |
- | <h3 class=" | + | |
- | < | + | |
- | <li class=" | + | |
- | </ | + | |
- | + | ||
- | <!-- SITE TOOLS --> | + | |
- | <div id=" | + | |
- | <h3 class=" | + | |
- | <form action="/ | + | |
- | <form action="/ | + | |
- | < | + | |
- | < | + | |
- | </div> | + | |
- | | + | # |
+ | #include < | ||
- | <!-- BREADCRUMBS --> | + | int main() |
- | < | + | { |
- | <div class=" | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | <hr class=" | + | |
- | </ | + | |
- | <div class=" | + | int i; |
+ | int *p; | ||
+ | p=&i; | ||
+ | int year; | ||
- | <!-- ********** ASIDE ********** --> | ||
- | <div id=" | ||
- | <h3 class=" | ||
- | <div class=" | ||
- | <!-- EDIT1 PLUGIN_WRAP_START [0-] -->< | ||
- | <p> | ||
- | <em class=" | ||
- | </p> | ||
- | <ul> | ||
- | <li class=" | ||
- | </li> | ||
- | <li class=" | ||
- | </li> | ||
- | <li class=" | ||
- | </li> | ||
- | <li class=" | ||
- | </li> | ||
- | </ul> | ||
- | <!-- EDIT5 PLUGIN_INCLUDE_START " | ||
- | <p> | + | printf("Type last two digits of year from 2001-2099;\n"); |
- | <em class="u"> | + | scanf("%d", p); |
- | </ | + | |
- | < | + | |
- | <li class=" | + | |
- | </ | + | |
- | </ | + | |
- | <!-- EDIT6 PLUGIN_INCLUDE_END | + | |
- | <!-- EDIT4 PLUGIN_INCLUDE_END | + | |
- | <p> | + | year=i; |
- | <em class=" | + | i=(float)(((i/2)/2)); |
- | </ | + | i=(year+i)%7; |
- | < | + | |
- | <li class=" | + | |
- | </ | + | |
- | <li class=" | + | |
- | </ | + | |
- | <li class=" | + | |
- | </ | + | |
- | <li class=" | + | |
- | </ | + | |
- | <li class=" | + | |
- | </ | + | |
- | </ul> | + | |
- | <p> | ||
- | <em class=" | ||
- | </p> | ||
- | <ul> | ||
- | <li class=" | ||
- | </li> | ||
- | <li class=" | ||
- | </li> | ||
- | <li class=" | ||
- | </li> | ||
- | </ul> | ||
- | </ | ||
- | </ | ||
- | | ||
- | <!-- ********** CONTENT ********** --> | ||
- | <div id=" | ||
- | <div class="pageId">< | + | //leap years! |
+ | if(year%4==0&& | ||
+ | printf("year, %d, is a leap year\n",2000+ year);} | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | printf(" | ||
- | <div class=" | ||
- | <!-- wikipage start --> | ||
- | <!-- TOC START --> | ||
- | <div id=" | ||
- | <h3 class=" | ||
- | <div> | ||
- | <ul class=" | + | //not leap years! |
- | <li class=" | + | else if(i==1&& |
- | <ul class="toc"> | + | printf("Jan 1st, %d, is on: Monday\n", 2000+year); |
- | <li class=" | + | else if(i==2&& |
- | <li class=" | + | printf("Jan 1st, %d, is on: Tuesday\n", 2000+year); |
- | <li class=" | + | else if(i==3&& |
- | <li class=" | + | printf("Jan 1st, %d, is on: Wednesday\n", 2000+year); |
- | <li class=" | + | else if(i==4&& |
- | <li class="level2"><div class=" | + | printf("Jan 1st, %d, is on: Thursday\n", 2000+year); |
- | <li class=" | + | else if(i==5&& |
- | <li class="level2"><div class=" | + | printf("Jan 1st, %d, is on: Friday\n", 2000+year); |
- | <li class=" | + | else if(i==6&& |
- | <li class="level2"><div class=" | + | |
- | </ | + | else if(i==7&& |
- | </ | + | |
- | </ | + | else if(i==0&& |
- | </ | + | |
- | <!-- TOC END --> | + | |
- | <h1 class=" | + | return(0); |
- | <div class=" | + | } |
- | <p> | ||
- | A project for COURSENAME by YOUR NAME OR GROUPMEMBER NAMES during the SEMESTER YEAR. | ||
- | </p> | ||
- | <p> | + | |
- | 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). | + | |
- | </p> | + | |
+ | | ||
- | </div> | + | </code> |
- | <h2 class=" | + | =====Execution===== |
- | <div class=" | + | |
- | <p> | ||
- | State the purpose of this project. What is the point of this project? What do we hope to accomplish by undertaking it? | ||
- | </p> | ||
- | </div> | + | <cli> |
+ | lab46: | ||
+ | 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 | ||
- | <h2 class=" | + | lab46:~/src/ |
- | <div class=" | + | 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 | ||
- | <p> | + | </cli> |
- | In order to successfully accomplish/perform this project, the listed resources/ | + | |
- | </ | + | |
- | < | + | |
- | <li class=" | + | |
- | </ | + | |
- | <li class=" | + | |
- | </ | + | |
- | <li class=" | + | |
- | </ | + | |
- | <li class=" | + | |
- | </ | + | |
- | <li class=" | + | |
- | </ | + | |
- | <li class=" | + | |
- | </ | + | |
- | </ul> | + | |
- | </ | + | =====Reflection===== |
+ | 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 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. | ||
- | <h2 class=" | + | 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' |
- | <div class=" | + | |
- | <p> | + | 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. |
- | State the idea or purpose of the project. What are you attempting to pursue? | + | =====References===== |
- | </ | + | |
- | + | ||
- | <p> | + | |
- | Upon approval, you&# | + | |
- | </ | + | |
- | + | ||
- | <p> | + | |
- | Providing any links to original source material, such as from a project page, is a good idea. | + | |
- | </ | + | |
- | + | ||
- | <p> | + | |
- | You&# | + | |
- | </ | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | <h2 class=" | + | |
- | <div class=" | + | |
- | + | ||
- | <p> | + | |
- | Give a general overview of your anticipated implementation of the project. Address any areas where you are making upfront assumptions or curtailing potential detail. State the focus you will be taking in implementation. | + | |
- | </ | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | <h2 class=" | + | |
- | <div class=" | + | |
- | + | ||
- | <p> | + | |
- | State and justify the attributes you&# | + | |
- | </ | + | |
- | < | + | |
- | <li class=" | + | |
- | </ | + | |
- | <li class=" | + | |
- | </ | + | |
- | <li class=" | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | <h2 class=" | + | |
- | <div class=" | + | |
- | + | ||
- | <p> | + | |
- | 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 | + | |
- | </ | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | <h2 class=" | + | |
- | <div class=" | + | |
- | + | ||
- | <p> | + | |
- | Upon completion of the project, if there is an applicable collection of created code, place a copy of your finished code within & | + | |
- | </p> | + | |
- | <pre class="c code c">< | + | |
- | * hello.c - A sample & | + | |
- | * | + | |
- | * written by NAME for COURSE on DATE | + | |
- | * | + | |
- | * compile with: | + | |
- | | + | |
- | * | + | |
- | * execute with: | + | |
- | | + | |
- | | + | |
- | & | + | |
- | <span class=" | + | |
- | & | + | |
- | <span class=" | + | |
- | <span class=" | + | |
- | <a href=" | + | |
- | <span class=" | + | |
- | <span class=" | + | |
- | </ | + | |
- | + | ||
- | <h2 class=" | + | |
- | <div class=" | + | |
- | + | ||
- | <p> | + | |
- | Again, if there is associated | + | |
- | </ | + | |
- | <pre class=" | + | |
- | <span class=" | + | |
- | <span class=" | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | <h2 class=" | + | |
- | <div class=" | + | |
- | + | ||
- | <p> | + | |
- | Comments/ | + | |
- | </ | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | <h2 class=" | + | |
- | <div class=" | + | |
- | + | ||
- | <p> | + | |
In performing this project, the following resources were referenced: | In performing this project, the following resources were referenced: | ||
- | </p> | ||
- | <ul> | ||
- | <li class=" | ||
- | </li> | ||
- | <li class=" | ||
- | </li> | ||
- | <li class=" | ||
- | </li> | ||
- | <li class=" | ||
- | </li> | ||
- | </ul> | ||
- | |||
- | <p> | ||
- | 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.) | ||
- | </p> | ||
- | |||
- | </ | ||
- | |||
- | <!-- wikipage stop --> | ||
- | </ | ||
- | |||
- | <div class=" | ||
- | |||
- | </ | ||
- | |||
- | <hr class=" | ||
- | |||
- | <!-- PAGE ACTIONS --> | ||
- | <div id=" | ||
- | <h3 class=" | ||
- | <div class=" | ||
- | <ul> | ||
- | < | ||
- | </ | ||
- | </ | ||
- | </ | ||
- | |||
- | | ||
- | <!-- ********** FOOTER ********** --> | ||
- | <div id=" | ||
- | <div class=" | ||
- | <div class=" | ||
- | <a href=" | ||
- | src="/ | ||
- | <a href=" | ||
- | src="/ | ||
- | <a href=" | ||
- | src="/ | ||
- | <a href=" | ||
- | src="/ | ||
- | </ | ||
- | </ | ||
- | |||
- | </ | ||
- | |||
- | <div class=" | ||
- | <div id=" | ||
- | </ | ||
- | </ | ||
- | |||
- | |||
- | |||
- | |||
- | |||
+ | * http:// | ||
+ | * http:// | ||
+ | * [[haas: | ||