zoukankan      html  css  js  c++  java
  • C++primer plus第六版课后编程题答案 6.7

    6.7
    #include<iostream>
    #include<cctype>
    using namespace std;
    
    void main67()
    {
    	const int Size=10;
    	int vowels=0;	//存储个数
    	int consonants=0;
    	int other=0;
    	cout<<"Enter words (q to quit)"<<endl;
    	char temp[Size];
    	char ch='0';
    	char t;	//读取数组内单个字符
    	do{
    		//while(ch!='13'&&ch!='
    ')
    		//{
    			cin>>temp;
    			cout<<temp<<" "<<endl;
    			t=temp[0];
    			//int j=0;
    			//while(t!='') //判断元音开头
    			//{ 这里我默认输入的都是单词或者数字,即不会出现如 aag125sa这类的输入
    			if(!isalpha(t))
    					other++;
    			else if(t=='a'||t=='e'||t=='i'||t=='o'||t=='u')
    					vowels++;
    			else
    					consonants++;
    			//}
    			
    			if(temp[0]=='q'&&strlen(temp)==1)	//判断是否为q至关重要的一步
    				break;
    			
    		//}
    		/**
    		cout<<"vowels="<<vowels<<endl;
    		cout<<"consonants="<<consonants<<endl;
    		cout<<"other="<<other<<endl;
    		cout<<"ch== "<<ch<<endl;
    		*/
    	}while(true);
    
    	cout<<vowels<<"  words beginning with vowels"<<endl;
    	cout<<consonants<<" words beinning with consonants"<<endl;
    	cout<<other<<" others"<<endl;
    	system("pause");
    
    
    }
    

  • 相关阅读:
    2019春招面试题总结-03
    2019春招面试题总结-02
    2019春招面试题总结-01
    Node.js 全局对象
    Node.js 路由
    Node.js 函数
    Node.js 模块系统
    Node.js Stream(流)
    Node.js Buffer(缓冲区)
    Node.js EventEmitter
  • 原文地址:https://www.cnblogs.com/qq84435/p/3664834.html
Copyright © 2011-2022 走看看