Provide the definition for each of the following structures and unions:
a) Structure inventory containing character array partName[ 30 ], integer partNumber, floating point price, integer stock and integer reorder.
b) Union data containing char c, short s, long b, float f and double d.
c) A structure called address that contains character arrays streetAddress[ 25 ], city[ 20 ], state[ 3 ] and zipCode[ 6 ].
d) Structure student that contains arrays firstName[ 15 ] and lastName[ 15 ] and variable homeAddress of type struct address from part (c).
e) Structure test containing 16 bit fields with widths of 1 bit. The names of the bit fields are the letters a to p.

Respuesta :

Answer:

a)

struct inventory  // structure inventory

{

char partName[ 30 ];  // char array

int partNumber;  // variable partNumber

float price;  // FLOAT VARIABLE PRICE

int stock ;  // INT VARIABLE STOCK

int reorder;  // INTEGER VARIABLE RECORDER

};

b)

union data // structure union

{

char c;  // char variable

short s; // short variable

long b; //

long variable float f ;  // float variable

double d ; // double variable

};

c)

struct address  // structure address

{

char streetAddress[ 25 ]; // character array

char city[ 20 ]; // variable char

char  state[ 3 ] ; // state array

char  zipCode[ 6 ] ; // zipcode array

};

d)

structure student  // structure student

{

char firstName[ 15 ]; // array first name

char  lastName[ 15 ] ;  // array last name

struct address * ;  // holding the home address

};

e)

struct test

{

unsigned a:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1, i:1, j:1, k:1, l:1, m:1, n:1, o:1, p:1;

}; // prototype test assign value

Explanation:

Following are the description of the above part

a)

  • By using the struct keyword we declared the structure .In the part (a) we declared the struct  "inventory".In this structure we char array "partName " of size 30 .
  • We holding the 3 int variable "partNumber" , "stock" and "reorder." and 1 float variable i.e "price ".

b)

  • By using the union keyword we declared the union .In the part (b) we created the union .
  • Inside that union we holding different types of datatype that are mention in the question .

C)

  • By using the struct keyword we declared the structure  .In the part (c) we created the structure.
  • Inside that structure we holding array of character of variable "streetAddress","city","state" and "zipcode" by using char array .

d)

  • By using the struct keyword we declared the structure .
  • In this we declared array of "firstname" and "lastname" of char datatype .
  • In the last we create a structure address by using the pointer following by struct address

e)

In the part e we created the test that contain unsigned value of thhe 16 bit and 1 width

ACCESS MORE