Due date: Wednesday, February 24, 2010, 11:55pm.
Task 1 (30 points)
The program in example.cpp allows the user to create an array of integers, of any length that the user wants, and it also allows the user to enter a value for each element in the array. Finally, the program prints out the array.
Write a program, in a file called task1.c, that is a modification of example.cpp, so that an array of doubles is created and printed instead of an array of integers. The user should be able to provide real numbers as values for the elements of the array. Feel free to copy/paste and modify code from example.cpp. Your solution should:
- define and use a function called read_double_array that is similar to the read_int_array function, except that it creates an array of doubles.
- define and use a function called print_double_array that is similar to the print_int_array function, except that it prints an array of doubles.
Hint: You will probably find it useful to use code from task 1, or from the example.cpp for the rest of the tasks in this assignment.
Task 2 (30 points)
Write a program, in a file called task2.c, that lets the user create an array of doubles and specify values for the elements of the array, and prints out the maximum value in that array. In particular, the program should perform the following steps:
- Asks the user to specify the length of the array.
- If the length specified by the user is less than or equal to 0, the program exits.
- Asks the user to enter a value for each element of the array.
- Prints out the array.
- Finds the largest value in the array, and prints that largest value.
For full credit, your program should define and use a function called double find_maximum(double * numbers, int length) that takes as input an array and the length of that array, and returns the largest value in that array. For partial credit, you can make a program that behaves as specified above but does not define or use the find_maximum function. For partial credit, you can make your function work with an array of ints, if you cannot get it to work with an array of doubles.
Task 3 (40 points)
Write a program, in a file called task3.c, that lets the user create an array of ints and specify values for the elements of the array, and prints out how many even numbers the array contains. In particular, the program should perform the following steps:
- Asks the user to specify the length of the array.
- If the length specified by the user is less than or equal to 0, the program exits.
- Asks the user to enter a value for each element of the array.
- Prints out the array.
- Counts how many even numbers the array contains, and prints out the answer.
Your program should define and use a function called int count_even_numbers(int * numbers, int length) that takes as input an array and the length of that array, and returns how many even numbers are stored in that array. For example:
- If the array contains numbers 5, 2, 3, 5, 2, 4, the answer is "3".
- If the array contains numbers 8, 8, 8, 8, the answer is "4".
- If the array contains numbers 8, 1, 3, the answer is "1".
- If the array contains numbers 1, 3, 5, 3, 1, 7, the answer is "0".
How to submit
Submisions are only accepted via WebCT. The submission should include files task1.c, task2.c, task3.c, and answers.doc. Do not submit entire project directories, or anything else except for the .c files and the answers.doc file.
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.
- A copy of your code from task3.c.
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 answers.doc contain your name and UTA ID?
- Did the submission include files task1.c, task2.c, task3.c, answers.docs, and nothing else?