1 / 13

Composition Steps

Composition Steps. 03 / 20 / 2013. Sort an array of numbers. int main( int argc , char* argv []) { int numbers[SIZE] = {2,5,3…} // COMPOSE IN MODULE HERE }. Sort an array of numbers. int main( int argc , char* argv []) { int numbers[SIZE] = {2,5,3…} // COMPOSE IN MODULE HERE

jeslyn
Download Presentation

Composition Steps

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. Composition Steps 03/20/2013

  2. Sort an array of numbers int main(intargc, char* argv[]) { int numbers[SIZE] = {2,5,3…} // COMPOSE IN MODULE HERE }

  3. Sort an array of numbers int main(intargc, char* argv[]) { int numbers[SIZE] = {2,5,3…} // COMPOSE IN MODULE HERE } Source parameters // precondition: numbers is array of ints // postcondition: numbers[0] <= ... <= numbers[SIZE-1] Preconditions Postconditions

  4. Sort an array of numbers int main(intargc, char* argv[]) { int numbers[SIZE] = {2,5,3…} // COMPOSE IN MODULE HERE } int* quicksort(int* input, int p, int r) void mergesort(char* input, int p, int r) void bubblesort(int* input) Available modules Starting slightly simpler … no structs

  5. Quicksort composition int* quicksort(int* input, int p, int r) Target parameters // precondition: input != NULL // precondition: input is array of ints // precondition: p != r // postcondition: input[0] <= ... <= input[SIZE-1] Preconditions Postconditions

  6. Quicksort composition int* quicksort(int* input, int p, int r) Target parameters // precondition: input != NULL // precondition: input is array of ints // precondition: p != r // postcondition: input[0] <= ... <= input[SIZE-1] Preconditions Postconditions

  7. Quicksort composition int* quicksort(int* input, int p, int r) // precondition: input != NULL // precondition: input is array of ints // precondition: p != r // postcondition: input[0] <= ... <= input[SIZE-1] Preconditions Postconditions ROLE: buffer ROLE: High Index ROLE: Low Index

  8. Quicksort composition int* quicksort(int* input, int p, int r) • Checking preconditions: • Source buffer is array of integers • Target buffer is array of integers • No transform required • Checking postconditions: • Postconditions match exactly • No mismatch detected • No transform required • [code] • Insert (wrapper | function pointer | method • invocation) Composition Steps Generated

  9. Mergesort Composition void mergesort(char* input, int p, int r) Target parameters // precondition: input != NULL // precondition: input is array of chars // precondition: p != r // postcondition: input[0] <= ... <= input[SIZE-1] Preconditions Postconditions

  10. Mergesort composition void mergesort(char* input, int p, int r) • Checking preconditions: • Source buffer is array of integers • Target buffer is array of chars • Transform required • Checking postconditions: • Postconditions do not match • Transform required • [code] • Int2Str • Insert (wrapper | function pointer | method) • Str2Int Composition Steps Generated

  11. Bubblesort Composition void bubblesort(int* input) Target parameters // precondition: input != NULL // precondition: input is array of ints // precondition: p != r // postcondition: input[0] <= ... <= input[SIZE-1] Preconditions Postconditions

  12. Bubblesort composition void bubblesort(int* input) • Checking preconditions: • Source buffer is array of integers • Target buffer is array of integers • No transform required • Checking postconditions: • Postconditions match • No transform required • [code] • Insert (wrapper | function pointer | method) Composition Steps Generated

  13. New questions! • Is there a time when a function invocation is better than a pointer / wrapper? • Transforms may lend themselves better to wrappers – self contained • Function pointer “messier” as ‘anything’ can be passed in • Getting into soft metrics?

More Related