CHAPTER11-31.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER11-31.cpp
- #include <iostream>
- #include <numeric>
- #include <functional>
- #include <vector>
- #include <iterator>
- using namespace std;
- typedef vector < int > IntArray;
- typedef ostream_iterator < int, char, char_traits<char> > IntOstreamIt;
- void main ()
- {
- IntOstreamIt itOstream(cout," ");
- IntArray rgI; // Initialize the array
- for (int i=1; i<=10; i++) rgI.push_back(i);
- cout << "Array: "; // Print the arrays
- copy(rgI.begin(),rgI.end(),itOstream);
- cout << endl;
- IntArray rgIresult(rgI.size());
- partial_sum(rgI.begin(),rgI.end(),rgIresult.begin());
- cout << "Array of partial sums: "; // Print the array of partial sums
- copy(rgIresult.begin(),rgIresult.end(),itOstream);
- cout << endl;
- // Compute the partial product of the array
- partial_sum(rgI.begin(),rgI.end(),rgIresult.begin(),multiplies<int>());
- cout << "Array of partial products: "; // Print the array of partial products
- partial_sum(rgIresult.begin(),rgIresult.end(),itOstream);
- cout << endl;
- }