Confidential Teaching Materials:
Quiz 7 Grading Criteria
Note: To receive any credit whatsoever, the date, your name, your student number, and your answers must
be legible and readily readable in the judgment of the grader.
Add brief explanatory comments as necessary to make sure your answers are clear and unambiguous
to the grader.
You are hired to work for a phone company during the summer. They have asked you to write part of a class,
Phone_Card, that will keep track of a pre-paid calling card. Of the various modules required, you are
responsible for the following ones:
Make_Call: this module will take in the amount of time (in minutes) for a given call. Each call will cost $0.15 per
minute. Make_Call deducts the cost of the call from the card’s current value. For purposes of this quiz, you
are to assume that, when making a call, the user is prompted by the system to specify the length of call to me
made, verifying that there is enough value left on the calling card to pay for that call, and that the call lasts
exactly that predetermined length of time. Thus, a given call may exhaust the balance but will never achieve
a negative balance. The initial value of a Phone_Card is $25.
Buy_Time: this module will take in the amount of money the person has purchased and add it to his/her card.
Each minute purchased costs $0.15. The purchase value should be added to the card’s value.
Balance: this module will return the current amount of time left on the card
[p1] 30 points
Write the public section for the class described above. You must include necessary comments, including purpose,
pre- and post-conditions.
LINES=30
[c1] 30 points
Example solution (particulars may vary):
class Phone_Card
public
function Balance isoftype Num ()
Confidential Teaching Materials:
Quiz 7 Grading Criteria, Page 2 of 5
procedure Initialize ()
//purpose – initializes the object’s variables
//pre – None
//post – all variables are initialized to default values
30 points
NOTE: If they don’t have class <Name>, don’t take off points.
For the modules:
+2(x3) for purpose (PCN)
+2(x3) for pre (PPC)
+2(x3) for post (PPC)
For the procedures:
+1(x3) for making it a procedure(PRO)
+2(x3) for the parameter or lack thereof (UNP)
+1 for making it an in parameter(INP)
+1 for having it be of type num(NUM)
For the function:
+2 for making it a function(FUN)
+1 for having it return a num(NUM)
[p2] 30 points
Write the protected section for the class described in problem one. Be sure to include any variables, constants,
types, helper modules and initializations needed. For this problem, you do not need to include comments.
LINES=58
[c2] 30 points
Example solutions (particulars may vary):
protected
COST_PER_MIN is .15
current-value isoftype Num
Confidential Teaching Materials:
Quiz 7 Grading Criteria, Page 3 of 5
[p3] 30 points
Write an algorithm that will allow the customer to use his/her pre-paid calling card. The algorithm should provide
the customer with a menu of the following choices:
1) Make Call: When the customer chooses this option, they should be prompted for how long their call will be.
If the current value of their card is sufficient to handle the call, the cost of that call is to be subtracted from
their account. Remember, our premise is that there must be enough time left on the card before the call is
made. If there are insufficient funds for the length of call specified, the system should print an appropriate
message, then cycle back to the menu choices again.
2) Buy Time: When the customer chooses this option, they should be prompted for how much money they want
to add to their calling card. Then update their card accordingly.
3) Check Balance: When the customer chooses this option, the current balance (in minutes) of their card should
be printed.
4) Quit: Algorithm should terminate
After an option is chosen and the task accomplished, this menu should be redisplayed until the Quit option is
chosen.
LINES=40
Confidential Teaching Materials:
Quiz 7 Grading Criteria, Page 4 of 5
[c3] 30 points
Example solution (particulars may vary):
algorithm Using_The_Phone_Card
uses Phone_Card
Confidential Teaching Materials:
Quiz 7 Grading Criteria, Page 5 of 5
[p4] 10 points
Explain the difference between a linear and a binary search. Give an example where each type of search would be
appropriate.
[c4] 10 points
Example solution:
A linear search looks at each element of the data structure that it is searching starting at the