Starting from:

$29.99

CS2211 ASSIGNMENT 2 Solution



Assignment overview
We would like students to experience command line input with C types of character, int, and float, to understand and use C types such as char, int, and float, as well as the flow control structures studied in class, and to use functions and recursive functions.
This assignment consists of two parts.
In part one, you are required to write a C program to perform some simple conversions. In part two, you are to write a C program to calculate value of exponential numbers.
Part one: 70%
The goal of the exercise is to implement a simple converter, called ”converter.c”, which works as follows.
(1) First, the user is asked what she/he wants to do. A single character can be entered with the following six actions associated with different values of the character. You can assume that the user will always enter a single character.
• 1 for conversion between Kilometer and Mile
• 2 for conversion between Litre and Gallon
• 3 for conversion between Centimetre and Inch
• 4 for conversion between Celsius and Fahrenheit
• 5 for quit
• For any other character, repeat step (1)
(2) In case of 1, 2, 3, and 4, each action should be implemented as a function. In case of 5, the program will terminate. For all the other values, repeat step (1).
(3) In case of 1 to 4, the program will ask the direction of the conversion. In each case, a single character can be entered whose value corresponding to each conversion direction.
In case of 1, the program will prompt the user for two choices and wait for a character input
• K for conversion from Kilometer to Mile
• M for conversion from Mile to Kilometer
• For any other character, repeat this case
In case of 2, the program will prompt the user for two choices and wait for a character input
• L for conversion from Litre to Gallon
• G for conversion from Gallon to Litre
• For any other character, repeat this case
In case of 3, the program will prompt the user for two choices and wait for a character input
• C for conversion from Centimetre to Inch
• I for conversion from Inch to Centimetre
• For any other character, repeat this case
In case of 4, the program will prompt the user for two choices and wait for a character input
• C for conversion from Celsius to Fahrenheit
• F for conversion from Fahrenheit to Celsius
• For any other character, repeat this case
HINT: to read a character properly, your program should handle the leading space character, tab character, and end of line, or new line, character, if any.
(4) Then the program asks for the input value, properly displays the result and returns to Step (1).
• The input value should be a float number and we assume the user will always enter valid numbers.
• Your program should prompt user and display the result to user in a descriptive manner.
(5) Your program should follow good programming styles, i.e. write clear code, choose good variable names, use appropriate functions, make proper comments, and etc.
Part two: 30%
The goal of this exercise is to implement an exponential number calculator, called ”exp calculator.c” with recursive function.
(1) First, the user is asked for the base and the exponent. We assume that base is a nonzero float number and exponent is an integer number. If the input base is zero, exit program.
(2) Then the exponential number is calculated using a recursive function in logarithmic time in terms of the absolute value of the exponent inputted. The result is then displayed. Hint:
for n> 0
if n is even
a(n−1)/2 ∗a(n−1)/2 ∗a = (a(n−1)/2)2 ∗a if n is odd

(3) You can assume that the user always enter float number for the base and integer number for the exponent. After each calculation, go to (1).
(4) Your program should follow good programming styles, i.e. write clear code, choose good variable names, use appropriate functions, make proper comments, and etc.
Testing your program
You should test your program by running it on Gaul. For part one, each case should be tested at least once. For part two, different bases and exponents should be tested. Capture the screen of your testing by using script command. There should be two resulting script files, converter.script and exp calculater.script, one for each part.
For assignment 2, in your Gaul account, you should have the following files in directory ∼/courses/cs2211a/Asn/asn2 to be submitted:
• Asn SubmissionForm.txt (fill with the required information)
• converter.c (for part one)
• converter.script (for part one)
• exp calculater.c (for part two)
• exp calculater.script (for part two)
Change your current working directory to ∼/courses/cs2211a/Asn. Create a file named YourUserName asn2.tar.gz and submit this file for assignment 2. YourUserName should be your UWO email account user name which is the same as your Gual account login user name. (For detailed information, please check CS2211a Assignment Submission Guidelines).

More products