M4ritimeSeeker

PASS Week 10: Arrays

Mar 28th, 2022
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. PROBLEM #1: Reversing Arrays (With TWO arrays)
  2.  
  3. Write a program that creates an array of 5 integer values {1, 2, 3, 4, 5}, and reverses it.
  4.  
  5. You will have about 4 loops total. One loop to fill the first array (Array A) with values,
  6. a second loop to print Array A, a third loop to fill the second array (Array B) with A's values backwards,
  7. and a fourth loop to print Array B.
  8.  
  9. SAMPLE OUTPUT
  10.  
  11. A: 1 2 3 4 5
  12. B: 5 4 3 2 1
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. PROBLEM #2: Creating a Login ID for a User
  34.  
  35. Write a program that asks user to enter in their first name, last name,
  36. and the last 4 digits of their social security number, and makes a custom User ID from them.
  37. Take the user's input and store it into 3 separate arrays. Use scanf() and the %s format specifier.
  38. ALSO MAKE SURE TO HAVE #include <string.h> AT THE TOP OF YOUR PROGRAM.
  39.  
  40. You will also create a fourth array to store the user ID itself. Here is the format:
  41. [First 3 letters of LAST name][First 2 letters of FIRST name][Last 4 digits of SSN]
  42.  
  43. Then print the login ID afterward.
  44.  
  45. ***IMPORTANT***
  46. As you can tell from the %s, this problem involves using strings. I (Justin) know that strings are in
  47. this week's module and not last week's, so you may have to consult the canvas module for strings to see
  48. how to take them as input. I don't know why this problem was here instead of next week ¯\_(ツ)_/¯
  49. HOWEVER, fortunately, you don't need to know strings forward and back to complete it.
  50. Once you get the two strings as input, you can just treat them as normal arrays. No bells and whistles attached.
  51.  
  52.  
  53. SAMPLE OUTPUT:
  54.  
  55. Enter in your first name: Justin
  56. Enter in your last name: Bentley
  57. Enter in the last 4 digits of your SSN: 1111
  58.  
  59. Unique User ID is BenJu1111
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. PROBLEM #3: Reversing Arrays (With ONE array)
  79.  
  80. Write a program that reverses an array without using a second array like problem #1.
  81. The array will contain ten integers {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  82.  
  83. The last element
  84. becomes the first, the second from last becomes second, and so forth. The purpose
  85. is to reverse the elements in place, i.e., without using a second array. You can use
  86. a variable to hold an element temporarily. Try it out with an array with an even number of
  87. elements and one with an odd amount of elements!
  88.  
  89. SAMPLE OUTPUT
  90.  
  91. Array before reversing: 1 2 3 4 5 6 7 8 9 10
  92. Array after reversing: 10 9 8 7 6 5 4 3 2 1
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. PROBLEM #4: Checking ISBN Numbers
  112.  
  113. The International Standard Book Number, ISBN, is used to uniquely identify a book.
  114. It is made of 10 digits. Write a function that tests an ISBN to see if it is valid.
  115.  
  116. For an ISBN number to be valid, the weighted sum of the 10 digits must be evenly divisible by 11.
  117.  
  118. To determine the weighted sum, the value of each position is multiplied by its
  119. relative position, starting from the right, and the sum of the product is determined.
  120. If (weighted sum) modulus 11 is 0, the ISBN number is valid.
  121.  
  122. Test your function with examples, use Amazon to get valid book ISBNs.
  123.  
  124. Example
  125. ISBN: 0-07-881809-5 (assume no dashes in your function)
  126.  
  127. Code * Weight = Value
  128. 0 10 0
  129. 0 9 0
  130. 7 8 56
  131. 8 7 56
  132. 8 6 48
  133. 1 5 5
  134. 8 4 32
  135. 0 3 0
  136. 9 2 18
  137. 5 1 5
  138.  
  139. Weighted Sum is 220
  140.  
  141. 220 % 11 = 0 (Valid ISBN)
  142.  
  143.  
  144.  
  145.  
  146. SAMPLE OUTPUT (ISBN is 0078818095)
  147.  
  148. Enter in 10 numbers one at a time: 0
  149. Enter in 10 numbers one at a time: 0
  150. Enter in 10 numbers one at a time: 7
  151. Enter in 10 numbers one at a time: 8
  152. Enter in 10 numbers one at a time: 8
  153. Enter in 10 numbers one at a time: 1
  154. Enter in 10 numbers one at a time: 8
  155. Enter in 10 numbers one at a time: 0
  156. Enter in 10 numbers one at a time: 9
  157. Enter in 10 numbers one at a time: 5
  158. Weighted Sum is: 220
  159. The ISBN is valid
  160.  
Advertisement
Add Comment
Please, Sign In to add comment