c++ primer plus 第六章变成练习 第7题

本文介绍了一段使用C++实现的程序,该程序涉及输入多行英语句子,统计句子长度并筛选以特定字母开头的单词。通过实例演示了字符串操作和条件判断的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<iostream>


#include<string>
const int STRSIZE = 20;




int main()
{
using namespace std;
int i = 0;
int m = 0;
string *str = new string[STRSIZE];
cout << "请输入一句英语"<<endl;
while (1)
{
cin >> str[i];
++i;
if (cin.eof()||i>=STRSIZE)
{
break;
}
}
cin.get();
i = 0;
m = str->length();
cout << m << endl;
while (i<m)
{
cout << str[i] << endl;
++i;
}
i = 0;
cout << "输出以i,e,a,o,u开头的单词" << endl;
char ch;
while (i<m)
{
ch = str[i][0];
if (isalpha(ch))
{
switch (str[i][0])
{
case 'i':cout << str[i];break;
case 'e':cout << str[i];break;
case 'a':cout << str[i];break;
case 'o':cout << str[i];break;
case 'u':cout << str[i];break;
default:cout << "识别错误" << endl << ch;break;
}
}
++i;
}


delete[] str;


cin.get();
cin.get();
system("pause");
return 0;

}


c++ primer plus 第六章变成练习 第7题,有更好的思路欢迎贴出来,大家一起学习



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值