Question

In: Computer Science

Design an algorithm that will read an array of 200 characters and display to the screen...

Design an algorithm that will read an array of 200 characters and display to the screen a count of the occurrences of each of the five vowels (a, e, i, o, u) in the array. Your string is: The quick brown fox jumped over the lazy dog

That is the question for my pseudo code question, I don't know if I have this correct can i have someone look this over and finish this and explain what i needed to add and or what i needed to change! Thank you.

Array Processing Challenge

MODULE Array_processing_challenge

Set total_a, total_e, total_i, total_o, total_u to zero

DO loop_index = 1 TO 200

IF characters (loop_index) = "a" or "A" THEN
add 1 total_a
ELSE
IF characters (loop_index) = "e" or "E" THEN
add 1 total_e
ELSE
IF characters (loop_index) = "i" or "I" THEN
add 1 total_i
ELSE
IF characters (loop_index) = "o" or "O" THEN
add 1 total_o
ELSE
IF characters(loop_index) = "u" or "U" THEN
add 1 total_a

ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDDO

Print "Total occurrences of a: ", total_a
Print "Total occurrences of a: ", total_e
Print "Total occurrences of a: ", total_i
Print "Total occurrences of a: ", total_o
Print "Total occurrences of a: ", total_u

END Array_processing_challenge

Solutions

Expert Solution

Solution :

In your psedo code there are 2 mistakes

1. Iterate the loop till the length of the array not to 200 ( Because if your array contain only 50 characters then there is wastaage of time and memory for that by iterating it to 200 times)

2. Inside the loop you have to increment the value of loop_index  so that it will point to next character in the array so add (loop_index =loop_index+1 inside do loop ). If you don't increment the value of loop_index then every time your program check condition for the first character only.

Algorithm :

Below is the coreect algorithm for processing the array

Array_processing( a){

total_a=0, total_e=0, total_i=0, total_o=0, total_u =0

//initializing index value to zero

index=0

len=sizeOf(a) //using the length of the array for the number of iteration

while(index<len) //we have to iterate till the length of the array

{

if(charAt(index)=='a' or charAt(index)=='A')

{

total_a=total_a+1  

//closing the if 'a' condition

}

else if(charAt(index)=='e' or charAt(index)=='E')

{

total_e=total_e+1  

//closing the if 'e' condition

}

else if(charAt(index)=='i' or charAt(index)=='I')

//closing the if 'i condition

{

total_i=total_i+1  

}

else if(charAt(index)=='O' or charAt(index)=='O')

{

total_o=total_o+1  

//closing the if 'o' condition

}

else if(charAt(index)=='U' or charAt(index)=='U')

{

total_u=totalu+1  

//closing the if 'u' condition

}

index=index+1; //incrementing the value of index each time till we iterate

}

} //end of while loop

Print "Total occurrences of a: ", total_a
Print "Total occurrences of a: ", total_e
Print "Total occurrences of a: ", total_i
Print "Total occurrences of a: ", total_o
Print "Total occurrences of a: ", total_u


Related Solutions

in java Read in a word and display the requested characters from that word in the...
in java Read in a word and display the requested characters from that word in the requested format. Write a Java program that ● prompts the user for a word and reads it, ● converts all characters of the input word to uppercase and display the word with a double quotation mark ( " ) at the start and end of the word, ● displays the word with all characters whose index is odd in lower case and for the...
Problem: Read in a word and display the requested characters from that word in the requested...
Problem: Read in a word and display the requested characters from that word in the requested format. Write a Java program that ● prompts the user for a word and reads it, ● converts all characters of the input word to uppercase and displays every other character starting from the 1st one, ● converts all characters of the input word to lowercase and displays every other character in reverse order starting from the last character, ● finally displays the original...
1. Read 20 integers into an array. Next, use the unique algorithm to reduce the array...
1. Read 20 integers into an array. Next, use the unique algorithm to reduce the array to the unique values entered by the user. Use the copy algorithm to display the unique values. 2. Modify the Exercise 1 above to use the unique_copy algorith. The unique values should be inserted into a vector that's initially empty. Use a back_inserter to enable the vector to grow as new items are added. Use the copy algorithm to display the unique values.
Design and implement a C++ program read in a whole line of characters as the input...
Design and implement a C++ program read in a whole line of characters as the input string; count and display how many times how frequently (among the letters) each (case insensitive) letter appears in the above mentioned input string; Sample program execution: An example of executing such a program is shown below. Note that the user input is in italic font. Please enter a line of characters: This is a really long line of characters! There are 41 characters in...
Need to read a PPM image using a 3D array and display it in a swing Jpanel.
Need to read a PPM image using a 3D array and display it in a swing Jpanel. 
Let A be an integer array of length n. Design a divide and conquer algorithm (description...
Let A be an integer array of length n. Design a divide and conquer algorithm (description and pseudo code) to find the index of an element of the minimum value in the array. If there are several such elements, your algorithm must return the index of the rightmost element. For instance, if A = {0,2,4,5,2,0,3,10}, then the algorithm should return 5, which is the index of the second 0.
5. Design a dynamic programming algorithm to solve the following problem. Input: An array A[1, ....
5. Design a dynamic programming algorithm to solve the following problem. Input: An array A[1, . . . , n] of positive integers, an integer K. Decide: Are there integers in A such that their sum is K. (Return T RUE or F ALSE) Example: The answer is TRUE for the array A = [1, 2, 3] and 5, since 2 + 3 = 5. The answer is FALSE for A = [2, 3, 4] and 8. Note that you...
Java Programm please! Design and implement an algorithm using recursion and backtracking to sort an array...
Java Programm please! Design and implement an algorithm using recursion and backtracking to sort an array of integers into ascending order. Consider the given array as input and produce a sorted array as output. Each time you take an integer from the input array, place it at the end of the output array. If the result is unsorted, backtrack.
6. Given the following array of characters: REALITYSHOWShow how this array will be sorted with the...
6. Given the following array of characters: REALITYSHOWShow how this array will be sorted with the help of : (a) insertion sort; (b) selection sort; (c) bubble sort with swaps counting; (d) bubble sort without swaps counting subject design and analysis of algorithms answer should be like eg p u r p l e p r u p l e
I have to write an initial algorithm and a refined algorithm for the following problem: Display...
I have to write an initial algorithm and a refined algorithm for the following problem: Display the square of numbers from 0 to some user inputted value. For example if the user enters 3 then the program will need to display the square of 0, 1, 2 and 3. Must use a counter loop. Must use 2 methods. One method that gets the number from the user and returns it. A second method is passed that number as a parameter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT