Problem 1 Array of structures 70 points): Beer Distribution Project Implement a
ID: 3575198 • Letter: P
Question
Problem 1 Array of structures 70 points): Beer Distribution Project Implement a Beer Distribution problem where your program should be able to input the information from "beer dat'' into an array of structures and then give users the option to search for a particular beer, view the entire inventory or place an order. The program's interface should be such that a user can perform either one of these tasks as much as they want until they decide to quit the program. l. Searching for a beer should prompt the user for an ID number and the result should display its quantity and price, if it is in your inventory. 2. A view of the entire inventory will display all the beers with their ID number, price and quantity in ascending order by price. This sorting should be done using either Recursive Bubble or Recursive Selection sort. 3. When placing an order an invoice of the order should be printed to the screen Please note you MUST use the beer,dat file provided: The file structure is set up such that the first element of the file is a number containing the total number beers. With this number you must once again dynamically allocate (malloc or calloc) the appropriate array size. After that each beer will be listed in the following format I. Beer Name 2. Beer ID digits) 3. Beer Quantity 4. Beer Price Grading: 5 points Comments Functioning code 10 points Well-written code 5 points Correct results, ordered output 10 points Functions and passing 10 points 13 points User interface, alloc, mallocExplanation / Answer
#include <stdio.h>
#include<string.h>
struct beer
{
string beer_name[20];
int beer_id;
int beer_quenty;
float beer_price;
};
int main(void) {
int i,n;
struct beer x[50];
printf("enter number of beer names ");
scanf("%d",&n);
for(i=1;i<=n;i++);
{
printf("enter beer name ");
scanf("%s",&x[i].beer_name);
printf("enter beer id ");
scanf("%d",x[i].beer_id);
printf("enter beer quentity ");
scanf("%d",&x[i].beer_quenty);
printf("enter beer price ");
scanf("%f",x[i].beer_price);
}
for(i=1;i<n;i++)
{
printf("%d beer name= %s ",x[i].beer_name);
printf("%d beer id = %d",x[i].beer_id);
printf("%d beer quentity =%d ",x[i].beer_quenty);
printf("%d beer price%d= ",x[i].beer_price);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.