Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions