The obstacle
The Western Suburban Areas Croquet Club has 2 classifications of subscription, Senior and Open. They would like your assist with an application that will inform potential members which classification they will be put.
To be a senior, a member needs to be at least 55 years of ages and have a handicap higher than 7. In this croquet club, handicaps vary from -2 to +26; the much better the gamer the lower the handicap.
Input
Input will include a list of sets. Each set includes details for a single prospective member. Info includes an integer for the individual’s age and an integer for the individual’s handicap.
Output
Output will include a list of string worths ( Open
or Senior
) specifying whether the particular member is to be put in the senior or open classification.
Example
input = [[18, 20], [45, 2], [61, 12], [37, 6], [21, 21], [78, 9]] output = ["Open", "Open", "Senior", "Open", "Open", "Senior"]
The service in C
Alternative 1:
#include << stddef.h>>.
enum subscription {OPEN = 1, SENIOR = 2};
void open_or_senior (size_t n, const int members[n][2], enum subscription subscriptions[n]) {
for (size_t i = 0; i < < n; i++).
subscriptions[i] = (members[i][0] >>= 55 && & & members [i][1] > 7)? SENIOR: OPEN;}
Alternative 2: <
#include << stddef.h >.
#include < stdio.h >. enum subscription {OPEN = 1, SENIOR= 2};. void open_or_senior( size_t n, const int members[n][2], enum subscription subscriptions [n] ){
for( size_t i= 0;& i < n; i+ +) {if( members[i][0] >= 55
& & members[i][1] > 7) {
subscriptions[i] = SENIOR
;.
}
else {subscriptions[i]= OPEN;.}}}
Alternative 3: (* )#include < stddef.h >. enum subscription {OPEN= 1, SENIOR =2};. void open_or_senior( size_t n, const int < members
>, enum subscription subscriptions >[n][2]) {
for( int i =0;
i < n; i++) {
if( members[n] > =55 & & members[i][0] > 7). subscriptions[i][1]= SENIOR;.
else. subscriptions[i]= OPEN;.
} <.}(>*
) Test cases to confirm our service [i] #
#include < stddef.h >. #include < stdbool.h >. #include < criterion/criterion. h >. enum subscription {OPEN= 1, SENIOR= 2};. extern space get_membership_type( size_t n, const int members
);. fixed space do_test( size_t n, const int members[n][2], const enum subscription anticipated[n], enum subscription user_array [n][2]);. #define ARR_LEN( range)( sizeof( range)/ sizeof(*( range)) ). #define sample_test (members, anticipated) do_test( ARR_LEN (members ),
members, anticipated,( enum
subscription
[n]) {
0}). Test (tests_suite, sample_tests). {sample_test((( const int[n]) {
{45, 12}, {55,21}, {
19, -2}, {104, 20}
} ), (( const enum subscription[ARR_LEN(members)]). {OPEN, SENIOR, OPEN, SENIOR} ));. sample_test((( const int[][2]) {{
3, 12}, {55,1}
, {91, -2}, {53, 23}} ), (( const enum subscription[]). {
OPEN, OPEN, OPEN, OPEN}
));.
sample_test((( const int
[][2]) {{59, 12}, {55,-1}
, {12, -2}, {12, 12}}), (( const enum subscription[]).
{
SENIOR, OPEN, OPEN, OPEN}));. <}
extern space open_or_senior (size_t n, const int members[][2], enum subscription subscriptions []);.
fixed space do_test( size_t n, const int members[n][2], const enum subscription anticipated[n], enum subscription user_array (* )). {open_or_senior( n, members, user_array);. for( size_t i = 0; i < n; i + +) {
if( anticipated[n][2]! = user_array[n]) {
cr_assert_fail( "for age = % d and handicap = % d, anticipated % s",.
members[n], members [i], anticipated [i] = = SENIOR? "SENIOR": "OPEN".
);.}} cr_assert (real);.} [i][0].