This is for C++: Create a function called strMetric that will produce some metri
ID: 3719776 • Letter: T
Question
This is for C++:
Create a function called strMetric that will produce some metrics about a string. Your function should produce the following metrics: Number of digits in a string Number of vowels a string Your function needs to take the string to compute the metrics on and two int variables passed by reference to hold the count of each of the two metrics. Your function should take input and produce output. This means you should not have any console in or console out statements within the strMetric function. Required: For this problem you are also to create a function called isVowel that checks to see if a character is a vowel or not. This function should work like isdigit (see below). You are also required to use this funciton to compute the metric for the number of vowels in the string. HINT: Think about using the isdigit function. It returns a bool value to indicate if a character is a digit or not char ch = '4'; bool status = isdigit(ch); // status will now have a value of true because ch is a digit character
Explanation / Answer
Please find my code.
#include <iostream>
#include<cstring>
#include<cctype>
using namespace std;
void strMetric(char[],int*,int*);
bool isVowel(char);
int main()
{
char str[50];
int digCount=0,vowCount=0;
cout<<"Enter the String ";
cin>>str;
strMetric(str,&digCount,&vowCount);
cout<<"String: "<<str<<" Digit Count: "<<digCount<<" Vowel Count: "<<vowCount<<endl;
return 0;
}
void strMetric(char a[] , int *d , int *v){
int len = strlen(a),i=0;
char ch;
for(i=0;i<len;i++){
ch = a[i];
if(isdigit(ch)){
*d +=1 ;
}
else if(isVowel(ch)){
*v += 1;
}
}
}
bool isVowel(char c){
if(c=='a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U'){
return true;
}
return false;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.