1 / 17

Recitation February 27, 2014

Recitation February 27, 2014. Test on Monday!! Email me BEFORE the weekend if you have questions. Project 2 will be going out next Wednesday. We’ll review it in class next week. . Announcements. Grades are posted using secret numbers Grading was based on: Writing all 3 functions

danton
Télécharger la présentation

Recitation February 27, 2014

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Recitation February 27, 2014

  2. Test on Monday!! • Email me BEFORE the weekend if you have questions. • Project 2 will be going out next Wednesday. • We’ll review it in class next week. Announcements

  3. Grades are posted using secret numbers • Grading was based on: • Writing all 3 functions • Correctly using the variables specified in function headers • Declaring necessary local variables • Correctly copying code segments Quizzes

  4. Reasons for functional decomposition: • Divide and conquer! • Easier to debug since the individual pieces can be tested. • Goals when decomposing: • Enable code reuse • Hierarchical decomposition- put functions in functions Functional Decomposition

  5. Pre-declaration of a function: • Takes place in a header file or above “main” • Ex. intfunction_name(int,int); • Calling the function inside of another function: • Omit the variable types and insert the variable to be passed in. • Ex. a=function_name(b,c); • Writing a function: • Can be written in a separate file or underneath main. • Include return and input variable types and names. • Ex. intfunction_name(int first, int second) { //Function code return 0; } Functional Decomposition

  6. Quiz 1 Solution

  7. Compiling multiple modules: • The files should be linked by a common header • Ex. #include “backgammon.h” • Recommendation: don’t #include other .c files! It makes compiling problematic. • Ex. gccbackgammon.hbackgammon.ccheck.c Compiling tricks

  8. Debugging: • Use gcc –g file_name.c • Making a binary: • Use gcc –c file_name.c • Compiling and renaming: • Use gcc –o new_file_name.outold_file_name.c Compiling Tricks

  9. Program Input Expected Compare Actual Test Vectors

  10. Create test vectors that test one aspect or the code’s full functionality. • Use “diff” to compare the actual output to the expected output: • Ex: gccprogram.outprogram.c program.out < test1.in > test.out diff test.out test1.expected.out program.out < test2.in > ! test.out diff test.out test2.expected.out Test Vectors

  11. Driver function Single function Input Expected Compare Actual Unit Tests

  12. Benefits of unit test vectors: • Supports functional decomposition • Allows for incremental test and build • In theory, they can be exhaustive. Unit Tests

  13. Initializing Arrays: • Arrays can be fully initialized once in C (this needs to happen when the array is first declared) • Example • Both pointers an arrays are used to access memory spaces. • The name of an array is a pointer to the first memory space occupied by the array. • Major difference: the address a pointer references can be changed. Pointers vs. Arrays

  14. Initializing: int number, *pointer, **point_2_pointer; • Assigning values: number=5; pointer=&number; point_2_pointer=&pointer; printf(“%i”,**point_2_pointer); printf(“%p”,*point_2_pointer); Brief Pointer review

  15. Math operations with pointers are all based on the size of the variable the pointer is used for. • Example Pointer Arithmetic

  16. Creating a function with a pointer as an input: intpointer_processing(intstep,char *array, int *value) { //Function’s code return 0;} • Creating a function with a pointer as an output: char* pointer_sending(int step, char *array, int *value) { char *array_point; //Function’s code return array_point; } Pointers with functions

  17. Know conversion to and from binary, octal and hexadecimal • Understand the benefits and principles of functional decomposition • Know the differences between pointers and arrays • Practice writing large pieces of code on paper under a time constraint. Tips

More Related