第十五周项目一 阅读下面程序,解释运行结果(5)

来源:互联网 发布:矩阵力学的主要创立者 编辑:程序博客网 时间:2024/05/20 19:31
/*copyright(c)2016.烟台大学计算机学院 * All rights reserved, * 文件名称:text.Cpp * 作者:舒文超 * 完成日期:2016年6月4日 * 版本号:vc++6.0 * 问题描述:阅读下面程序,并写出运行结果。 */#include <iterator>#include <algorithm>#include <functional>#include <iostream>#include <vector>using namespace std;class Angle{    int degrees;public:    Angle(int deg) : degrees(deg) {}    int mul(int times)    {        return degrees *= times;    }};int main(){    int x[] = {1, 2, 4, 5, 8};    vector<Angle> va;    for(int i =10; i <= 50; i += 10)        va.push_back(Angle(i));    transform(va.begin(), va.end(), x, ostream_iterator<int>(cout , "  "), mem_fun_ref(&Angle::mul));    cout << endl;    return 0;}

运行结果:

                10  40  120  200  400

解释:“ transform(va.begin(), va.end(), x, ostream_iterator<int>(cout , "  "), mem_fun_ref(&Angle::mul)) ”
            的意思是用ya的没一个数乘以x中的每一个相对应的数,最终输出。

0 0