struct shape scale(struct shape s, double c)
{ struct shape new_shape = s;
if (new_shape.shape_kind == RECTANGLE) {
new_shape.u.rectangle.height *= c;
new_shape.u.rectangle.width *= c;
} else
new_shape.u.circle.radius *= c;
return new_shape;
}
15. [was #14]
(a) enum week_days {MON, TUE, WED, THU, FRI, SAT, SUN};
(b) typedef enum {MON, TUE, WED, THU, FRI, SAT, SUN} Week_days;
17. [was #16] All the statements are legal, since C allows integers and
enumeration values to be mixed without restriction. Only (a), (d), and (e) are safe. (b) is not meaningful if i has a value other than 0 or 1. (c) will not yield a meaningful result if b has the value 1.
Answers to Selected Programming Projects
1. [was #6; modified]
#include <stdio.h>
#define COUNTRY_COUNT \
((int) (sizeof(country_codes) / sizeof(country_codes[0])))
struct dialing_code {
char *country;
int code;
};
const struct dialing_code country_codes[] =
{{"Argentina", 54}, {"Bangladesh", 880},
{"Brazil", 55}, {"Burma (Myanmar)", 95},
{"China", 86}, {"Colombia", 57},