Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Copy the code from Daily19.c into your daily23.c to begin. Design and implement the stub functions convert_lengths and convert_weights from Daily19. The purpose here is

Copy the code from Daily19.c into your daily23.c to begin. Design and implement the stub functions convert_lengths and convert_weights from Daily19. The purpose here is to realize that although daily19 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 daily19 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 (input value of 2). An input value of 0 indicates that the user no longer wants to convert weight measurements and want to return to the main menu. 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.

This is my code from Daily19(Please modify/ add to this code if possible):

#include

#include

//Function prototypes here

void convert_lengths();

void convert_weights();

int main(int argc, char* argv[])

{

int userInt=4;

//Need the user to be trapped in a while loop in order to continously

//get a input that is valid

while(userInt != 0)

{

//Printf statements prompting the user to enter an input within range

printf("1. convert lengths ");

printf("2. convert weight ");

printf("0. Exit ");

printf("Enter your choice: ");

scanf("%d",&userInt);

//various if statementsd that handle each case

if(userInt == 1)

{

convert_lengths();

}

else if(userInt == 2)

{

convert_weights();

}

else if(userInt == 0)

{

//This ends the program since there is no function for case 0

printf("The user chose to exit ");

}

else{

//Asks the user to re enter within range should they enter something that is not

printf(" Please enter either 0,1,or 2: ");

}

}

return 0;

}

//The following are the stubs that simply print what the user has elected to convert

void convert_lengths(){

printf("The user wants to convert lengths ");

}

void convert_weights()

{

printf("The user wants to convert weights ");

}

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

Step: 3

blur-text-image

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions