akosiraff

Phone Dial C# 2010

Mar 28th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. Download: http://solutionzip.com/downloads/phone-dial-c-2010/
  2.  
  3. Step 1: Requirements – Phone Dialing Program
  4. Your mission: A prepaid phone service needs a program that converts alphanumeric keyboard input into a phone number. The user will input eight characters and the program will output either an error message or the translated seven-digit phone number. The input may contain digits, letters, or both. Letters can be uppercase or lowercase.
  5. The program will perform the conversion per a standard telephone keypad layout.
  6. 0
  7. 5
  8. J K L
  9. 1
  10. 6
  11. M N O
  12. 2
  13. A B C
  14. 7
  15. P Q R S
  16. 3
  17. D E F
  18. 8
  19. T U V
  20. 4
  21. G H I
  22. 9
  23. W X Y Z
  24. The program implements the following methods.
  25. Main(): Declares seven character variables and passes these to the following methods by reference:
  26. ProcessInput(): gets user input and performs the conversion
  27. ShowResults(): displays the results
  28. GetInput(): Gets seven characters from the user and stores them into the seven variables Main() has passed by reference.
  29. ProcessInput(): Calls ToDigit() for each, passing each character variable by reference, and returns one of these codes to Main() by value:
  30. 0 if there were no input errors
  31. -1 if there were input errors
  32. Input errors include the following:
  33. The first character is 0 (seven-digit phone numbers can’t start with 0).
  34. The first three characters are “555″ (no phone numbers start with 555).
  35. Any character is not a digit or an uppercase or lowercase letter.
  36. ToDigit(): Converts a character (passed by reference) to its corresponding digit per the table above, and returns one of these codes to ProcessInput() by value:
  37. 0 if the character is valid (a digit or uppercase or lowercase letter)
  38. -1 if the character is not valid
  39. ShowResults(): Writes converted telephone number to the screen, inserting a dash (-) between the third and fourth digits, and accepts the seven character variables from Main() by reference.
  40. Sample Output:
  41. Enter a 7 character phone number: 2132121
  42. The converted phone number is: 213-2121
  43. Enter a 7 character phone number: 2scdfER
  44. The converted phone number is: 272-3337
  45. Enter a 7 character phone number: 555resw
  46. Invalid input, please try again.
  47. Enter a 7 character phone number: 0988765
  48. Invalid input, please try again.
  49. Enter a 7 character phone number: 12345678
  50. Invalid input, please try again.
  51. Enter a 7 character phone number: @34*uy
  52. Invalid input, please try again.
  53. Tips
  54. Best practice: Don’t try to write too much at a time! First, write an outline in comments based on the requirements and the pseudocode. Then, implement declaring seven char variables. Make sure to fix any compiler errors before implementing more. Then, write and call an empty GetInput() method that accepts parameters, but does nothing but return a dummy value. Make sure you can pass the seven character variables by reference without compiler errors before implementing any of the GetInput() logic. Keep working incrementally like this, testing as you go. Set breakpoints and use the debugger at each phase to make sure your logic is working correctly. Then, use the same approach to implement the other methods. Test each phase with valid input before handling any invalid conditions.
  55. Pseudocode
  56. ProcessInput( ) Method
  57. Get 7 characters from the user and store them in the 7 variables that Main() has passed by reference
  58. Call ToDigit() for each of the 7 characters
  59. If toDigit returns an error code (-1), return an error code (-1)
  60. If the first character is 0, return an error code (-1) to Main()
  61. If the first three characters are 555, return an error code (-1)
  62. If there are no errors, return 0
  63. ToDigit ( ) Method
  64. Convert the characters (passed from ProcessInput() by reference) to upper case
  65. Use a switch statement to translate characters into their corresponding digits.
  66. Write a case statement for each digit and for each valid uppercase letter
  67. Write a default case that returns an error code (-1) for invalid letters
  68. If there are no invalid letters, return 0
  69. ShowResults ( ) Method
  70. Display the Phone Number using the character variables Main() has passed by reference
  71. Main() Method
  72. Declare 7 char variables
  73. Get user input by calling the GetInput() method, passing it the 7 variables by reference
  74. Perform the conversion by calling the ProcessInput( ) method, passing it the 7 variables by reference
  75. Display an error message or call ShowResults(), depending on the code ProcessInput() returns
  76.  
  77. Download: http://solutionzip.com/downloads/phone-dial-c-2010/
Advertisement
Add Comment
Please, Sign In to add comment