This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:spring2014:cprog:projects [2014/02/20 17:50] – [Projects] wedge | haas:spring2014:cprog:projects [2014/04/18 14:56] (current) – [Projects] wedge | ||
---|---|---|---|
Line 11: | Line 11: | ||
* [[/ | * [[/ | ||
* [[/ | * [[/ | ||
- | * [[/ | + | |
- | * [[/ | + | |
+ | * [[/ | ||
+ | ======Week 10====== | ||
+ | |||
+ | * Questions | ||
+ | * structs | ||
+ | * structs in action | ||
+ | |||
+ | ======Week 9===== | ||
+ | * Question and answer week. Some good code examples too. | ||
+ | |||
+ | ======Week 8===== | ||
+ | * As I teach the lab, I wasn't able to give out warning grades. I sent a list to Joe, who promptly did not get to submitting warning grades. However... I was rather unsettled by what I saw: | ||
+ | * 16 total people in the class | ||
+ | * 7 are doing fine (~43%) | ||
+ | * most have only submitted 3 or 4 out of 6 projects | ||
+ | * most have been very attentive on their Opus | ||
+ | * most have attended most if not all classes | ||
+ | * 2 would be doing fine (~12%) if they would keep their Opus up-to-date (at least one entry per week) | ||
+ | * projects/ | ||
+ | * don't forget about the Opus! | ||
+ | * 7 are not doing fine (~43%) | ||
+ | * none to 2 out of 6 projects submitted | ||
+ | * attendance is all over the place (never through all) | ||
+ | * opus is all over the place (1 entry total through just over 1 entry per week) | ||
+ | * So, 2+7 = 9; 9/16 = 56%. | ||
+ | * more than half the class is not passing (this is new to me) | ||
+ | * I don't seem to be getting enough questions based on the lack of work I'm seeing | ||
+ | * I know some people aren't spending enough time on class material (how are you going to learn it if you don't play with it) | ||
+ | * 56% of the class would get an F in the class if grades were to be submitted now | ||
+ | * We seem to have gotten about a week behind on project completion. Well, for those who have been being active and attentive in class. | ||
+ | * I've made the next project due in 2 weeks instead of 1 to help you get caught up. | ||
+ | * Remember: | ||
+ | * I can answer questions from Joe's side of class | ||
+ | * Joe can answer questions from my side of class | ||
+ | * We have tutors, they can help | ||
+ | * I can answers questions from my side of class | ||
+ | * I can answer said questions outside of class | ||
+ | * I can answer said questions inside of/during class | ||
+ | * Asking questions is good | ||
+ | ======Week 7====== | ||
+ | |||
+ | * Be sure your Opus is up to date with your weekly progress and exploits! | ||
+ | * loops | ||
+ | * for | ||
+ | * while | ||
+ | * do while | ||
+ | * functions | ||
+ | * return type | ||
+ | * parameters | ||
+ | * function prototypes | ||
+ | ======Week 6====== | ||
+ | |||
+ | * arrays | ||
+ | * pointer arithmetic | ||
+ | * loops | ||
+ | * for | ||
+ | * while | ||
+ | * do while | ||
+ | * Type in these programs, compile/ | ||
+ | * figure out what is going on with each and every step | ||
+ | * ask questions on things you do not understand | ||
+ | * Be sure to update your Opus! | ||
+ | |||
+ | =====Single Dimensional Array of Characters===== | ||
+ | Arrays are commonly used to simulate strings in C. | ||
+ | |||
+ | <code c 1> | ||
+ | /* | ||
+ | * This code should produce a warning on compilation. Fix it. | ||
+ | */ | ||
+ | #include < | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | int i; | ||
+ | char input[12]; | ||
+ | |||
+ | fprintf(stdout, | ||
+ | fgets(input, | ||
+ | |||
+ | fprintf(stdout, | ||
+ | |||
+ | for(i=0; i< | ||
+ | { | ||
+ | if (input[i] == ' | ||
+ | fprintf(stdout, | ||
+ | else if (*(input+i) == ' | ||
+ | fprintf(stdout, | ||
+ | else | ||
+ | fprintf(stdout, | ||
+ | } | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | =====Single Dimensional Array and Memory===== | ||
+ | To have a better understanding of arrays, we should note how they are represented in memory. Pay close attention to the output of this program: | ||
+ | |||
+ | <code c 1> | ||
+ | #include < | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | int i; | ||
+ | unsigned short int data[8] = { 255, 256, 49152, 13, 65535, 2600 }; | ||
+ | |||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | fscanf(stdin, | ||
+ | |||
+ | fprintf(stdout, | ||
+ | fscanf(stdin, | ||
+ | |||
+ | fprintf(stdout, | ||
+ | for(i = 0; i < 8; i++) | ||
+ | { | ||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | } | ||
+ | fprintf(stdout, | ||
+ | |||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | =====Command-line Arguments and 2D Array Manipulation===== | ||
+ | Here we play with a two-dimensional array created by the system, via the command-line arguments provided to main(): | ||
+ | |||
+ | <code c 1> | ||
+ | /* | ||
+ | * Fun with arrays and loops using command-line arguments | ||
+ | * | ||
+ | * Try renaming the executable, and running it with different numbers/ | ||
+ | */ | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main(int argc, char **argv) | ||
+ | { | ||
+ | int i, j; | ||
+ | |||
+ | fprintf(stdout, | ||
+ | for(i = 0; i < argc; i++) | ||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | |||
+ | for(i = 0; i < argc; i++) | ||
+ | fprintf(stdout, | ||
+ | fprintf(stdout, | ||
+ | | ||
+ | for(i = 0; i < argc; i++) | ||
+ | { | ||
+ | for(j = 0; j <= strlen(argv[i]); | ||
+ | { | ||
+ | if ((*(*(argv+i)+j)) == ' | ||
+ | fprintf(stdout, | ||
+ | else | ||
+ | fprintf(stdout, | ||
+ | |||
+ | fprintf(stdout, | ||
+ | } | ||
+ | fprintf(stdout, | ||
+ | } | ||
+ | fprintf(stdout, | ||
+ | |||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
======Week 5====== | ======Week 5====== | ||
Line 19: | Line 189: | ||
* if/else if/else | * if/else if/else | ||
* switch/case | * switch/case | ||
- | * arrays | + | * value of taking the modulus (remainder) of a number |
- | * creating | + | * with integers, math has no decimal points-- such values are dropped/ |
- | * using | + | * 4 < |
- | * pointers | + | |
- | * loops | + | * 22 / 8 = 2 |
- | * for loops for assisting in array manipulation | + | * 4 / 6 = 0 |
- | * probably will not get to all this stuff | + | |
- | * overview of next project | + | * < |
+ | * < | ||
+ | * Pointer-related video: [[http:// | ||
+ | * on lab46, if you see a C function you don't know, try looking up its manual page: | ||
+ | * for printf(): **man 3 printf** | ||
+ | * for atoi(): **man 3 atoi** | ||
+ | * for rand(): **man 3 rand** | ||
+ | | ||
+ | * did some code walk-throughs/ | ||
+ | * for the following programs, work out by hand the values for **i** and **m** when x is: | ||
+ | * 1 | ||
+ | * 2 | ||
+ | * 3 | ||
+ | * 4 | ||
+ | |||
+ | ===Sample code 1=== | ||
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | int i, x, m = 0; | ||
+ | srand(time(NULL)); | ||
+ | x = rand()%4 +1; | ||
+ | for(i=0; | ||
+ | { | ||
+ | m = m + i + x; | ||
+ | } | ||
+ | if(m< | ||
+ | i=7; | ||
+ | else if(m==16) | ||
+ | i=4; | ||
+ | else if((m%2)==1) | ||
+ | i=33; | ||
+ | else | ||
+ | i=6; | ||
+ | |||
+ | printf(" | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===Sample code 2=== | ||
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main(int argc, char **argv) | ||
+ | { | ||
+ | int m, i, x; | ||
+ | if(argc <2) | ||
+ | { | ||
+ | fprintf(stderr, | ||
+ | exit(1); | ||
+ | } | ||
+ | x= atoi(argv[1]); | ||
+ | for(i=0; | ||
+ | { | ||
+ | m = m+i+x; | ||
+ | } | ||
+ | m=m%8; | ||
+ | |||
+ | switch(m) | ||
+ | { | ||
+ | case 0: | ||
+ | i=3; | ||
+ | break; | ||
+ | case 1: | ||
+ | case 2: | ||
+ | i=12; | ||
+ | break; | ||
+ | case 4: | ||
+ | case 7: | ||
+ | i=7; | ||
+ | break; | ||
+ | case 5: | ||
+ | i=2; | ||
+ | break; | ||
+ | default: | ||
+ | i=0; | ||
+ | break; | ||
+ | } | ||
+ | printf(" | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
======Week 4====== | ======Week 4====== | ||