Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

about c language Do problems 1 and 2 of Column 5 *problems 1 : comment on the programming style used in this column and in

about c language

Do problems 1 and 2 of Column 5

*problems 1 : comment on the programming style used in this column and in this book in general address issues such as teh variable names, the form and specification of the binary search function the code layout and so forth.

*problems 2: translate the pseucode description of binary search into languages other than c. and build scanffolding to test and debug your implementation how do the language and syste, help and hinder.

Lab:: problems 1 and 2 of Column 5

Instead of commenting on his code, rewrite it so that it adheres to our courses programming standards and guidelines. This should be done with the binary search on page 46. Include all the

assertions found in Section 5.3 and the test scaffolding found in Section 5.4. Note that this has to be done for C and

not for other languages as suggested in problem 2. Instead of commenting on his code, rewrite it so that it adheres to our coursesprogramming standards and guidelines.

This should be done with the binary search on page 46. Include all the

assertions found in Section 5.3 and the test scaffolding found in Section 5.4. Note that this has to be done for C and

not for other languages as suggested in problem 2.

image text in transcribed

46 PROGRAMMING PEARLS while (scanf("%d %d", &n , &t) for (i = 0; i t 0 x[result] =- We can start with a C program of about two dozen lines: the binarysearch function and the above code in the main function. We should expect to grow the program as we add additional scaffolding postcondition: Most of the pseudocode statements in Section 4.2 translate line-by-line most other languages, for that matter). Where the pseudocode stores a mto answer variable p, the C program will return the value. Replacing the aue in loop with the C infinite loop for (::) yields this code When I type the input line "2 0", the program generates the two-element array with x [O] =0 and x[1 ] 0, then reports (on the next, indented, line) that the result of searching for 0 was that it was in location 0: 2 10 return -1; rest of loop -5 -1 -1 2 15 We can transform that to a while loop by reversing the test: while (1u) f .. rest of loop The typed input is always in italics. The next pair of lines shows that 10 is correc found in location 1. The final six lines describe three correct unsuccessful search The program thus correctly handles all possible searches in an array of two disti elements. As the program passed similar tests on inputs of other sizes, I grew m and more confident of its correctness and more and more bored with this labori hand testing. The next section describes scaffolding to automate this job. return -1; The final program is then int binarysearch(DataType t) return (any) position if t in sorted x[O..n-1] or int 1, u, 1 if t is not present Not all testing proceeds this smoothly. Here is a binary search proposed by eral professional programmers while (1 t*/ u=n-1; /* printf(" %d %d %d ", 1, m, u) ; */ if (x[m] t) else return -1; u=m; 5.2 A Test Harness return m; The first step in exercising the function is, of course, to walk through a few st cases by hand. Tiny cases (zero-, one- and two-element arrays) often suffice to Smok out bugs. On larger arrays such tests become tedious, so the next step is to build a river to call the function. Five lines of C scaffolding can do the job return -1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

Students also viewed these Databases questions

Question

What does standard of living mean to you?

Answered: 1 week ago

Question

2. What efforts are countries making to reverse the brain drain?

Answered: 1 week ago