A325)Could you please help me to solve this problem? Problem: Write Standard ML
ID: 3580956 • Letter: A
Question
A325)Could you please help me to solve this problem?
Problem:
Write Standard ML function(s) to find the number of vowels and nonvowels in the strings sent as parameter in a list, and returns the strings and their count of vowels and nonvowels in a record list.
Sample Run:
-find([“good”,”luck”,”on”,”your”,”homework”]);
val it =
[{word="good",vowels=2,nonvowels=2},{ word="luck,vowels=1,nonvowels=3},
{ word="on",vowels=1,nonvowels=1},{ word="your",vowels=2,nonvowels=2 },
{ word="homework",vowels=3,nonvowels=5 }] : wrdrec list
Note:
Use the following list in your program to specify the vowels.
val vowels=[#”a”, #”e”, #”i”, #”o”, #”u”];
Use the explode function which changes a string to a char list.
- explode "abc";
val it = [#"a",#"b",#"c"] : char list
You can write as many functions as needed.
Do not forget to declare your types.
Explanation / Answer
var vowels=[a,e,i,o,u]
var words=[“good”,”luck”,”on”,”your”,”homework”]
var charc=[]
var i=0
while i<words.length
do
var vowel = 0
var nonVowels = 0
charc = [];
var word = words[i];
var j=0
while j<word.length
charc[j] = word.charAt(j);
j=j+1
var k=0
while k< vowels.length
do
if(charc[j] == vowels[k]) vowel = vowel + 1 else nonVowels = nonVowels + 1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.