< previous page page_249 next page >

Page 249
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
    info.open(indata.data);
    info >> m >> n;
    cout << The sum of  < m < and < n
         < is < m+n << endl;
return 0;
}
Programming Problems
1. Using a top-down design, write a C++ program that inputs a single letter and prints out the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
2=ABC 4=GHI 6=MNO 8=TUV
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
3=DEF 5=JKL 7=PRS 9=WXY
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
No digit corresponds to either Q or Z. For these two letters, your program should print a message indicating that they are not used on a telephone.
The program might operate like this:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Enter a single letter, and I will tell you what the corresponding digit is on the telephone.
R
The digit 7 corresponds to the letter R on the telephone.
Here's another example:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Enter a single letter, and I will tell you what the corresponding digit is on the telephone.
Q
There is no digit on the telephone that corresponds to Q.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Your program should print a message indicating that there is no matching digit for any nonalphabetic character the user enters. Also, the program should recognize only uppercase letters. Include the lowercase letters with the invalid characters.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Prompt the user with an informative message for the input value, as shown above. The program should echo-print the input letter as part of the output.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Use proper indentation, appropriate comments, and meaningful identifiers throughout the program.
2. People who deal with historical dates use a number called the Julian day to calculate the number of days between two events. The Julian day is the number of days that have elapsed since January 1, 4713 B.C. For example, the Julian day for October 16, 1956, is 2435763. There are formulas for computing the Julian Day from a given date and vice versa.

 
< previous page page_249 next page >