Anda di halaman 1dari 2

Read ALL of this, please. Thank you. Notice that this is labeled Problem Set 3a - Program 1.

This is the first assignment where you should verify that it runs correctly on the computer. You will submit the C source code for Exercise 2.7 Exercise 2.8 Exercise 2.9 BUT we are changing the instructions slightly. Be sure to read this all the way to the end. These three exercises are three different techniques to solve the same problem. Exercise 2.7 uses recursion; Exercise 2.8 uses a while-loop; and Exercise 2.9 uses a for-loop. If you're not sure you understand one technique but have more confidence about another, do the one you understand first. What is different from the book description of the assignment exercises? The book description tells you to write three separate programs, one for each exercise. It gives an example in Exercise 2.6 where -- the author writes main to create test cases and check results; -- main calls sum which the author writes to check for bad input and it returns a value to indicate that the input was bad OR, if the input is ok, sum calls _sum -- _sum performs the actual activity of interest. In your assignment, you will -- write main to call each of three functions called productRecursion, productWhile, and productFor. Main tests them for their ability to detect bad input and, if a function runs to completion, main prints the result. (See example in Exercise 2.6) -- write productRecursion to check for bad input. If the input is good, it should then call _productRecursion to perform as described in Exercise 2.7. -- write productWhile to check for bad input. If the input is good, it should then call _productWhile to perform as described in Exercise 2.8. -- write productFor to check for bad input. If the input is good, it should then call _productFor to perform as described in Exercise 2.9. How to submit: Use the editor on the student server to create your program in a file. It will save time for the TA's if you name your file program1.c. Then put program1.c into a ZIP file and submit the zip file. Before you submit it as your homework, you should compile program1.c with the gcc compiler: >gcc -Wall -Wextra -o program1 program1.c If it compiles without finding any errors, it will show the prompt: > If gcc found errors, you'll see those instead and you'll have to fix the problems and rerun the compile command. If you get the prompt and no error messages, you can then tell the system to run your executable program called program1 (notice that it does not end in ".c"). >./program1 STRONG ADVICE: Pick one of the three functions and write main, the product and _product functions for the one you picked. Compile; fix errors until correct; run and verify results. THEN add statements in main to call the next product function, add that product function, and add the _product function that

corresponds to it. Compile; correct errors; run and verify results. Then do the same for the third function. This is called "incremental development". Programmers in many, many companies approach development this way (AFTER they understand WHAT they are supposed to be doing). This is due on Friday, February 10, 6:00 p.m. Prof. Dameron

Anda mungkin juga menyukai