Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include int main() { char ch; int N, average = 0, sum = 0, count = 0; printf(Enter the number of cities ); scanf(%d, &

#include

int main() {

char ch;

int N, average = 0, sum = 0, count = 0;

printf("Enter the number of cities ");

scanf("%d", & N);

int patients[N];

while (1)

{

printf(" Enter a, to take the number of COVID patients of all N into patients array of size N. Enter b, to find the average number of patients of all the N. Enter c, to count and display the # of N which have above average COVID patients. Enter q, to quit/exit the menu system. ");

printf(" Enter your choice ");

scanf("%s",&ch);

switch (ch)

{

case 'a':

{ sum = 0;

printf(" Enter number of patients in respective cities ");

for (int i = 0; i < N; i++)

{

scanf("%d", & patients[i]);

sum = sum + patients[i];

}

break;

}

case 'b':

{ if(patients[0]==NULL)

{

printf("enter input first");

break;

}

average = sum / N;

printf("average covid patients in all cities are %d ", average);

break;

}

case 'c':

{ count = 0;

if(patients[0]==NULL)

{

printf("enter input first");

break;

}

for (int i = 0; i < N; i++)

{

if (patients[i] > average)

{

printf("city %d ", i + 1);

count++;

}

}

printf("total number of cities with patients above covid average are %d ", count);

break;

}

case 'q': return 0;

default: printf("invalid input ");

}

}

return 0;

} [02:22] You will extend the assignment one. Here is the description.

(a)(i) Create a City structure that will have the following members: name (string type), population (int type), area (float type) and numOfCOVIDPatients (int type).

(ii) In the main function, create an array of size N of City structure type. This array will be used by all the functions. You will have a lower case n to keep track of the number of cities in the array. You will pass this array and # of cities as arguments to the functions.

(b) Create a function takeCitiesInfoFromKeyboard that takes a City structure array and n as parameters. It takes information of all the Cities from keyboard and stores in the City structure array. Do you know that arrays are passed by reference?

(c) Create a function computeAverageNumOfCOVIDPatients that takes a City structure array and n as parameters. It computes and returns the average number of COVID patients of all the Cities.

(d) Create a function findAboveAvgCOVIDPatientCities that takes a City structure array and n as parameters. It finds all the Cities that have higher than average number of COVID patients and displays their information in a tabular format with following values (including the given column heading):

City Name City Population City Area Num of City COVID Patients

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

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions