C++问题求原音和辅音字母问题

来源:百度知道 编辑:UC知道 时间:2024/08/24 08:27:55
给定一个字符串,求解给定的字符串中元音和辅音的个数,要求用函数实现,求元音函数int isVolel(string src)。求辅音函数 int isConsonant(string src),两个函数的返回值分别表示src中元音和辅音的个数。要求实现对两个函数的调用,调用用的实参数为你的姓名的拼音+学号,如:袁晓的学号为730103149,则调用实参数为:yuanxiao730103149。
提示:求取字符串的长度和取得字符串中的某位置的字符可以参见如下代码
#include <iostream>
#include <string>
using namespace std;
int main()
{
printf("Hello World!\n");
string str = "abc";
char c = ' ';
char b = ' ';
for(int k = 0; k < str.size(); k++) // str.size()求得字符串的长度
{ // 字符串的下标从0开始计数,取得字符串中某个位置的字符有两种方式
c = str.at(k); // 1,通过at(i)方法求取第i个位置的字符
b = str[k]; // 2,通过下标操作[i]来求取第位置的字符两种方式都可以
}
return 0;
}
请问这个程序该怎么写?

不知道你要求用什么规则判断元音?
给你一个简单的,判断a,e,i,o,u
#include<iostream>

using namespace std;
//判断是不是a,e,i,o,u
//0表示是,1表示不是,2表示非字符
int IsYuan(char ch)
{
int iFlag;
if (('a'<=ch && ch<='z')||('A'<=ch && ch<='z'))
{
switch (ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
iFlag = 0;
break;
default:
iFlag = 1;
}
}
else
{
iFlag = 2;
}
return iFlag;
}
//统计元音
int isVolel(string src)
{
int counts = 0;
for(int k = 0; k < src.size(); k++) //
{
if (IsYuan(src[k])==0)
{
counts++;
}
}
return counts;
}
//统计福音
int isCon