第九章2-3题
来源:互联网 发布:smtp 端口 编辑:程序博客网 时间:2024/05/18 20:11
#include<string>
#include<iostream>
using namespace std;
void strCount(const string& str);
int main()
{
int i = 1;
string nx;
while(1)
{
cout<<"请输入第"<<i<<"个句子.(q To exit)";
getline(cin,nx);
if(nx == "q")
break;
else strCount(nx);
++i;
}
cout<<"Bye";
return 0;
}
void strCount(const string& str)
{
static int total = 0;
total += str.size();
cout<<"总共输入了"<<total<<"个字母."<<endl;
}
第3题
#include<iostream>
#include<cstring>
struct chaff
{
char dross[20];
int slag;
};
int main()
{
using namespace std;
chaff* rb = new chaff[10];
for(int i = 0 ; i < 10 ; ++i)
{
cout<<"请输入第"<<i+1<<"个渣渣的名称:";
cin.getline((rb+i)->dross,20);
cout<<"请输入这个渣渣的战斗力:";
cin>>(rb+i)->slag; //均没有检查输入
cin.get();
}
for(int i = 0 ; i < 10 ; ++i)
{
cout<<"第"<<i+1<<"个渣渣名叫"<<(rb+i)->dross<<endl;
cout<<"该渣渣战斗力为:"<<(rb+i)->slag<<endl;
}
delete [] rb;
return 0;
}
- 第九章2-3题
- 第九章 二题
- 第九章第二题
- 第九章第三题
- 第二章第九题
- 第二章第九题
- 第二章第九题
- 第三章第九题
- 第三章第九题
- 第五章第九题
- 第九章课后题
- 第九章3
- 第九章2
- 第二章习题第九题
- HTML第九章上机题
- 第九章第1题
- 第九章第4题
- 第九章项目一 3
- 第8章 1-3题
- 图书管理系统
- 第八章4-7题
- 第九章第1题
- linux安装mysql
- 第九章2-3题
- 第九章第4题
- 巴什博弈(hdu 2897)
- Linux Kernel设备驱动模型之 struct device_node
- 第10章第1题
- 第10章第2题
- [译]Java定时任务调度-Quartz Cron 调度
- 第10章第3题
- 第10章第4题