Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
transform.cpp
Go to the documentation of this file.
1
29#include <algorithm> // for transform
30#include <functional> // for multiplies
31#include <deque> // for deque
32#include <iostream> // for cout, endl
33#include <iomanip> // for setw
34
35
36int main ()
37{
38 typedef std::deque<int, std::allocator<int> > Deque;
39
40 // Initialize a deque with an array of integers.
41 const Deque::value_type a [] = { 99, 264, 126, 330, 132 };
42 const Deque::value_type b [] = { 280, 105, 220, 84, 210 };
43
44 Deque d1 (a, a + sizeof a / sizeof *a);
45 Deque d2 (b, b + sizeof b / sizeof *b);
46
47 // Print the original values.
48 std::cout << "The following pairs of numbers: \n ";
49 Deque::iterator i1;
50 for (i1 = d1.begin(); i1 != d1.end(); ++i1)
51 std::cout << std::setw (6) << *i1 << " ";
52
53 std::cout << "\n ";
54 for (i1 = d2.begin(); i1 != d2.end(); ++i1)
55 std::cout << std::setw (6) << *i1 << " ";
56
57 // transform the numbers in one sequence to their factorials
58 // and store the results in another sequence
59 std::transform (d1.begin (), d1.end (), d2.begin (), d1.begin (),
60 std::multiplies<int>());
61
62 // Display the results.
63 std::cout << "\n\nHave the products: \n ";
64 for (i1 = d1.begin (); i1 != d1.end (); ++i1)
65 std::cout << std::setw (6) << *i1 << " ";
66
67 std::cout << std::endl;
68
69 return 0;
70}
#define d1
Definition 17.names.cpp:228
#define a
Definition 17.names.cpp:109
#define i1
Definition 17.names.cpp:233
#define b
Definition 17.names.cpp:110
#define d2
Definition 17.names.cpp:254
std::deque< std::string, std::allocator< std::string > > Deque
Definition deque.cpp:35
int main()
Definition transform.cpp:36