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

Create a Book class which will include information such as the title, author and

ID: 2990884 • Letter: C

Question

Create a Book class which will include information such as the title, author and the current number of books in the library. Do this for 3 books. This class will have friend functions that allow the books to be seperated alphabetically, either by title or author, ignoring the first word of the title if that word is "the" or "a". The alphabetical sort by the authors last name should be the last name only and can ignor the first name. Sorting by the title should ignore spaces such that a letter sequence such as "...for mal..." and "...formal..." would be equivalent. Class Book should have: string title; //Holds the complete title of the book string authorFirst; //Holds authors first name and middle (if exists) name string authorLast; //Holds authors last name sring int bookCount; //Holds the current number of book objects in existence Class Book should also have the following functions: A default argument constructor supplying default author and title if none supplied by user. A display function - to display all data members of a Book object. Accessor functions - to access the title, author name and bookCount data members. Mutator functions - to sort the books by title or by author's last name, must be able to do either sort as selected by user. The main() driver function is to create an array of at least 10 pointers of class Book and initialize all data members to either the default values or allow the user to enter title and author information. The menu portion of main shoudl allow user to select and of the following: Add a new book using dynamic memory allocation Book author and title information are to be entered into a character array This then must be manipulated such that it is stored as a string in the book object. Edit a selected Book title. Delete a book. Allow user to delete a book by either title or author Must handle book not foud if no match found for title or author Must also properly realign the pointers so that there is no gap in the array Display all books. displayed as last sorted (or not) by the user Main() should perform array index checking to make sure no operation tries to utilize an object array element that doesn't exist. Menu entries should be accepted regardless of upper or lowercase entry

Explanation / Answer

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

#define max_input (3)

typedef struct book {
char title[100];
char author[100];

};

/*function prototypes*/
void input(struct book *books);
void searchData(int *searchCriteria, char search[100]);
void searchArray(struct book *books, int searchCriteria, char search[100]);

int main() {

struct book books[max_input];
char search[100];
int searchCriteria; //1 for search with title and 2 for search with author

input(books); //get input from user

searchData(&searchCriteria, search);

searchArray(books, searchCriteria, search);


return 0;
}

void input(struct book *books) {
int i;
for (i = 0; i < max_input; i++) {
printf("Enter data of book %d : ", (i+1));
printf("Title: ");
//fgets (books[i].title, 100, stdin);
scanf("%s", books[i].title);
printf("Author: ");
scanf("%s", books[i].author);
printf(" ");
  
}
}

void searchData(int *searchCriteria, char search[100]) {

printf(" 1. To search with title ");
printf("2. To search with author ");
printf("Enter search criteria: ");
  
scanf("%d", searchCriteria);
printf(" ");

printf("Enter search data: ");
scanf("%s", search);
printf(" ");


}

void searchArray(struct book *books, int searchCriteria, char search[100]) {
int flag = 0, i;
  
for (i = 0; i < max_input; i++) {
if (searchCriteria == 1) {
if (strcmp(books[i].title, search) == 0) {
flag = 1;
printf(" Found !! ");
printf("Book title: %s ", books[i].title);
printf("Book author: %s ", books[i].author);

return;
}
} else {
if (strcmp(books[i].author, search) == 0) {
flag = 1;
printf(" Found !! ");
printf("Book title: %s ", books[i].title);
printf("Book author: %s ", books[i].author);

return;
}
}
}

if (flag == 0)
printf(" Text not found ");
}

------------------------------------------------------

OUTPUT