$\textstyle \parbox{1.5in}{CS1320}$ $\textstyle \parbox{3in}{\Large CS1320 Homework~4}$ $\textstyle \parbox{1.5in}{23~Sep 1999}$


Due Thursday, 30 Sep 1999, at the beginning of class.

Reading

Read Section 9.1 of the text and then read Chapter 3.

Problems

When submitting a program, please submit a printed copy of the program's code prepended with comments briefly describing its input and output. Please indent your code to make it readable. See Section 2.5 of the textbook for style hints. If you desire, you can also submit examples demonstrating your program's correctness.

1.
In class we developed an algorithm for converting non-negative integers to binary representation. Write a C++ program based on this algorithm. Input to the program will be a non-negative decimal integer X. Output will be the binary representation of X. For example, an input of ``5'' will yield ``101,'' and an input of ``25'' will yield ``11001.''

2.
Write a program to compute the exponentiation function BE (B to the Eth power), where B is any number and E is an integer. Remember that B0 is 1 for all B, and B-E = $ {\frac{1}{B^E}}$.

Examples:
input output
3.0 0 1
2 3 8
2 -2 0.25

3.
Write a program to find and print all text strings of the following form: 2 letters, 1 number, another letter, and then the first two letters again. ``ab3cab'' and ``aa1baa'' would be included; ``abcdef'' and ``ab4cde'' would not be included. Assume the letters are in lowercase.

To solve this problem, it may be useful to know that each character is represented inside the computer as a small integer. For example, try the following lines of code:


int x = 'a'; 
cout << x << endl;
One should be very careful about treating characters as integers since the same character may be represented using different numbers on different computers. However, it is fairly safe to write a loop to print all the lowercase characters a, b, ..., z as


char c = 'a'; 
while (c <= 'z') { 
  cout << c << endl; 
  c += 1; 
}

4.
Write a simple currency-conversion program. Currencies will be represented as single letters. The input should consist of two parts: Output should consist of: Hints:




1999-09-22