## CSci 1001 Problem set 3. Due Thursday, October 23 at 2pm.

### Problem 1 (6 points): history of computers

Questions 14, 15, 18 p. 113.

### Problem 2 (8 points): Elections result

Write a program that reads the names of two candidates, then asks you to enter the number of votes for each person, and then prints the the name of the winner. If it's a tie, it has to say so.

For instance, the dialog with the program may go like this (using prompts to read the data):

• The program asks "Please enter the name of the first candidate:", you enter "Bart Simpson"
• The program asks "Please enter the name of the second candidate:", you enter "Lisa Simpson"
• The program asks "How many votes did Bart Simposon get?", you enter 10
• The program asks "How many votes did Lisa Simposon get?", you enter 12
• The program prints "The winner is Lisa Simpson!"

If it's a tie, print something like "Bart Simpson and Lisa Simpson got equal number of votes".

### Problem 3 (10 points): fix a mistake in the program

The following program converts percent values into letter grades (with the 10% scale, i.e. 90-100 is A, 80-89 is B, etc.). It works, but has mistakes in its logic so it gives wrong results for some inputs.
You may assume that the number entered is always between 0 and 100. There are no "plus" or "minus" grades, such as B-.

1. Give at least two examples of data for which it gives incorrect results, clearly explain why (list the specific comparisons that the data goes through in each example)
2. Fix the mistakes. You might want to change the comparison part quite a bit. Make your correct program very clear.
3. Test your program to make sure that it works correctly (try the inputs that were working in the wrong version to make sure that they still work). Write down what data you tested it with
4. What would be your advice on how to avoid similar mistakes in conditionals in the future?
``````
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
an INCORRECT program for converting from numeric
to letter grades for CSci 1001 problem set
Author: Elena Machkasova
-->
<html  xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>
Fix this program!
</title>
<body>
<h1>Converting to letter grades</h1>
<p>
<script type="text/javascript" language="javascript">
var numeric = window.prompt("Please enter your numeric grade: ", "");
numeric = parseFloat(numeric);

if (numeric > 90) {
} else if (numeric < 80)  {
} else if (numeric < 70)  {
} else if (numeric < 60)  {
} else {
}

</script>
</p>
</body>
</html>
``````

### Problem 4 (4 points): real-life algorithms

Ex. 11 p. 154. Include a printout, a photocopy, or a scan of each of the two algorithms, mark parts of it that you think are unclear and parts that you think are clear, briefly explain why.

### How to submit

Send all of your program files to me by e-mail. You may submit the written part (if any) in class or send it together with your problem set. Please send only ONE e-mail with your entire submission, make sure you include everything. Multiple e-mails with your homework may result in a lower grade.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.