帮忙编写一个C++程序

来源:互联网 发布:three.js源码阅读笔记 编辑:程序博客网 时间:2024/04/29 16:48
|||while&#40; = 'E') && (select **"<<endl;break;default:break;}}while((select = '/0') //将ch中的字符转存到message中{message[i] = ch[i];i++;} message[i] = '/0'; //结束标志符}void CCharStat::StatChar(){for(int i = 0; i < ContentNum; i++){if(((message[i] >= 'a') && (message[i] <= 'z')) ||((message[i] >= 'A') && (message[i] <= 'Z'))){CountEnglish++;}else if((message[i] >= '0') && (message[i] <= '9')){CountNumeral++;}else if(message[i] == ' '){CountBlank++;}else{CountOthers++;}}}void CCharStat::PrintResult(){cout<<"The result of characters statted is "<<endl;cout<<"The number of English character is "<<CountEnglish<<endl;cout<<"The number of numeral character is "<<CountNumeral<<endl;cout<<"The number of blank character is "<<CountBlank<<endl;cout<<"The number of other character is "<<CountOthers<<endl<<endl;}void CCharStat::ClearData(){CountEnglish = 0;CountNumeral = 0;CountBlank = 0;CountOthers = 0;ContentNum = 0;}答案补充#include"ChStat.h"void main(){char select = '1';CCharStat ChStat; do{cout<<"**CharacterStat Software**"<<endl<<endl;cout<<"select 1: Input Character"<<endl;cout<<"select 2: See about result"<<endl;cout<<"select 3: Clear history"<<endl;cout<<"select E(e): exit"<<endl<<endl;cout<<"Please select: ";cin>>select;答案补充switch(select){case '1':ChStat.CharInput();break;case '2':ChStat.StatChar();ChStat.PrintResult();break;case '3':ChStat.ClearData();break;case 'E':case 'e':cout<<"**Thank you for using this software = '/0')i++;ContentNum = i;//计算ch长度i = 0;message = new char[ContentNum + 1]; while(ch[i] 再存在ch中int i = 0;cin.ignore();//清除输入流中的错误cout<<"Please input characters and twice Enter end"<<endl;getline(cin //所以先利用这个对象输入 由于string类对象可以输入任意长度 第二次按回车才开始输出 给分哦 digit letter blank 其他有%d个/n" n);ch=getchar();for(i=1;i<=n;i++){ch=getchar();if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))letter++;else if(ch>='0'&&ch<='9')digit++;else if(ch==' ')blank++;else other++;}printf("空格有%d个 Search&#40;MeiMei&#41;&#41; printf&#40;&quot;;)&quot;&#41;;printf&#40;&quot;:)&quot;&#41;;|||"http://download.pchome.net/utility/file/editor/5285.html"挺好用的 格式咋都乱了呢 给分吧 |||#include <stdio.h>int main(void){ printf("Hello World = 'e'));}答案补充耶 就要先输入9就会输出有4个英文1个空格3个数字1个其他 如果你先输入10空格就会多出1个答案补充可以就给分 再输入要统计的东西 先输入你要统计的东西的个数 数字有%d个 &n);printf("Enter %d characters:" n;char ch;blank=letter=digit=other=0;printf("Enter n characters:");scanf("%d" other i digit letter other);return 0;}说明 英文有%d个 other);return 0;}怎么样 while(ch[i] /n"); return 0;}|||#include<stdio.h>int main(){ int blank ch //ChStat.h#include<iostream>using namespace std;class CCharStat{public:CCharStat();~CCharStat();void CharInput();void StatChar();void PrintResult();void ClearData();private:char *message;int ContentNum;};//ChStat.cpp#include"ChStat.h"#include<string>#include<iostream>using namespace std;static int CountEnglish = 0;static int CountNumeral = 0;static int CountBlank = 0;static int CountOthers = 0;CCharStat::CCharStat(){message = NULL;ContentNum = 0;}CCharStat::~CCharStat(){delete[] message;}void CCharStat::CharInput(){string ch;//用于输入需统计的内容 从读取的内容中删除该终止符 以换行符作为终止字符//在读取完成后 数字有%d个 &n);printf("Enter %d characters:" n;char ch;blank=letter=digit=other=0;printf("Enter n characters:");scanf("%d" other i digit letter '/n'); //getline函数的功能是允许从输入流中读取多个字符 英文有%d个 合作愉快|||#include<stdio.h>int main(){int blank digit letter blank 其他有%d个/n" n);ch=getchar();for(i=1;i<=n;i++){ch=getchar();if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))letter++;else if(ch>='0'&&ch<='9')digit++;else if(ch==' ')blank++;else other++;}printf("空格有%d个 比如你要输入Abcd 123
原创粉丝点击