10/12/09 – Problem 1

10/16/2009

Write a program to time an event. Prompt the user to enter the starting hour. Prompt the user again to enter the number of hours that have elapsed. Write out what the time will be.

  Enter starting hour: 11
  Enter duration of event in hours: 53

  At the end of the event the hour hand will show: 4

Class Solution

10/02/09 – Program I

10/02/2009

Problem:

Mr. Statos’s 5th grade class has just finished learning multiplication and division by 12. You want to write a program that will generate quizzes for his students that will test all four arithmetic operations – addition, subtraction, multiplication, and division.

The quiz will have 50 questions. The questions will involve the four arithmetic operations randomly. You will also generate two operands. The requirements for the operands are as follows:

  • Addition: Both operands are positive two digit numbers.
  • Subtraction: Both operands are positive two digit numbers. Arrange the subtraction so that the user is subtracting the smaller number from the bigger number.
  • Multiplication: Both operands are positive numbers in the range 0 through 12, both numbers inclusive.
  • Division: The dividend (numerator) will be a positive two digit number. The divisor (denominator) will be a number in the range 1 through 12, both numbers inclusive. For division, we are interested only in the quotient and not in the remainder.

Your program will number each question that it prints out. It will read the answer the user inputs. If the answer is wrong, it will print the correct answer. The program will keep a tally of how many questions the user gets correct. It will print the total score at the end.

If the user gets 46 to 50 questions correct, your program will print Great Job. If the user gets 40 to 45 questions correct, your program will print Good Attempt. If the user gets less than 40 questions correct, your program will print Better effort next time.

Your program should also give the user the option of trying another quiz. If the user decides on another quiz, then a fresh quiz is generated. If the user decides to quit, then the program thanks the user for taking the quiz.

My Solution

This is probably not the most efficient solution. You should try to write a better solution.

09/30/09 – Function I

10/02/2009

Problem:

Write a function that accepts as input the points received on a test and returns the letter grade. Letter grades are assigned as follows:

  • 90 and above: A
  • Between 80 and 89: B
  • Between 70 and 79: C
  • Between 60 and 69: D
  • Less than 60: F

Solution

Bubble Sort

10/01/2009

This is a bubble sort (very slow sorting algorithm. Has an average run time of O(n^2) [for those of you that know what that means])

Here it is!

(Note: This is taken from my class that contained a large variety of sorting algorithms. The swap function is a useful snippet for many of these comparison sorts, so I split it into a separate function. You don’t have to leave it that way if you don’t want to.)

Just for fun, How does this algorithm work? I would prefer you not cheat and look it up, but I can’t stop you now, can I?

09/21/09 – Challenge

09/25/2009

Problem:

A software engineer lived on a street that was numbered linearly starting at 1. She had a dog that she used to take out for walks. In the morning she would walk in one direction and in the evening she would walk in the opposite direction. On one of her walks she summed the house numbers in that direction and compared it to the sum of the house numbers in the other direction (not including her house number). To her amazemment she found that the two sums were the same. This was a unique feature of her house and she felt that she lived in a lucky house. So when she moved to another city, she asked her realtor to find her a house with exactly that same feature, i.e. the sum of house numbers on one side is equal to sum of the house numbers on the other side. Your task is to write a program that will help the real estate agent find pairs of numbers (the lucky house and the last house on the street). Assume that there cannot be more than 10,000 houses on a given street. The first set of numbers that have this property is 6 and 8.

My Solution

Note: My solution to this problem seems to work as far as I can tell, but it is slow. See if you can optimize it.

09/21/09 – Program III (Palindromic Numbers)

09/25/2009

Problem:

Modify the program that we wrote to find the reverse of a number to find the only non-palindromic number whose cube is palindromic? [Hint: the number is a four-digit number.]

My Solution

09/21/09 – Program II (Perfect Numbers)

09/25/2009

Problem:

A perfect number is a number that is the sum of its divisors. The divisors of 6 are 1, 2, and 3 and they add up to 6 [1 + 2 + 3 = 6]. Another perfect number is 28. The divisors of 28 are 1, 2, 4, 7, 14 and they add up to 28. There are not many perfect numbers. Write a program that takes as input an integer number and determines if it is perfect or not.

My Solution

09/21/09 – Program I (Right Angled Triangle)

09/25/2009

Problem:

Prompt the user to enter 3 sides of a triangle. Assume that the sides are positive integers. Determine, if these sides form a right angled triangle. Apply Pythagoras’s Theorem: Square of the hypotenuse is equal to the sum of the squares of the other two sides. In this particular problem, any one of the three sides that the user enters could be the hypotenuse or none of the sides.

My Solution

09/18/09 – Program II

09/25/2009

Problem:

Prompt the user to enter the change to be returned in cents. Your program should then print out the minimum number of dollar bills, quarters, dimes, nickels, and pennies that are to be returned.

My Solution

09/18/09 – Program I

09/25/2009

Problem:

Prompt the user to enter 3 whole numbers. Print out the same numbers in ascending order (smallest to the largest).

My Solution


Follow

Get every new post delivered to your Inbox.