Due date: Wednesday, February 10, 2010, 11:55pm.
Task 1 (40 points)
Write a program, in a file called task1.c, that does the following:
- Ask the user to input a temperature T in Fahrenheit.
- If T is equal to 777.0, the program exits.
- Otherwise, the program should convert T from Fahrenheit to Celsius, and print the temperature in Celsius. Have in mind that if the temperature is T degrees Fahrenheit, then the temperature is X degrees Celsius, where X = (T-32) * 5 / 9.
- After the program prints the temperature in Celsius, it should go back to step 1.
Your solution must satisfy the following requirements:
- Temperatures should be represented as variables of type double.
- Conversion from Fahrenheit to Celsius should be performed by calling a function called convert_to_celsius, that takes as argument the temperature in Fahrenheit and returns the corresponding temperature in Celsius.
Optionally, you can submit the following code for partial credit (this may be useful if you cannot solve the entire task):
- Submit a file called task1a.c, where the program asks the user just once to input a temperature T, and then the program converts T to Celsius and prints the result, without using functions, and without asking the user to input any more temperatures after that.
- Submit a file called task1b.c, where the program asks the user just once to input a temperature T, and then the program converts T to Celsius and prints the result, using a convert_to_celcius function, but without asking the user to input any more temperatures after that.
- Submit a file called task1c.c, that behaves as specified for full credit (see steps 1, 2, 3, 4 above), but without using any function.
Task 2 (40 points)
Write a program, in a file called task2.c, that does the following:
- Ask the user to input two positive integers, A and B.
- If A<=0, or if B<=0, the program should exit without doing anything.
- Otherwise, the program prints out the number of integers between A and B (including A and B) that are multiples of 7 (i.e., numbers that, when divided by 7, give a remainder of zero). For example, if A = 15 and B = 30, then the program should print "There are 2 multiples of 7 between 15 and 30". If A = 5 and B = 60, then the program should print "There are 8 multiples of 7 between 5 and 60".
Your solution must satisfy the following requirements:
- There must be a function int is_multiple(int number, int Y) that returns 1 if number is a multiple of Y, and 0 otherwise.
- There must be a function int count_multiples(int A, int B, int X) that returns the number of integers between A and B (including A and B) that are multiples of X.
Optionally, for partial credit, you can submit:
- A file called task2a.c, that asks the user to input a number, and prints out whether that number is a multiple of 7, without using any functions.
- A file called task2b.c, that asks the user to input a number, and prints out whether that number is a multiple of 7, using the is_multiple function.
- A file called task2c.c, that behaves as specified for full credit, but without using functions.
Task 3 (20 points)
Mr. Bugs wants to write a simple program that prints out all multiples of 7 between 1 and 70. However, to his great chagrin, his program produces an unexpected output. Your task is to find and correct the bug in Mr. Bugs code.
DO NOT SUBMIT SOURCE CODE for this question. Just include, in your answers.doc file, an answer that includes:
- The line that contains the error in the original code.
- Your corrected version of that line.
Here is the program that Mr. Bugs wrote:
#include <stdio.h>
int main()
{
int i;
for (i = 7; i <= 70; i = i+7);
{
printf("%d\n", i);
}
}
How to submit
Submisions are only accepted via WebCT. The submission should include files task1.c, task2.c, answers.doc. Do not submit entire project directories, or anything else except for those three files.
Your answers.doc file should be a single Microsoft Word file that includes:
- Your name and UTA ID number at the top.
- A copy of your code from task1.c.
- A copy of your code from task2.c.
- Your answer for task 3.
Make sure that your answers.doc file is easy to parse, and that it is easy for us to figure out which part corresponds to which task. Feel free to use headings such as "start of copy of task1.c".
We try to automate the grading process as much as possible. Not complying precisely with instructions causes a significant waste of time during grading, and thus points will be taken off for failure to comply, and/or you may receive a request to resubmit.
Submission checklist
- Was the assignment submitted via WebCT?
- Did the submission include files task1.c, task2.c, answers.docs, and nothing else?
- Were all functions named as specified in the assignment, and taking arguments as specified in the assignment?