Final Version, Oct 17, 1996 READ THE WHOLE FILE AND DO SO CAREFULLY. DO NOT TURN THIS IN WITH THE turnin PROGRAM BEFORE 8 AM Tuesday, OCTOBER 15. If you finish before then, just wait a while before turning it in. Also, check for changes before turning it in. CSE 9A UCSD Fall, 1996 Assignment 3 Due dates for Assignment 3: >>You must turn it in with the turnin program from your account for this class by midnight at the end of the day Monday Oct 21. (If you miss that deadline, you can turn it in up to 24 hours late, but with a penalty.) >>You must complete an interview for assignment 3 by the end of the day Monday October 28. Note that there is no grace period on the interview deadline. Reading: Chapters 3 and Section 4.1 of Chapter 4 all in the Savitch text Programming: In this exercise you will start with a partially written program and fill in the missing code. In most cases what is missing are function definitions. The program with the blanks to fill in is in the file hw03.template. You must fill in some missing code in the main part of the program and you must give three function definitions. The completed program will ask the user if he/she wants to convert from miles to kilometers or from kilometers to miles. The user responds with the number 1 for the first case and the number 2 for the second case. If the user responds with any other number, he/she is asked the question again, and again until an appropriate response is made. The program will then ask for the appropriate input and compute the appropriate answer. The program then repeats this action again and again until the user says to quit. More specifically, after doing one calculation, the program asks: Do you want to do it again? (yes/no). The user responds with "yes" or "no", but the program reads only the first letter 'y' or 'n'. (Actually any letter other than 'y' is interpreted as "no"). Upper or lowercase letters can be used. To see what the dialogue should be like you can run hw03.o which contains the compiled object code from a solution to this assignment. Details: >You do not need to define any functions besides those whose prototypes are given in hw03.template. >Be sure to place all function definitions after main and to leave the function prototypes before main. >The function new_line(), whose prototype is given below, takes zero arguments. This function will disregard all the input remaining on a line so that the next time there is a cin, the input will be taken from the next line. The definition of new_line is given in hw03.template. You do not need to understand the definition. You only need to know how to use the function new_line. void new_line(); //Discards all the input remaining on the current input line. >The function from_miles_to_kilometers, whose prototype is given below, takes no arguments and returns one of the two letters, uppercase 'M' or uppercase 'K'. This function is unlike any in the text book in that it gets it's information by carrying on a dialogue with the user, rather than having any arguments. Run the sample object code to see what this dialogue should be. In particular notice that the user is asked to input the number 1 or 2, not the letters 'M' or 'K'. Also note that if the user types in some other number, then they are asked again to enter a number. THIS FUNCTION MUST USE A LOCAL VARIABLE NAMED ans TO HOLD THE NUMBER TYPED IN BY THE USER. SO ans WILL BE OF TYPE int. (Note that main also has a variable named ans, but the one in main is of type char.) char from_miles_or_kilometers(); //Returns 'M' if the user wants to convert from miles to kilometers. //Returns 'K' if the user wants to convert from kilometers to miles. //Gets the answer by asking the user. //Keeps asking the user until it gets an appropriate answer. >It is good programming practice check the user's input. In the function from_miles_or_kilometers the user is asked to enter 1 or 2. If the user enters any other number, the user is asked again. This is good and should normally be done whenever input is accepted from the user. But, for this assignment, you only need to do this sort of checking in the from_miles_or_kilometers function. October 17, 1996