akosiraff

Download PrintLetters CPP

Dec 9th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/printletters-cpp/
  3. Use the program, Arrays of Pointers, on p. 188 of the text as a starting point for this assignment.
  4. (from page 188.):
  5. Arrays of Pointers
  6. With an array of pointers of type char , each element can point to an independent string, and the
  7. lengths of each of the strings can be different. You can declare an array of pointers in the same
  8. way that you declare a normal array. Let ’ s go straight to rewriting the previous example using
  9. a pointer array:
  10. // Ex4_07.cpp
  11. // Initializing pointers with strings
  12. #include
  13. using std::cin;
  14. using std::cout;
  15. using std::endl;
  16. int main()
  17. {
  18. char* pstr[] = { “Robert Redford”, // Initializing a pointer array
  19. “Hopalong Cassidy”,
  20. “Lassie”,
  21. “Slim Pickens”,
  22. “Boris Karloff”,
  23. “Oliver Hardy”
  24. };
  25. char* pstart(“Your lucky star is “);
  26. int dice(0);
  27. cout < < endl
  28. < < "Pick a lucky star!"
  29. < > dice;
  30. cout < = 1 & & dice < = 6) // Check input validity
  31. cout < < pstart < < pstr[dice - 1]; // Output star name
  32. else
  33. cout < < “Sorry, you haven’t got a lucky star.”; // Invalid input
  34. cout < < endl;
  35. return 0;
  36. }
  37. Now reference the following instructions to assist you when completing your Programming Using Arrays and Pointers assignment.
  38. • Using a for loop, print the contents of the array.
  39. The output should appear like this:
  40. PRINTING CONTENTS OF ARRAY
  41. ==================================
  42. A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  43. • Change the program logic to prompt you for a position within the array that coincides with the letter. See the example below:
  44. This is the title to your Program related to the alphabet.
  45. Select the number that coincides with the alphabet.
  46. For example, the number 7 should display the letter G.
  47. Enter a number between 1 and 26: 4
  48. The number you selected: 4
  49. The letter related to this number: D
  50. • Then, write the code to update every other element within the array with a lowercase x. The output should appear like the following:
  51. PRINTING CONTENTS OF ARRAY and adding x to every other element
  52. A x C x E x G x I x K x M x O x Q x S x U x W x Y x
  53. • Write the code that will display only the even or odd numbered elements within the array. The output should appear as follows:
  54. PRINTING CONTENTS OF ARRAY USING THE MOD Option
  55. =====================================================
  56. Even Numbered Element = 0 Contents of Element within Array is = A
  57. Even Numbered Element = 2 Contents of Element within Array is = C
  58. Even Numbered Element = 4 Contents of Element within Array is = E
  59. Even Numbered Element = 6 Contents of Element within Array is = G
  60. Even Numbered Element = 8 Contents of Element within Array is = I
  61. Even Numbered Element = 10 Contents of Element within Array is = K
  62. Even Numbered Element = 12 Contents of Element within Array is = M
  63. Even Numbered Element = 14 Contents of Element within Array is = O
  64. Even Numbered Element = 16 Contents of Element within Array is = Q
  65. Even Numbered Element = 18 Contents of Element within Array is = S
  66. Even Numbered Element = 20 Contents of Element within Array is = U
  67. Even Numbered Element = 22 Contents of Element within Array is = W
  68. Even Numbered Element = 24 Contents of Element within Array is = Y
  69. Download: http://solutionzip.com/downloads/printletters-cpp/
Add Comment
Please, Sign In to add comment