Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1 Array of structures 70 points): Beer Distribution Project Implement a

ID: 3574595 • 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. 1. 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 1, 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 User interface, alloc, malloc 13 points

Explanation / Answer

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
/* Define a beerdata structure */
typedef struct {
char beer_name[100];
int beer_id;
char beer_quantity[10];
char beer_price[20];
} beerdata ;
beerdata beer[30];
FILE * filehandle;
char lyne[121];

char *item;
int reccount = 0;
int k;
int count = 0;

/* Here comes the actions! */
/* open file */

filehandle = fopen("beer.dat","r");

/* Read file line by line */
while (fgets(lyne,20,filehandle) ) {
if(count >= 4){
reccount++;
count = 0;
}
if(count == 0){
strcpy(beer[reccount].beer_name,lyne);
}
if(count == 1){
item = strtok(lyne," ");
beer[reccount].beer_id = atoi(item);
}
if(count == 2){

item = strtok(lyne," ");
strcpy(beer[reccount].beer_quantity,item);
}
if(count == 3){
strcpy(beer[reccount].beer_price,lyne);
}
count++;
}

/* Close file */

fclose(filehandle);

/* Loop through and report on data */

printf("Beer Record ");
for (k=0; k<4; k++) {
printf("%s ",beer[k].beer_name);
printf("%d ",beer[k].beer_id);
printf("%s ",beer[k].beer_quantity);
printf("%s ",beer[k].beer_price);
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote