⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vowel.cpp

📁 我学习C++ Primer Plus过程中写下的课后作业的编程代码
💻 CPP
字号:
//第六章
//7.编写一个程序,它每次读取一个单词,直到用户只输入q。然后,该程序指出有多少个单词
//以元音打头,有多少个单词以辅音打头,还有多少个单词不属于这两类。为紫,方法之一是,
//使用isalpha()来区分以字母和其他字符打头的单词,然后对于通过了isalpha()测试的单词,
//使用if或switch语句来确定哪些以元音。

#include <iostream>
#include <string>
#include <cctype>

int main()
{
	using namespace std;
	int vowels=0;
	int consonants=0;
	int others=0;
	char ch;
	string words;
	cout<<"Enetr words (q to quit):"<<endl;
	cin>>words;
	while( "q"!=words && "Q"!=words )
	{
		if( isalpha(words[0]) )
		{
			ch=tolower(words[0]);
			switch(ch)
			{
			case 'a':	vowels++;	break;
			case 'e':	vowels++;	break;
			case 'i':	vowels++;	break;
			case 'o':	vowels++;	break;
			case 'u':	vowels++;	break;
			default:	consonants++;
			}
		}
		else
			others++;
		cin>>words;
	}
	cout<<vowels<<" words beginning with vowels."<<endl;
	cout<<consonants<<" words beginning with consonants."<<endl;
	cout<<others<<" others"<<endl;
	return 0;
}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -