chintseming
Technical User
question:
Develop a program to allow users to perform operations on book records.
A book record should contain the below minimum information:
· ISBN : 10 characters
· Title : 30 characters
· Author : 30 characters
· Price : floating point number
· Category : an enumerated type of SF-Science Fiction, HR-Horror, RM-Romance
· PublishedDate : date format in nested date structure type dd/mm/yyyy
You program should be able to store up to 10 book records in an array called BookArray
Your program should at least perform the below operations:
· Add book records in BookArray
· Display all book records
· Find and display book information given the ISBN
· Find all books written by a particular Author
· Delete book record given the Title
this is the program!
#include <stdio.h>
#include <string.h>
typedef enum
{
SF_Science_Fiction=0, HR_Horror=1, RM_Romance=2
} Category_Value;
typedef struct
{
char ISBN[10];
char Title[30];
char Author[30];
float Price;
Category_Value Category;
char PublishedDate[11];
} BkArray;
void add_records(BkArray []);
void display_all_records(BkArray []);
void display_information(char *IBSN, BkArray []);
void display_books(BkArray []);
void delete_records(char *title, BkArray library);
void BarLine(int num);
main()
{
//variables
int choice;
char ISBN[10];
BkArray library[10];
BarLine(30);
printf("\tMENU\n"
BarLine(30);
printf("1 - Add new records.\n"
printf("2 - Display all book records.\n"
printf("3 - Find and display book information given the ISBN.\n"
printf("4 - Find all books written by a particular author.\n"
printf("5 - Delete book record given the title.\n"
printf("\nEnter your choice: "
scanf("%d", &choice);
switch(choice)
{
case 1: add_records(library);
break;
case 2: display_all_records(library);
break;
case 3: printf("Enter ISBN: "
scanf("%s", ISBN);
break;
case 4: display_books(library);
break;
case 5: printf("Enter title: "
break;
default: printf("\nThere is no such choice.\n"
}
return 0;
}
void BarLine(int num)
{
for(int l = 0; l < num; l++)
printf("="
printf("\n"
}
void add_records(BkArray lib[])
{
int number;
printf("\nEnter the number of records that you are going to enter: "
scanf("%d", &number);
for(int k = 0; k < number; k++)
{
printf("\n#%d Record:\n", k+1);
BarLine(30);
printf("Enter ISBN: "
gets( lib[k].ISBN);
printf("\nEnter the title of the book: "
gets( lib[k].Title);
printf("\nEnter the author of the book: "
gets(lib[k].Author);
printf("\nEnter the price of the book: "
scanf("%f", &lib[k].Price);
printf("\nEnter the category of the book\n"
scanf("%d", &lib[k].Category);
printf("\nEnter the published date in the format of dd/mm/yyyy: "
gets (lib[k].PublishedDate);
}
}
void display_all_records(BkArray library[])
{
for (int p = 0; p != 9; p++)
{
printf("\n#%d Record:\n", p+1);
BarLine(30);
printf("ISBN: %s\n", library[p].ISBN);
printf("Title: %s\n", library[p].Title);
printf("Author: %s\n", library[p].Author);
printf("Price: %f\n", library[p].Price);
printf("Category: %s\n", library[p].Category);
printf("Published Date: %s\n", library[p].PublishedDate);
}
return;
}
void display_information(char *ISBN, BkArray library[])
{
for (int q = 0; q != 9; q++)
{
if (strcmp(library[q].ISBN,ISBN))
{
printf("Book Found!"
printf("ISBN: %s\n", library[q].ISBN);
printf("Title: %s\n", library[q].Title);
printf("Author: %s\n", library[q].Author);
printf("Price: %s\n", library[q].Price);
printf("Category: %s\n", library[q].Category);
printf("Published Date: %s\n", library[q].PublishedDate);
return;
}
}
printf("Book cannot be found!"
}
void display_books(BkArray lib[])
{
char author1[31];
printf("Enter author: "
scanf("%s", &author1);
for(int r = 0; r != 9; r++)
{
if(lib[r].Author == author1)
printf("%s\n", lib[r].Title);
}
}
void delete_records(char *title, BkArray library)
{
for (int i = 0; i < sizeof(library.BookArray); i++)
{
if(title == library.BookArray.title)
{
for (int j = i; j < sizeof(library.BookArray); j++)
library.BookArray[j].title =
library.BookArray[j++].title;
}
}
}
Develop a program to allow users to perform operations on book records.
A book record should contain the below minimum information:
· ISBN : 10 characters
· Title : 30 characters
· Author : 30 characters
· Price : floating point number
· Category : an enumerated type of SF-Science Fiction, HR-Horror, RM-Romance
· PublishedDate : date format in nested date structure type dd/mm/yyyy
You program should be able to store up to 10 book records in an array called BookArray
Your program should at least perform the below operations:
· Add book records in BookArray
· Display all book records
· Find and display book information given the ISBN
· Find all books written by a particular Author
· Delete book record given the Title
this is the program!
#include <stdio.h>
#include <string.h>
typedef enum
{
SF_Science_Fiction=0, HR_Horror=1, RM_Romance=2
} Category_Value;
typedef struct
{
char ISBN[10];
char Title[30];
char Author[30];
float Price;
Category_Value Category;
char PublishedDate[11];
} BkArray;
void add_records(BkArray []);
void display_all_records(BkArray []);
void display_information(char *IBSN, BkArray []);
void display_books(BkArray []);
void delete_records(char *title, BkArray library);
void BarLine(int num);
main()
{
//variables
int choice;
char ISBN[10];
BkArray library[10];
BarLine(30);
printf("\tMENU\n"
BarLine(30);
printf("1 - Add new records.\n"
printf("2 - Display all book records.\n"
printf("3 - Find and display book information given the ISBN.\n"
printf("4 - Find all books written by a particular author.\n"
printf("5 - Delete book record given the title.\n"
printf("\nEnter your choice: "
scanf("%d", &choice);
switch(choice)
{
case 1: add_records(library);
break;
case 2: display_all_records(library);
break;
case 3: printf("Enter ISBN: "
scanf("%s", ISBN);
break;
case 4: display_books(library);
break;
case 5: printf("Enter title: "
break;
default: printf("\nThere is no such choice.\n"
}
return 0;
}
void BarLine(int num)
{
for(int l = 0; l < num; l++)
printf("="
printf("\n"
}
void add_records(BkArray lib[])
{
int number;
printf("\nEnter the number of records that you are going to enter: "
scanf("%d", &number);
for(int k = 0; k < number; k++)
{
printf("\n#%d Record:\n", k+1);
BarLine(30);
printf("Enter ISBN: "
gets( lib[k].ISBN);
printf("\nEnter the title of the book: "
gets( lib[k].Title);
printf("\nEnter the author of the book: "
gets(lib[k].Author);
printf("\nEnter the price of the book: "
scanf("%f", &lib[k].Price);
printf("\nEnter the category of the book\n"
scanf("%d", &lib[k].Category);
printf("\nEnter the published date in the format of dd/mm/yyyy: "
gets (lib[k].PublishedDate);
}
}
void display_all_records(BkArray library[])
{
for (int p = 0; p != 9; p++)
{
printf("\n#%d Record:\n", p+1);
BarLine(30);
printf("ISBN: %s\n", library[p].ISBN);
printf("Title: %s\n", library[p].Title);
printf("Author: %s\n", library[p].Author);
printf("Price: %f\n", library[p].Price);
printf("Category: %s\n", library[p].Category);
printf("Published Date: %s\n", library[p].PublishedDate);
}
return;
}
void display_information(char *ISBN, BkArray library[])
{
for (int q = 0; q != 9; q++)
{
if (strcmp(library[q].ISBN,ISBN))
{
printf("Book Found!"
printf("ISBN: %s\n", library[q].ISBN);
printf("Title: %s\n", library[q].Title);
printf("Author: %s\n", library[q].Author);
printf("Price: %s\n", library[q].Price);
printf("Category: %s\n", library[q].Category);
printf("Published Date: %s\n", library[q].PublishedDate);
return;
}
}
printf("Book cannot be found!"
}
void display_books(BkArray lib[])
{
char author1[31];
printf("Enter author: "
scanf("%s", &author1);
for(int r = 0; r != 9; r++)
{
if(lib[r].Author == author1)
printf("%s\n", lib[r].Title);
}
}
void delete_records(char *title, BkArray library)
{
for (int i = 0; i < sizeof(library.BookArray); i++)
{
if(title == library.BookArray.title)
{
for (int j = i; j < sizeof(library.BookArray); j++)
library.BookArray[j].title =
library.BookArray[j++].title;
}
}
}