C++ Primer_5th<第三章>
文章平均质量分 62
Aclite
这个作者很懒,什么都没留下…
展开
-
<C++ Primer_5th>习题_3.2
//编写一段程序从标准输入中一次读取一整行,然后修改该程序使其一次读入一个词。#include#includeusing namespace std;int main( ){ string line; //提示用户输入字符串,直至文件结束或遇到异常输入 cout << " 请输入你的字符串,可以包括空格: " << endl; //使用getline()函数来读取一行字符串原创 2017-09-30 21:11:46 · 256 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.35
//编写一段程序,利用指针将数组中的元素置为0#includeusing namespace std;int main(){ const int sz = 10; int a[sz], i = 0; //通过for循环为数组赋值 for (i = 0; i < sz; ++i) a[i] = i; cout << "初始状态下数组的内容是: " << endl; /原创 2017-10-03 21:18:28 · 222 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.31
//编写一个程序,定义一个含有10个int的数组,令每个元素的值就是其所在位置的值#includeusing namespace std;int main(){ const int sz = 10; int a[sz]; //遍历数组元素并赋值 for (int i = 0; i < sz; ++i) { a[i] = i; } //输出数组中的全部元素 cout原创 2017-10-03 21:17:50 · 306 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.25
//使用迭代器划分分数范围#include#includeusing namespace std;int main(){ //该vector对象记录各分数段的人数,初始值为0 vector v_grade(11); int i_val; auto it = v_grade.begin(); cout << "请输入一组成绩(0~100): " << endl; whil原创 2017-10-03 21:16:55 · 250 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.24
//读入一组整数并把它们存入一个vector对象,将每对相邻整数的和输出出来。//使用迭代器实现#include#includeusing namespace std;int main(){ vector v_int; int i_val; cout << "请输入一组数字: " << endl; while (cin >> i_val) v_int.push_ba原创 2017-10-03 21:16:17 · 222 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.23
//编写一段程序,创建一个含有10个整数的vcetor对象,然后使用迭代器将所有元素值都变成原来的2倍。输出vector对象的内容,检验程序是否正确#include#include#include#includeusing namespace std;int main(){ vector v_int; //生成随机数种子 srand((unsigned)time(NULL原创 2017-10-03 21:15:40 · 274 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.22
//修改之前的那个输出 text第一段程序,首先把text的第一段全部改写成大写形式,然后再输出它#include#include#includeusing namespace std;int main(){ vector text; string s; cout << "请输入一段字符串" << endl; //利用getline读取一句话,直接回车产生一个空串,表示段原创 2017-10-03 21:14:59 · 308 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.20
//读入一组整数并把它们存入一个vector对象,将每对相邻整数的和输出出来。#include#includeusing namespace std;int main(){ vector v_int; int i_val; cout << "请输入一组数字: " << endl; while (cin >> i_val) v_int.push_back(i_val);原创 2017-10-03 21:14:01 · 175 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.17
//从cin读入一组词并把它们存入一个vcetor对象,然后设法把所有词都改为大写形式。输出改变后的的结果,每个词占一行。#include#include#includeusing namespace std;int main(){ vector v_string; string s; char cont = 'y'; //提示用户输入 cout << "请输入第一个词原创 2017-10-03 21:13:21 · 214 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.16
#include#include#include using namespace std;int main( ){ vector v1; vector v2(10); vector v3(10, 42); vector v4{ 10 }; vector v5{ 10,42 }; vector v6{ 10 }; vector v7{ 10,"hi" }; cout原创 2017-10-03 21:12:08 · 161 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.14
//编写一段程序,用cin读入一组整数并把他们存入一个vector对象#include#includeusing namespace std;int main(){ vector v_int; int i; //记录用户的输入值 char cont = 'y'; cout << "请输入第一个整数值: " << endl; while (cin原创 2017-09-30 21:19:42 · 295 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.10
//编写一段程序,读入一个包含标点符号的字符串,将标点符号去除后输出字符串剩余的部分//使用范围for实现#include#include#includeusing namespace std;int main( ){ string s; //提示用户输入 cout << "请输入一个字符串,最好含有某些标点符号: " << endl; getline(cin, s)原创 2017-09-30 21:18:46 · 214 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.6
//编写一段程序,使用范围for语句将字符串内的所用字符用X代替#include#includeusing namespace std;int main( ){ string s; //提示用户输入 cout << "请输入一个字符串,可以包含空格:" << endl; getline(cin, s); //读取整行,遇回车符结束 for (auto &c原创 2017-09-30 21:17:41 · 181 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.5
//编写一段程序从标准输入中读入多个字符串并将它们连接在一起,输出连接成的大字符串#include#includeusing namespace std;int main(){ char cont='y' ; string s, result ; //提示用户输入第一个字符串 cout << " 请输入第一个字符串: " << endl; //判断第一个字符串是否正确原创 2017-09-30 21:17:08 · 218 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.4
//编写一段程序读入两个字符串,比较其是否相等并输出结果。如果不等,输出较大的那个字符串。#include#includeusing namespace std;int main( ){ string s1, s2; //提示用户输入字符串 cout << "请输入两个字符串 : " << endl; cin >> s1 >> s2; //比较两个字符串 if (s1原创 2017-09-30 21:14:19 · 252 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.3
//string类的输入运算符和getline函数分别是如何处理空白字符的。(string和getline函数对含有空白字符串的区别)#include#includeusing namespace std;int main(){ string word, line; //提示用户输入字符串 cout << "请选择读取字符串的方式: 1表示逐词读取, 2表示整行读取 " <<原创 2017-09-30 21:13:15 · 224 阅读 · 0 评论 -
<C++ Primer_5th>习题_3.36
//编写一段程序,比较两个数组是否相等#include#include#includeusing namespace std;int main(){ const int sz = 5; int a[sz], b[sz], i; //生成随机数种子 srand((unsigned)time(NULL)); //为数组赋值 for (i = 0; i < sz; ++i)原创 2017-10-03 21:19:08 · 220 阅读 · 0 评论