Question: Write a C++ Program: Arrays & structs: This problem has the following 4 functions, plus a main function: unsigned firstNotPresent(const unsigned ar[], unsigned els); bool
Write a C++ Program:
Arrays & structs:
This problem has the following 4 functions, plus a main function:
unsigned firstNotPresent(const unsigned ar[], unsigned els);
bool isPermutation(const unsigned a[], unsigned els);
void reverseA(ABC & abc);
void reverseA(ABC ar[], unsigned els);
As you can see, a couple of functions use the struct ABC type, defined as follows:
struct ABC{
unsigned n;
char c;
double a[3];
};
Your main should call these 4 functions; beyond that, what your main does is up to you. (Having main do a quick test to see if these 4 functions seem to work would be a good idea.) As always, you are welcome to write whatever helper functions you think would be worthy of the name. unsigned firstNotPresent(const unsigned ar[], unsigned els);
Just return the first whole number that is not in the array.
For example, if ar held {8, 3, 5, 4, 2, 1, 0}, then firstNotPresent(ar, 7) would return 6;
firstNotPresent(ar, 6) would return 0.
bool isPermutation(const unsigned ar[], unsigned els);
Return whether every subscript in the array is also a value in the array. For example, if ar held {4, 2, 0, 1, 3, 3}, then isPermutation(ar, 5) would return true (because the numbers 0, 1, 2, 3, and 4 all appear in {4, 2, 0, 1, 3}); isPermutation(ar, 6) would return false (because the numbers 0, 1, 2, 3, 4, and 5 do not all appear in {4, 2, 0, 1, 3, 3}).
void reverseA(ABC & abc);
reverseA's job is to reverse the order of the elements in the a array within the abc struct object
(without changing abc's n field or c field). For example, if abc held the data {1, 'a', {2.2, 3.3, -4.4}}
on entry, then it would hold the data {1, 'a', {-4.4, 3.3, 2.2}} on exit.
void reverseA(ABC ar[], unsigned els);
This reverseA has the same name as the other reverseA, but as you know, it's fine for two C++ functions to have the same name as long as they have different parameter lists (which they do). This reverseA's job is to reverse the order of elements in the a array of all the elements of this array of structs.
For example, if ar held the data
{{1, 'a', {-4.4, 3.3, 2.2}}, {2, 'b', {-7.7, 6.6, 5.5}}}
on entry, then it would hold the data
{{1, 'a', {2.2, 3.3, -4.4}}, {2, 'b', {5.5, 6.6, -7.7}}}
on exit.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
