Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming A local drugstore gathered some data in a file for antacids. The store manager would like to be able to recommend product to

C programming

A local drugstore gathered some data in a file for antacids. The store manager would like to be able to recommend product to customers based on customer reviews. The file has the following format (the first line is not included in the file).

InStock unitsSold Avg. Customer Review #of Reviews Brand

0 891 4.2 170 Pepto Bismol

45 320 4.5 38 Ranitidine Fx

...

The numbers represent the number of units in stock at the drugstore, and units sold for the past three months, the average customer review, and the number of reviews, followed by the brand name.

Write program that read in the data from a file and sort the antacids by average customer review. The output file contains the list of top 5 recommended antacids (top 5 by average customer review with 50 or more reviews, and currently in stock). The list of recommended antacids should be written the same file name as the input file name with added extension of .top. For example, if the original file name is antacids.txt, the output file name is then antacids.txt.top.

1. Input file name should be obtained from the command line. For example, if the file name is antacids.txt, you will run the program as:

./a.out antacids.txt

2. Read the data using fscanf function. To read the brand name (last item in a line), use "%[^n]n" as the conversion specifier for fscanf function.

3. Define a structure antacids to store the brand (string), unitsInStock (integer), and unitsSold (integer), and avg customer review (double), number of reviews (integer). Assume the brand is no more than 100 characters.

4. Build an array of antacids structures. Assume that there are no more than 100 antacids drugs in the file.

5. Modify the selection_sort function to sort an array of antacids drugs in descending order, sorted by avg. customer review. The function should have the following prototype:

void selection_sort(struct antacids antacid_drugs[], int n);

6. The output file should include the list of antacids drugs for recommendation (average customer review of 4 or more with 50 or more reviews, currently in stock) in the same format as the input file but in sorted order by average customer review.

//---------------------------------------------------- Antacid file ----------------------------------------------------//

// Copy and paste in antacids.txt document:

20 291 4.2 170 Pepto Bismol

35 320 4.3 238 Zantac Fx

52 150 4.4 55 Fast Tums

15 74 4.7 201 Alka-Seltzer

22 120 3.5 458 Milk of Magnesia

15 109 4.1 87 Axid AR

2 75 3.5 293 Prilosec

15 58 3.3 389 Tagamet

27 45 3.9 68 Prevacid Fx

0 90 5.0 174 Pepcid K

81 17 4.0 1132 Zantac Regular

8 8 4.3 2 Tums Regular

//---------------------------------------------------- selection_sort file ----------------------------------------------------//

// selection_sort file to modify:

#include

#define N 10

void selection_sort(int a[], int n);

int main(void)

{

int i;

int a[N];

printf("Enter %d numbers to be sorted: ", N);

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

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

selection_sort(a, N);

printf("In sorted order:");

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

printf(" %d", a[i]);

printf(" ");

return 0;

}

void selection_sort(int a[], int n)

{

int i, largest = 0, temp;

if (n == 1)

return;

for (i = 1; i < n; i++)

if (a[i] > a[largest])

largest = i;

if (largest < n - 1) {

temp = a[n-1];

a[n-1] = a[largest];

a[largest] = temp;

}

selection_sort(a, n - 1);

}

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

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

When may a taxpayer petition the U.S. Tax Court? How is this done?

Answered: 1 week ago