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

Can anyone help me with this exercise? C code please! Write a program in C that

ID: 2081522 • Letter: C

Question

Can anyone help me with this exercise? C code please!

Write a program in C that simulates a book library database. We want to have two actions: Insert a new book record Print the list of all the available books and its features Each book has the following information: Title Author Year Price The program should ask the user what he wants to do: Insertion (1) Print (2) Exit(3) If the user chooses Insertion, he must be asked to enter all the information about the book. Once he finishes, he should get the message "A new record was created" and he should be returned to the initial choice (Insertion (1), Print (2), Exit(3)). If he chooses to print, the program should print all the book records that he has entered so far along with all the information. The program must run continuously until the user chooses Exit (3).

Explanation / Answer

#include <stdio.h>
int i=0,k=0;
struct library
{
char title[80];
char author[30];
int year;
int price;
};

void insert(struct library[]);
void display(struct library[]);

int main()
{
struct library data[20];
int choice;
while(1)
{
printf(" -------------------- ");
printf("Press 1 Insertion ");
printf("Press 2 Display ");
printf("Press 3 Exit ");
printf(" Enter choice(1-3) : ");
printf(" -------------------- ");
scanf("%d", &choice);
switch (choice)
{
case 1:
insert(data);
break;
case 2:
display(data);
break;
case 3:
exit(0);
}
}


return 0;
}

void insert(struct library list[80])
{
{
printf(" Enter data for Record #%d ", i + 1);

printf(" Enter title : ");
fflush(stdin);
gets(list[i].title);
printf("Enter author : ");
gets(list[i].author);
printf("Enter year : ");
scanf("%d", &list[i].year);
printf("Enter price : ");
scanf("%d", &list[i].price);
k=i;
i=i+1;
}
}

void display(struct library list[80])
{
int y;

printf(" title author year price ");
for (y = 0; y <= k; y++)
{
printf("%s %s %d %d ", list[y].title, list[y].author, list[y].year, list[y].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