In: Computer Science
The following is a structure template:
struct box
{
char maker[40];
float height;
float width;
float length;
float volume;
};
a. Write a function that has a reference to a box structure as its formal argument
and displays the value of each member.
b. Write a function that has a reference to a box structure as its formal argument
and sets the volume member to the product of the other three dimensions.
#include <stdio.h> #include <string.h> struct box { char maker[40]; float height; float width; float length; float volume; }; // a. Write a function that has a reference to a box structure as its formal argument //and displays the value of each member. void print(struct box *b) { printf("Maker: %s\n", b->maker); printf("Height: %f\n", b->height); printf("Width: %f\n", b->width); printf("Length: %f\n", b->length); printf("Volume: %f\n", b->volume); } //b. Write a function that has a reference to a box structure as its formal argument //and sets the volume member to the product of the other three dimensions. void set_volume(struct box *b) { b->volume = b->height*b->width*b->length; } int main() { struct box b; strcpy(b.maker, "Maker"); b.length = 2; b.width = 7; b.height = 5; set_volume(&b); print(&b); return 0; }