COSC 10503: C Programming Lisa Ball Last update: 10.17.09 ============================================================= ***SEE HOMEWORK ASSIGNMENTS BELOW*** Lab (357 TTC 3rd floor) help hours: Ford and Alex -- contact info sent in email ================================================================== Planned exam dates (see syllabus): Exam 1: Wed., Sep 30, 2009 Exam 2: Wed., Nov 4, 2009 Final Exam: Final exam is held according to the official University schedule. ================================================================== INFORMATION YOU NEED TO KNOW When you are asked to email me your C program files=> Send your documented program to l.ball@tcu.edu. Subject line should be "lab# turnin" (example lab7 turnin) Attach your program file as lab#name.c (example lab1smith.c),using ONE of the partners names. === REQUIRED DOCUMENTATION === Use comments like on page 49 (*** points will be deducted if you do not ***). An example: /* * Programmer: Ozzy Ozborne Date Completed: 10-22-08 * Programmer: Janice Joplin Class: COSC 10503 * Instructor: Dr. Lisa Ball * * This program calculates and displays the mean, variance, * and standard deviation from the data stored in the file * absorb.txt. */ I strongly encourage you to work in PAIRS. Make sure both partners names appear in the documentaiton. LAB closes at 5:00pm on Fridays...keep this in mind when submitting your assignments lcc note: develop your programs in a directory path that does NOT contain spaces (e.g. c:\myprograms, not c:\my programs) Basic tutorial on the Windows lcc compiler is at http://www.q-software-solutions.de/products/lcc-win32/tutorial.shtml ============================================================================== Hw #1 Due Date Friday, Sep. 4 (start of class (10:00am Central)) Problem: Question #6 (Chapter 2, end of chapter) Additional Instructions: *** TURN IN TO ME YOUR C PROGRAM, PRINTED ON PAPER (aka a hardcopy)*** (if you will be absent, then contact me for other arrangments) ============================================================================== Hw #2 Due Date Sep 14 (Monday) Problem: page 111 #3 (Chapter 3) Additional Instructions: (1) EMAIL YOUR PROGRAM Do this for all labs from now on unless specifically told otherwise Instructions reprinted from above: Send your documented program to l.ball@tcu.edu. Subject line should be "lab# turnin" (example lab7 turnin) Attach your program file as lab#name.c (example lab1smith.c),using ONE of the partners names. (2) your instruct() function should only include the printf statements. Do not pass or return parameters. (3) Like all the labs, you can work in teams of 2 (pair programming) ============================================================================== Hw #3 Due Date Sep 18 (Friday) Problem: page 112 #8 (Chapter 3) Additional Instructions: (1) EMAIL YOUR PROGRAM Do this for all labs from now on unless specifically told otherwise (2) your instruct() function should only include the printf statements. Do not pass or return parameters. (3) Like all the labs, you can work in teams of 2 (pair programming) ============================================================================== Hw #4 Due Date Sep 25 (Friday) Problem: #4 (Chapter 4) Additional Instructions: ============================================================================== Hw #5 Due Date Oct 2 (Friday) Problem: page 231 #8 (Chapter 5) Additional Instructions: do the correct one! =============================================== ============================================================================== Hw #6 Due Date Oct 16 (Friday) Problem: page 228 #3 (Chapter 5) Additional Instructions: you'll want 2 loops (nested) =============================================== Hw #7 Due Date Oct 23 (Friday) Problem: Figure 5.12 (Chapter 5) Additional Instructions: Type in Figure 5.12 (page 196). The purpose of this lab is to test your ability to properly set up a program that uses file input. =============================================== =============================================== =============================================== S P R I N G 2 0 0 9 =============================================== Below is from spring 2009 Useful for extra practice =============================== Hw #1 Due Date Jan 28 (midnight: at the end of the day Wednesday) Problem: page 72 #3 (Chapter 2) Additional Instructions: ============================================================================== ============================================================================== Hw #2 Due Date Feb 4 (midnight: at the end of the day Wednesday) (or whatever date next wednesday is) Problem: page 111 #5 (Chapter 3) Additional Instructions: your instruct() function should only include the printf statements. Do not pass or return parameters. ============================================================================== Hw #3 Due Date Feb. 11 (midnight: at the end of the day Wednesday) Problem: page 161 #8 (Chapter 4) Additional Instructions: The 3 weights (w1,w2,w3) should be values between 0 and 1 (inclusive) and must sum to 1 (w1+w2+w3=1). ============================================================================== ============================================================================== Hw #4 Due Date Feb 25 (midnight: at the end of the day Wednesday) Problem: page 171 Self-check Programming #1 (Chapter 5) Additional Instructions: Write a complete program to produce the required output, once using a while loop and once using a for loop. Write a function called my_while() to produce the required output using a while loop and another function called my_for() to produce the required output using a for loop. The main() function should only (1) print the name of the function just before it is called and (2) call the 2 functions that you write. All variables must be of type int. DO NOT USE THE pow() FUNCTION FOR THE CALCULATION. Define a constant NUM_VALUES with the value 6. Use NUM_VALUES to control how many times each loop executes. For all labs, remember to - Comment and add spacing for major sections of code (each function should have spacing and documentation above it). - Add an example of expected input format in all user prompts - Test multiple times with different inputs (where appropriate) ============================================================================== ============================================================================== Hw #5 Due Date Mar 4 (midnight: at the end of the day Wednesday) Problem: page 231 #9 (Chapter 5) Additional Instructions: For all labs, remember to - Comment and add spacing for major sections of code (each function should have spacing and documentation above it). - Add an example of expected input format in all user prompts - Test multiple times with different inputs (where appropriate) ============================================================================== ============================================================================== Hw #6 Due Date Mar 11 (midnight: at the end of the day Wednesday) Problem: Write a program to calculate and display the average for each group of numbers in a file named numbers.txt (store this file in the same directory as your executable so you only need to give the file name when opening the file). The file data is arranged so that each group of numbers is preceded by the number of data items in the group (you may assume the file was created accurately). For example: 5 96 87 78 93 21 4 92 82 85 87 6 72 69 85 75 81 73 <== in your text editor, hit the enter key after this line Thus, the first number in the file, 5, indicates that the next 5 numbers should be grouped together. The number 4 indicates that the following 4 numbers are a group, and the 6 indicates that the last 6 numbers are a group. Additional Instructions: The code below shows a sample of reading from an input file. Note we use int main() instead of void main() so we can return a value. For the above assignment, you'll use a nested loop with the outer loop terminating when EOF is encountered. #include int main() { FILE *infile; double val; if ((infile=fopen("numbers.txt","r"))==NULL) { // try to open file for reading printf("\nFailed to open the input file afile.txt\n"); return(1); // exit program due to error } while (fscanf(infile,"%ld",&val)!=EOF) printf("here's where we process each element read"); fclose(infile); return(0); // normal program termination } ============================================================================== ============================================================================== Hw #7 Due Date Mar 25 (midnight: at the end of the day Wednesday) Problem: page 357 #4 (Chapter 7) Additional Instructions: For your input file, use this file (HW10503.txt), moved to the appropriate location so that you do not need to use a path name in fopen(). For your output file, use the name count.txt. Only output the array values for printable characters (ASCII value 32 for space to ASCII value 126 for the ~ character). See Appendix A in your text for the full ASCII character set. ============================================================================== ============================================================================== Hw #8 Due Date Apr 8 (midnight: at the end of the day Wednesday) Problem: page 303 #8 (Chapter 6) Additional Instructions: use a file named signal.txt for the input signal stream. ============================================================================== ============================================================================== Hw #<9> Due Date (midnight: at the end of the day ***MONDAY***) the last lab of the semester :) Problem: Create a story. Create a story composed of 3 randomly generated sentences. Each sentence is formed as ARTICLE-NOUN-VERB-PREPOSITION-ARTICLE-NOUN. Place a space between each word. End each sentence with a period and space. Capitalize the first letter of each sentence. An example sentence is "The dog walked to a town. " Use at least the following 2 functions: select_word() -- pass an array of words, the number of words in the array, and return a randomly selected word form the array. build_sentence() -- pass the 6 words that have been selected and output the complete, formatted sentence. You may want to pass in the words within an array. Use the following 4 arrays of 5 words each. ARTICLE: the, a, one, some, any NOUN: boy, girl, dog, town, car VERB: drove, jumped, ran, walked, skipped PREPOSITION: to, from, over, under, on ============================================================================== ==============================================================================