Question

Write a C program to create a list of books details. The details of a book...

Write a C program to create a list of books details. The details of a book include title, author, publisher, publishing year, no. of pages , price

Perform the following with respect to the list of books created

  1. Display all the details of books written by a given author.
  2. Sort the details of books in the increasing order of price.
  3. Display the details of books published by a given publisher in a given year.
  4. Sort the list of books in the increasing order of two fields , author and title of the books.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

typedef struct{

char title[20];

char author[20];

char publisher[20];

int pub_year;

int no_pages;

double price;

} BOOK;

void sortByPrice(BOOK *book, int n);

void sortByAuthorTitle(BOOK *book, int n);

int main(){

int n;

printf("How many books would you like to enter: ");

scanf("%d", &n);

BOOK *books = (BOOK *)malloc(n*sizeof(BOOK));

for(int i=0; i<n; i++){

printf("Enter book title: ");

scanf("%s", books[i].title);

printf("Enter book author: ");

scanf("%s", books[i].author);

printf("Enter book publisher: ");

scanf("%s", books[i].publisher);

printf("Enter book publishing year: ");

scanf("%d", &books[i].pub_year);

printf("Enter no of pages: ");

scanf("%d", &books[i].no_pages);

printf("Enter price: ");

scanf("%lf", &books[i].price);

}

char author[20];

printf("Enter author name: ");

scanf("%s", author);

int exists = 0;

for(int i=0; i<n; i++){

if(strcmp(books[i].author, author)==0){

printf("Book Title: %s\n", books[i].title);

printf("Book Publisher: %s\n", books[i].publisher);

printf("Book Publishing Year: %d\n",books[i].pub_year);

printf("Book No_of Pages: %d\n", books[i].no_pages);

printf("Book Price: %lf\n",books[i].price);

exists = 1;

}

}

if(!exists)

printf("No books found with author %s\n\n", author);

//sort by price

sortByPrice(books, n);

char publisher[20];

printf("Enter publisher name: ");

scanf("%s", author);

exists = 0;

for(int i=0; i<n; i++){

if(strcmp(books[i].publisher, publisher)==0){

printf("Book Title: %s\n", books[i].title);

printf("Book Publisher: %s\n", books[i].publisher);

printf("Book Publishing Year: %d\n",books[i].pub_year);

printf("Book No_of Pages: %d\n", books[i].no_pages);

printf("Book Price: %lf\n",books[i].price);

exists = 1;

}

}

if(!exists)

printf("No books found with publisher %s\n\n", publisher);

//sort by book author and title

sortByAuthorTitle(books, n);

for(int i=0; i<n; i++){

if(strcmp(books[i].publisher, publisher)==0){

printf("Book Title: %s\n", books[i].title);

printf("Book Publisher: %s\n", books[i].publisher);

printf("Book Publishing Year: %d\n",books[i].pub_year);

printf("Book No_of Pages: %d\n", books[i].no_pages);

printf("Book Price: %lf\n",books[i].price);

}

printf("\n");

}

return 0;

}

void sortByPrice(BOOK *books, int n){

for(int i=0; i<n; i++){

for(int j=i+1; j<n; j++){

if(books[i].price>books[i].price){

BOOK temp = books[i];

books[i] = books[j];

books[j] = temp;

}

}

}

}

void sortByAuthorTitle(BOOK *books, int n){

for(int i=0; i<n; i++){

for(int j=i+1; j<n; j++){

if(books[i].author>books[i].author && books[i].title>books[i].title){

BOOK temp = books[i];

books[i] = books[j];

books[j] = temp;

}

}

}

}

Add a comment
Know the answer?
Add Answer to:
Write a C program to create a list of books details. The details of a book...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please use C++ write a program to read a textfile containing a list of books. each...

    please use C++ write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. each line in the file has tile, ..... write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. Each line in...

  • Consider the following relation for published books: BOOK(Book title, Author_name, Book type, List price, Author affil,...

    Consider the following relation for published books: BOOK(Book title, Author_name, Book type, List price, Author affil, Publisher) Author_affil refers to the affiliation of author. Suppose the following dependencies exist: Book title Publisher, Book type Book type List price Author_name > Author affil (a) What normal form is the Book relation in? Why? (b) Decompose Book into 2NF relations. . (c) Decompose Book into 3NF relations.

  • Question: Consider the following relation for published books: BOOK (Book title, Author_name, Book_type, List_price, Author_affil, Publisher)...

    Question: Consider the following relation for published books: BOOK (Book title, Author_name, Book_type, List_price, Author_affil, Publisher) Author _affil refers to the affiliation of an author. Suppose the following dependencies exist Book_title Publisher, Book type Book-type → List-pricej Author name → Authoraffil - a. What normal form is the relation in? Explain your answer.

  • Write a program for the management of a bookstore in java, WITHOUT THE USE OF BOOK...

    Write a program for the management of a bookstore in java, WITHOUT THE USE OF BOOK CLASS, just arrays, strings, loops, etc. Overview; First menu 1. List all books 2. Search all books 3. Purchase books 4. Exit If option 1 is chosen: List all books by Title, Author, Price, Copies, Category within a group of arrays If option 2 is chosen: Search all books by Title, Author, Price, Copies, Category If option 3 is chosen: List books, List shopping...

  • Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use impl...

    Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...

  • Write a program for the management of a bookstore in Java Programming Language, WITHOUT THE USE...

    Write a program for the management of a bookstore in Java Programming Language, WITHOUT THE USE OF STUFF RELATING TO OBJECTS AND WHAT NOT, just arrays, strings, loops, etc. I'm in an intro to programming class so I haven't learned those techniques and am not allowed to use them. The books we just create Overview; Opening menu 1. List all books 2. Search all books 3. Purchase books 4. Exit If option 1 is chosen: List all books by Title,...

  • Create a program that has 4 lists. One list has the title of 5 books. Another...

    Create a program that has 4 lists. One list has the title of 5 books. Another list has the price of the 5 books and another list has the quantity of the 5 books. Put all 3 lists into a Master List(the fourth list). Using a loop print out the Title of each book and the value of the inventory (quantity * price) # The book "100 Years of Solitude" has an inventory value of $568.78 # Use Python

  • Consider an ABC digital library that manages technical books, the data requirements are summarized as follows:...

    Consider an ABC digital library that manages technical books, the data requirements are summarized as follows: A book is identified by its ISBN number, and it has a title, a price, and a date of publication. It is published by a publisher, which has its own ID number and a name. Each book has exactly one publisher, but one publisher typically publishes multiple books over time. A book is written by one or multiple authors. Each author is identified by...

  • Question: Instructions: A Well-known Online Bookstore Stores Its Data In A Special Database. The Website Has...

    Question: Instructions: A Well-known Online Bookstore Stores Its Data In A Special Database. The Website Has Customers. • Any Book Of The Bookstore Has A Title, Year, Price And ISBN. It Is Written By The Author And Published By The Publisher. The Author And Publisher Are Share Some Of Attributed Like Name, Address And URL Of Their Details. The Publisher Can ... This problem has been solved!

  • Write just one SQL statement per question 1. Display Publisher ID, Publisher Name and Total Number...

    Write just one SQL statement per question 1. Display Publisher ID, Publisher Name and Total Number of Books published by each publisher. 2. List Publisher ID, Publisher Name, Title and price of the highest priced book. 3. List Order ID, Customer ID, Order Date, and Number of Items in each order. Order the data by Customer ID in ascending (A – Z) order. 4. Display Title, Category and Profit for each book in the children and computer category. 5. Display...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT