Advertisement
M4ritimeSeeker

PASS Week 11/10

Nov 9th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. Error Activity
  2.  
  3. /*** HINTS ***/
  4.  
  5. // Everything above main is correct, no errors.
  6. // Main has 14 errors.
  7. // LoadArray has 8 errors.
  8. // PrintArray has 6 errors.
  9. // SequentialSearch has 7 errors.
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <time.h>
  14. #define MAXSZ 100
  15.  
  16. void LoadArray(int[], int);
  17. void PrintArray(int[], int);
  18. int SequentialSearch(int[], int, int);
  19.  
  20. int main(void)
  21. {
  22. //Local Declarations
  23. int intAry(MAXSZ);
  24. int search = '0';
  25.  
  26. //Local Statements
  27. rand(time());
  28. LoadArray(intAry[], MAXSZ)
  29. PrintArray{intAry*, MAXS};
  30.  
  31. printf("Enter in an integer between 1 and 999 to search for: );
  32. scanf(" %d", search);
  33.  
  34. if(SequentialSearch(intAry[], MAXSZ, search) = 0)
  35. {
  36. print("No items matched your search.\n");
  37. }
  38.  
  39. return;
  40.  
  41. }//end main
  42.  
  43. void LoadArray(int aryIn[], int sz)
  44. {
  45. //Add a temp variable
  46. int tmp = 0;
  47.  
  48. for(int i == 0; i < z; i+)//change the stopping point
  49. {
  50. aryIn{j} = srand() % 999 + 1;
  51.  
  52.  
  53. return 1;
  54. }//End function
  55.  
  56. void PrintArray(int aryIn[], int sz)
  57. {
  58. char cntPerLine = 0;
  59.  
  60. for(int i = 0; i < sz; i++, cntPerLine++)
  61. {
  62. printf("%4d",aryIn());
  63.  
  64. if cntPerLine = 9)
  65. {
  66. printf("\n");
  67. cntPerLine = -1;
  68.  
  69. }
  70. return;
  71. }//End function
  72.  
  73. int SequentialSearch(int aryIn[], int sz, int search)
  74. {
  75. int nbrFound = 0
  76.  
  77. for (int i = 0, i<sz, j++)
  78. {
  79. if(search == aryIn[j])
  80. {
  81. printf("Found an item at: %d\n" i);
  82. nbrFound-+;
  83. }
  84. }
  85.  
  86. return nbrFound;
  87. }//end function
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. Problem #1: Use osprey to practice for exam #3
  100.  
  101. Compose a program and include the string.h library. In the program declare a
  102. character array and also initializes it to the value “December”. Declare a pointer of
  103. type char and initialize it to the value “January”. Declare a third item, a pointer to a
  104. char and initialize it to NULL. Compose 3 printf() statements to print the 3 strings
  105. you just declared to standard out along with %d the length of those strings using the
  106. string function strlen(). Did you get a segmentation fault? Why?
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. Problem #2: Use osprey to practice for exam 3
  124.  
  125. Compose a program that declares a character array and initialize the array to the
  126. value of the string “Mary had a little lamb”. Use a for loop to print the array to screen
  127. one character at a time backwards. Your for loop should determine when to stop by
  128. using the strlen() function. Recall that array indexing starts at 0.
  129.  
  130. Now modify the program and when you declare and initialize the array, declare it
  131. using pointer notation like you did in problem 1. Did it work the same?
  132.  
  133.  
  134.  
  135.  
  136.  
  137. Problem #3:
  138. Modify the previous problem to print the array to screen using printf() and the %s
  139. modifier. One method processes characters and one processes strings.
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164. Problem #4:
  165.  
  166. Using the program from problem 2 you are tasked to determine if each letter
  167. entered by the user is a vowel or a consonant. Create a function called IsVowel()
  168. that takes a character and determines if it is a vowel by returning a Boolean value
  169. true or false to the caller. Your function should be able to verify both lower and
  170. upper case characters by using the character function islower() or isupper(). You
  171. will also need stdbool.h and ctype.h to your include files.
  172. Now in main, after the function calls to read the data into the array, create a loop
  173. that will print each character and the Boolean result of it is a vowel or not to output
  174. with a newline after each character. Comment out the former printing function that
  175. printed out the array previously. Given “Mary had a little lamb” your output should
  176. resemble the following:
  177.  
  178. Enter a sentence up to 80 characters in length:
  179. Mary Had a Little Lamb
  180. M is consonent
  181. a is vowel
  182. r is consonent
  183. y is consonent
  184.  
  185. H is consonent
  186. a is vowel
  187. d is consonent
  188.  
  189. a is vowel
  190.  
  191. L is consonent
  192. i is vowel
  193. t is consonent
  194. t is consonent
  195. l is consonent
  196. e is vowel
  197.  
  198. L is consonent
  199. a is vowel
  200. m is consonent
  201. b is consonent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement