void set( ABC x[], const unsigned n[], const char c[], const double a[][3], unsi
ID: 669264 • Letter: V
Question
void set( ABC x[], const unsigned n[], const char c[], const double a[][3], unsigned elements );
This does the same thing as the other set function, but it does it with arrays of values instead of single values. x, n, c, and a are parallel arrays: x, n and c each have elements elements; a has elements rows. Each element of x is set according to the corresponding elements of n, c, and a. For instance, if n[17] were 1234, c[17] were ‘?’, and a[17] were {10.0, 20,0, 30.0}, then set would set x[17] to {1234, ‘?’, {10.0, 20.0, 30.0}} (assuming, of course, that elements > 17). Naturally, I expect that you’ll write this function the easy way, which is to repeatedly call the other set function.
the other set function:
void set( ABC &x, unsigned n, char c, const double a[3] )
{
x.n = n;
x.c = c;
//cout << "x.n = " << x.n << endl;
//cout << "x.c = " << x.c << endl;
for (int i = 0; i < SIZE; i++)
{
x.a[i] = a[i];
// cout << "x.a[i] = " << x.a[i] << endl;
}
}
Explanation / Answer
void set( ABC x[], const unsigned n[], const char c[], const double a[][nArr], unsigned elements ) {
for (unsigned i = 0; i < elements; i++){
set(x[i], n[i], c[i], a[i]); // this is the other function given in the problem
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.