C++ Primer(第五版)练习3.25
2016-10-07 18:48
337 查看
首先,先给出书中所示的利用下标运算符实现划分分数段的程序:
题目中要求使用迭代器改写程序并实现完全相同的功能:
#include <iostream> #include <string> #include <vector> using namespace std; int main() { vector<unsigned> scores(11, 0); unsigned grade; while (cin >> grade) if (grade <= 100) ++scores[grade / 10]; for (auto c : scores) cout << c << " "; system("pause"); return 0; }
题目中要求使用迭代器改写程序并实现完全相同的功能:
#include <iostream> #include <string> #include <vector> using namespace std; int main() { vector<unsigned> scores(11,0); unsigned grade; auto it = scores.begin(); while (cin >> grade) if (grade <= 100) ++*(it + grade / 10); for (auto a : scores) cout << a << " "; system("pause"); return 0; }
相关文章推荐
- C++ primer(第五版) 练习 3.25 个人code 和疑问
- C++ Primer(第五版)练习3.25
- C++ primer(第五版) 练习 5.23、5.24、5.25 个人code
- C++ primer(第五版) 练习 6.56 个人 code
- C++ primer 第五版 中文版 练习 10.24个人code
- C++ primer 第五版 中文版 练习 10.33 个人code
- C++ primer 第五版 中文版 练习 12.19 个人code
- C++ Primer(第五版)练习12.6
- C++ primer第五版 练习 6.33
- c++ primer第五版 练习7.9
- C++ Primer(第五版)练习3.41
- C++ primer(第五版) 练习 3.39 个人code
- C++ primer(第五版) 练习 3.43 个人code
- C++ primer(第五版) 练习 5.17 个人code
- C++ primer(第五版) 练习 6.10 个人code
- C++ primer 第五版 中文版 9.3.2 节练习
- C++ primer 第五版 中文版 练习 10.1 个人code
- C++ primer 第五版 中文版 练习 10.37 个人code
- C++ primer 第五版 中文版 练习 11.32 个人code
- C++ Primer 第五版 练习 3.21,3.24