Question
Define a union ut with 2 members: int num, float fi b. [10] Define a struct st with members: int flag and array of unions
Define a union ut with 2 members: int num, float fi
b. [10] Define a struct st with members: int flag and array of unions u. u has 15 elements
i. When flag 0, each element of u's num field is valid
ii. When flag 1, each element of u's fi field is valid
c. [5] Declare a global array called sts with N struct st elements.
d. [20] Write a function to randomly initialize each struct st in the array sts. The prototype of this function should be void initialize();
i. For each struct, generate a random number to set the flag variable.
ii. If the flag is 0, generate random integers for each element of u and assign that to the num field of each union.
iii. If the flag is 1, generate another random integer between 300 and 10000. Divide that random number by 1000 and assign that to the fi field of each union.
e. [20] Write a function that averages each struct st's array of unions. The prototype of the function is float average():
f. [20] Write a function that counts the number union u values that are less than k.k is a passed in integer. The prototype of the function is int count(int k); u
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started