CS 110: Assignment 1

Summer 2008

Due Date and Time: Tuesday, July 15th, 2008 at 8:00 am

Important: Be sure to include appropriate comments in your code, choose meaningful identifiers, and use indentation as done in the programs in the textbook and in the class notes.
  1. (15 mks) Suppose a, b and c denote the lengths of the sides of a triangle. Then the area of the triangle can be calculated using the formula:
formula,

where s=(1/2)(a+b+c). Design an algorithm that uses this formula to find the area of a triangle. Write a program to implement and test the algorithm that you designed. Test your program with the following values:

  1. (15 mks) Write a program that prompts the user to input a six-digit positive integer. The program then outputs the digits of the number, one digit per line. For example, if the input is 123456, the output is:
1
2
3
4
5
6


Test your program with the following inputs: 987145, 450102, 600000.


  1. (15 mks) Write a program that prompts the user to input a length expressed in centimeters. The program should then convert the length to inches (to the nearest inch) and output the length expressed in yards, feet, and inches, in that order. For example, suppose the input for centimeters is 312. To the nearest inch, 312 centimeters is equal to 123 inches. 123 inches would thus be output as:
3 yard(s), 1 feet (foot), and 3 inch (es).

It should not be output as:

2 yard(s), 4 feet (foot) 3 inch (es).

Use the following conversion information:

1 inch = 2.54 centimeters
1 foot = 12 inches

1 yard = 36 inches

Test your program with the following inputs: 407, 1387, 76, 28, 8961



    Bonus (10 mks)

A permutation of three objects, a, b, and c, is any arrangement of these objects in a row. For example, some of the permutations of these objects are abc, bca, and cab. The number of permutations of three objects is 6. Suppose that these objects are strings. Write a program that prompts the user to enter three strings. The program then outputs the six permutations of those strings.

Test your program with the following input strings:


  1. "Hello"
"Goodbye"

"Goodnight"

  1. "Hello There"
"How are you?"

"I am good"