In this exercise you will practice the topdown approach to p

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. Create a project called Daily19. Add a C source file to the project named daily19.c. Converting lengths and weights Write a program that asks the user if he or she wants to convert values that are lengths or weights. If the user chooses lengths, the program calls a stub function convert_lengths that simply indicates the user\'s choice. If the user chooses weights, the program calls a stub function convert_weights that simply indicates the user\'s choice. Use the value 1 to indicate lengths and the value 2 to indicate weights. If the user enters 0, terminate the program. The program should continue to prompt the user for input until he or she correctly enters a value of 0, 1, or 2. In addition, the program should allow the user to call convert_lengths or convert_weights as many times as desired (i.e., until a value of 0 is input, indicating that the user is finished). Notice that this style of loop does not require you to ask the user if they want to continue but instead assumes they want to continue until they select 0. From now on, please always write comments for each function and explain the function parameters. You should write comments for other part of your code when needed. An example output:

Solution

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

int convert_lenghts();
int convert_weights();
void exit();

//main function
int main()
{
//variable to store selection of user.
int i;
//prompt user for selection.
printf(\"1. convert lenghts\ \");
printf(\"2. convert weights\ \");
printf(\"3. exit\ \");

printf(\"Please choose from (1,2,0) \");
//read selection from user.
scanf (\"%d\",&i);
//switch case statments for the selection.
switch(i)
{
case 1:
convert_lenghts();
system(\"pause\");
break;
case 2:
convert_weights();
system(\"pause\");
break;
case 3:
exit();
system(\"pause\");
break;

default :
printf(\"Enter valid number\ \");
system(\"pause\");
}
}

int convert_lenghts()
{
//stub for conversion of lenghts.
}

int convert_weights()
{
//stub for conversion of weights.
}

void exit(){
system.exit();
}

 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 funct

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site