Download Evaluation form

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Addition wikipedia , lookup

Large numbers wikipedia , lookup

Strähle construction wikipedia , lookup

Elementary mathematics wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Line (geometry) wikipedia , lookup

Transcript
MIDTERM 2: In-Class Programming Exam: Time: 3 hours.
OPEN BOOKS, NOTES, CALCULATORS, PROGRAMS and OPEN INTERNET
DO NOT TALK OR COMMUNICATE TO YOUR FRIENDS.
CLASSMATE EMAIL IS FORBIDDEN.
I am very suspicious if any email window is open. In this case you will receive a grade F for this exam.
AS SOON AS YOU FINISH a program, please call your instructor for a demonstration, and then submit
your diskette. THEN YOU CONTINUE TO THE NEXT PROGRAM.
Question 1:
Part 1. Print the first fifteen even numbers starting from 11. Then find their sum.
You should not use any other information other than the numbers given in the problem.
Your program must be general enough for any number rather than fifteen and for any starting rather than
11.
Worth: 10 points:
Bonus: 1 point: Print the first n even numbers starting from k; then find their sum, where n and k are
two given numbers given via keyboard.
Show your work before you proceed to the next part of the question.
Part 2. Someone just show you the following steps of observation:
Step 1: list the sequence
12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
Step 2: list the sequence in the reverse order
40 38 36 34 32 30 28 26 24 22 20 18 16 14 12
Step 3: If you add column by column you do get a constant value--52
Step 4: Hence the sum of the sequence is
(First number in the sequence + last number of sequence) * 15/2
Do you believe this formula? Justify your answer. (2points)
Use this formula in your program instead of doing a do loop in Part 1. (8 points.)
Show your work when you finish.
Question 2:
A company decides to raise salary of its employees for the next fiscal year. The formula is
full-time: raise is 5.3% if income is greater than 70K,
7.5 % if below or equal to 70K but greater than 50K,
10.4% if below or equal to 50K.
part time: raise will be less than full timers .82% in all ranges.
 (10 points)You are asked to calculate the raise for each employee when the current salary
is given.
 Bonus: 1 point if input is fed multiple times without re-execute the program. Program is
terminated when a special character is the enter key.
 Bonus: 1 point if the output is rounded off up to cents.
Question 3:
Solve the problem of translating a positive integer into a word equivalent. For example: the word
equivalent of 255 is “two hundred fifty five.”
1. You need to submit documentation. (10 points)
2. The source code: 10 points.
3. Bonus: 1 point: do not print “zero” in the word equivalent except for the number 0.
Question 4: A point in a 2-dimensional vector space is defined as a pair of floating-point numbers. It is
written in the form
(a , b)
where a and b are two floating point numbers.
 Write a code to define this set. ( hint: it is a class)
 The origin ( 0 , 0) is a default number. So, generate its constructor.

Also, generate a general constructor for any point (a, b) where a and b are given numbers
provided by users or by other classes (callers).
 Write a method to print out any point.
 Two vectors can be added by the formula: (a1, b1) + (a2, b2) = (a1+a2 , b1+b2). Write a
method to perform this addition.
Worth: 2 points for each sub-question.
Question 5: A floppy diskette is divided into 16 sectors (like 16 pieces of a pie). They are labeled
consecutively clockwise from 0 to 15. If a file is stored into a diskette, it is stored on multiple sectors.
However, these sectors are not selected consecutively; instead they are selected in a pattern. For example,
if the sector 5 is the initial selected sector, the skip-one pattern is 5 7 9 11 13 15 1 3 5. Similarly the skiptwo pattern with initial sector 3 would be 3 6 9 12 15 2 5 8 …
 Design a solution to print a pattern of arbitrarily number of skips with an initial sector. (10
points)
 Write a Java program based on your design. (10 points)
 Bonus: (3 points) modify the program to access sector counter-clockwise.
Question 6:
1. (4 points). You are asked to represent a set of 1-dimentional arrays of strings. That means each
member is an array of strings. (Hint: a class in Java.)
2. (4 points)Write code to create an array of null strings. (Hint: it is a default constructor.) (4 points.)
3. (4 points). Implement the following operation on the members: (Hint: a method)
push:
 This operator will insert a given string into the next available space in the array.
 If we define currentIndex as the index of the recent-used space in the array, then
insert will save a given string to the array at the space with the index currentIndex
+1. Moreover the currentIndex is set to currentIndex+1.
currentIndex  currentIndex +1
<arrayName>[currentIndex]  the given string

4.
5.
6.
The currentIndex should be initialized -1 when the array is null (initial array without
any insertion.
(4 points). Implement the following operation on the members: (Hint: a method)
pop:
 This operator will move a string at currentIndex out.

I remind you that we define currentIndex as the index of the recent-used space in
the array.
The popped string  <arrayName>[currentIndex]
currentIndex  currentIndex -1
 Of course, if the currentIndex is -1, there is nothing to pop.
(4 points). You must write another class with a main method to test Question 6.1. to 6.4. by
printing the array after each operation.
Bonus 1 point: What is the scientific name of a member in this class?
Question 7: An instructor needs a Java program for computing exam statistics. The relevant formulas are
average, standard deviation, minimum and maximum of values, and median score.:
Average = total of all values/count of values,
Standard Deviation = square root (sum of squares of values/ count of values - square of average)


Write a Java program to calculate these above statistics scores. (4points for each formula)
Bonus: (2 points): to include reading the scores via keyboard as a string.
Name:______________________________
Midterm 2
Nov 11, 1999
Comp 110/L
Evaluation form
Question 1:
Part 1.
 Worth: 10 points
 Bonus: 1 point: Print the first n even numbers starting from k; then find their sum, where n
and k are two given numbers given via keyboard.
 Comment:
Part 2.
Do you believe this formula? Justify your answer. (2points)
Use this formula in your program instead of doing a do loop in Part 1. (8 points.)
Show your work when you finish.
Comment:
Question 2:
 (10 points)You are asked to calculate the raise for each employee when the current salary is given.
 Bonus: 1 point if input is fed multiple times without re-execute the program. Program is
terminated when a special character is the enter key.
 Bonus: 1 point if the output is rounded off up to cents.
 Comment:
Question 3:
 You need to submit documentation. (10 points)
 The source code: 10 points.
 Bonus: 1 point: do not print “zero” in the word equivalent except for the number 0.
 Comment:
Question 4:
 Write a code to define this set. ( hint: it is a class)
 The origin ( 0 , 0) is a default number. So, generate its constructor.
 Also, generate a general constructor for any point (a, b) where a and b are given numbers
provided by users or by other classes (callers).
 Write a method to print out any point.
 Two vectors can be added by the formula: (a1, b1) + (a2, b2) = (a1+a2 , b1+b2). Write a method
to perform this addition.
Worth: 2 points for each sub-question.

Comment:
Question 5
 Design a solution to print a pattern of arbitrarily number of skips with an initial sector. (10
points)
 Write a Java program based on your design. (10 points)
 Bonus: (3 points) modify the program to access sector counter-clockwise.
 Comment:
Question 6:
1. (4 points). You are asked to represent a set of 1-dimentional arrays of strings. That means each
member is an array of strings. (Hint: a class in Java.)
2. (4 points)Write code to create an array of null strings. (Hint: it is a default constructor.) (4 points.)
3. (4 points). Implement the following operation on the members: (Hint: a method): push.
4. (4 points). Implement the following operation on the members: (Hint: a method): pop.
5. (4 points). Implement (4 points). You must write another class with a main method to test a) b) c)
and d) by printing the array after each operation.
6. Bonus 1 point: What is the scientific name of a member in this class?
Comment:
Question 7: average, standard deviation, minimum and maximum of values, and median score:
 Write a Java program to calculate these above statistics scores. (4points for each formula)
 Bonus: (2 points): to include reading the scores via keyboard as a string.
Comment: