Assignment #1, due April 16 4pm via Digital Drop box
Note: This assignment is to be done on
your own. I reserve the right to ask you about your code after you turn it in,
and to adjust your grade if you cannot explain your code.
Introduction
For this assignment, you will actually be writing
incorrect code, on purpose. The idea is to help you understand how
different test cases are important, and what makes 2 test cases actually
different.
Language
You may use C++ or Java.
Organization
Please put everything into a single file with a main() that
tests the functions by checking both the cases that should be correct
and the cases that should produce an error. For clarity, separate the
problems in the output with the following lines of output: (the number of
dashes doesn't matter)
-------------------------------
PROBLEM X
-------------------------------
where X is replaced by the appropriate number.
The main() should still do the right things in terms of style: describe the output.
- Look at this simple problem from a lab (written by Steve Cooper)
for an introductory programming course: In Canada, there is a provincial tax of 8% (the PST),
and a
federal tax of 7% (the GST). The function should take the price
of an item, and then print out the provincial tax, the federal tax, and the
total cost of the item.
Write a function that gets the
correct answer for an item costing $1, but fails for other inputs.
- A palindrome is a string that reads the same even if the order of the
letters is reversed. Examples include "radar", "eve", "abba", "ablewasiereisawelba",
"amanaplanacanalpanama". (The last two are more interesting if you break them up
into words: "Able was I ere I saw Elba" and "A man, a plan, a canal ... Panama!")
Write a version of an isPalindrome() method for strings that works
(returns true)
if the string is indeed a palindrome, but fails (returns true) if the string is not a
palindrome. To distinguish this one from the others, call it isPalindrome1.
Note that you should write isPalindrome1() as a plain function.
- Write a version of an isPalindrome() method for strings that works
if the string is not empty, but fails (returns false) if the string is empty. To distinguish
this one from the others, call it isPalindrome2.
- Write a version of an isPalindrome() method for strings that works
if the string is of even-length (has 0, 2, 4, ..., 2n characters), but fails
if the string is of odd-length. To distinguish
this one from the others, call it isPalindrome3.
Grading
Note that your answers must actually look like code that
might work. Any solution that purposely checks for a condition and then
explicitly causes the program to fail will receive no credit. Ex:
if
((str.length() % 2) == 1) while (true); // this doesn't count
- 35% for the best solved problem
- 25% for the second best solved problem
- 15% for the third best solved problem
- 5% for the fourth best solved problem
- 20% for general style-- good variable names, function names, comments, spacing,
indentation
Turning in your assignment:
Submit it to the Digital
Drop box by the start of class on the due date.