Repository navigation
Expand file tree
/
Copy pathsample.cpp
More file actions
182 lines (164 loc) · 3.55 KB
/
Copy pathsample.cpp
File metadata and controls
182 lines (164 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# include <cstdlib>
# include <iostream>
# include <iomanip>
using namespace std;
int main ( );
void make_arrays ( int m, int **a, int n, int **b );
void i4vec_print ( int n, int a[], string title );
//****************************************************************************80
int main ( )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for ARRAY_RETURN.
//
// Discussion:
//
// The correct form of this program was worked out with the somewhat
// bemused assistance of Miro Stoyanov.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 03 February 2014
//
// Author:
//
// John Burkardt
//
{
int *a;
int *b;
int m;
int n;
cout << "\n";
cout << "ARRAY_RETURN:\n";
cout << " C++ version\n";
cout << " Create two arrays in a function, \n";
cout << " return them in the argument list.\n";
//
// Specify the size of the arrays to be created.
//
m = 10;
n = 5;
make_arrays ( m, &a, n, &b );
//
// Verify that the arrays were created and transferred properly.
//
i4vec_print ( m, a, " A as received by main:" );
i4vec_print ( n, b, " B as received by main:" );
//
// Free memory.
//
delete [] a;
delete [] b;
//
// Terminate.
//
cout << "\n";
cout << "ARRAY_RETURN:\n";
cout << " Normal end of execution.\n";
return 0;
}
//****************************************************************************80
void make_arrays ( int m, int **a, int n, int **b )
//****************************************************************************80
//
// Purpose:
//
// MAKE_ARRAYS creates, sets, and returns two arrays using the argument list.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 03 February 2014
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int M, the desired size of the first array.
//
// Output, int **A, the first array.
//
// Input, int N, the desired size of the second array.
//
// Output, int **B, the second array.
//
{
int i;
//
// We create PA and PB simply as a convenience.
// They make the code a little more readable.
//
int *pa;
int *pb;
( *a ) = new int[m];
pa = *a;
for ( i = 0; i < m; i++ )
{
pa[i] = 10 + i;
}
i4vec_print ( m, pa, " A as defined in MAKE_ARRAYS:" );
( *b ) = new int[n];
pb = *b;
for ( i = 0; i < n; i++ )
{
pb[i] = 100 + 2 * i;
}
i4vec_print ( n, pb, " B as defined in MAKE_ARRAYS:" );
return;
}
//****************************************************************************80
void i4vec_print ( int n, int a[], string title )
//****************************************************************************80
//
// Purpose:
//
// I4VEC_PRINT prints an I4VEC.
//
// Discussion:
//
// An I4VEC is a vector of I4's.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 14 November 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int N, the number of components of the vector.
//
// Input, int A[N], the vector to be printed.
//
// Input, string TITLE, a title.
//
{
int i;
cout << "\n";
cout << title << "\n";
cout << "\n";
for ( i = 0; i < n; i++ )
{
cout << " " << setw(8) << i
<< ": " << setw(8) << a[i] << "\n";
}
return;
}