Question: Create a project called Daily14. Add a C source file to the project named daily14.c. In this exercise, you will practice the top-down approach to
Create a project called Daily14. Add a C source file to the project named daily14.c.
In this exercise, you will practice the top-down approach to program design and implementation. Recall that, with this approach, we assume that any other functions on which a particular function depends operate as expected. We use stub functions as temporary placeholders when designing and implementing the program, and as we iterate, we refine these stubs by writing the C code that implements the required functionality. All of the functions that you write for this assignment should return void so that you can practice passing pointers to change the value of things.
Project Daily14: Stepwise refinement on daily 13.
Copy the code from Daily13.c into your daily14.c to begin. Design and implement the stub functions convert_lengths and convert_weights from Daily13.
The purpose here is to realize that although daily13 did not do everything that we wanted it to do, it was completely testable as a unit. We could test the looping behavior and see that it called the functions correctly and that the program did not accept bad input for the menu options. In this assignment you are going to revisit the code from daily13 and consider the two functions convert_lengths and convert_weights, examining these functions as the independent problems described below.
The function convert_lengths will ask the user if he or she wants to convert lengths from feet/inches to meters/centimeters (input value of 1) or from meters/centimeters to feet/inches (input value of 2). An input value of 0 indicates that the user no longer wants to convert length measurements. Based on the users input, the convert_lengths function will call a stub function length_to_metric for an input value of 1, a stub function length_to_us for an input value of 2, and return control to the main program for an input value of 0. Returning control to the main program simply requires your function to return. You should not ever call the function main from your program. The convert_lengths function continues to prompt the user for input until he or she correctly enters a value of 0, 1, or 2. The new stub functions should simply indicate the users choice by printing an appropriate message.
The function convert_weights will ask the user if he or she wants to convert weights from pounds/ounces to kilograms/grams (input value of 1) or from kilograms/grams to pounds/ounces. An input value of 0 indicates that the user no longer wants to convert weight measurements. Based on the users input, the convert_weights function will call a stub function weight_to_metric for an input value of 1, a stub function weight_to_us for an input value of 2, and return control to the main program for an input value of 0. The convert_weights function continues to prompt the user for input until he or she correctly enters a value of 0, 1, or 2. The new stub functions should simply indicate the users choice by printing an appropriate message
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
