Create a structure named Book for storing book details such as title, author, edition, and price. Write a C program to input details for n books, find the highest expensive and the lowest priced books, and display their information.xxxaaaa1245yyyddd5100xxx aaaa 1 245
Question
Create a structure named Book for storing book details such as title, author, edition, and price. Write a C program to input details for n books, find the highest expensive and the lowest priced books, and display their information.xxxaaaa1245yyyddd5100xxx aaaa 1 245
Solution
Sure, here is a simple C program that does what you asked for:
#include <stdio.h>
#include <string.h>
// Define the structure
typedef struct {
char title[50];
char author[50];
int edition;
float price;
} Book;
int main() {
int n, i, maxIndex = 0, minIndex = 0;
printf("Enter the number of books: ");
scanf("%d", &n);
Book books[n];
// Input book details
for(i = 0; i < n; i++) {
printf("Enter title, author, edition and price of book %d: ", i+1);
scanf("%s %s %d %f", books[i].title, books[i].author, &books[i].edition, &books[i].price);
}
// Find the highest expensive and the lowest priced books
for(i = 1; i < n; i++) {
if(books[i].price > books[maxIndex].price) {
maxIndex = i;
}
if(books[i].price < books[minIndex].price) {
minIndex = i;
}
}
// Display their information
printf("The highest expensive book is %s by %s, edition %d, price %.2f\n", books[maxIndex].title, books[maxIndex].author, books[maxIndex].edition, books[maxIndex].price);
printf("The lowest priced book is %s by %s, edition %d, price %.2f\n", books[minIndex].title, books[minIndex].author, books[minIndex].edition, books[minIndex].price);
return 0;
}
This program first asks for the number of books, then for each book it asks for the title, author, edition and price. It then finds the book with the highest price and the book with the lowest price, and finally it prints the information of these two books.
Similar Questions
Develop an online book purchase system using structure concept in C and refer the following constraints.• Define structures to represent a book and a user. Include attributes such as book ID, title, author, price.• Use appropriate data types for each attribute and ensure encapsulation by making attributes private or protected.• Select suitable functions to add, delete, and display books in the structure.Input:2CSE101 C++ ProgrammingDennis Ritchie2000CSE102Python ProgrammingDavid Mark 2500Output:Do you want to delete Y or N? YCSE101Successfully deleted!Remaining RecordsCSE102Python ProgrammingDavid Mark 2500
Problem definition: You are working on a project to develop a book inventory management system for a local bookstore. The system is required to handle a large number of books efficiently. In this context, you have implemented a C program that takes user input for book details, such as title, author, category, and cost. The program then sorts and displays the books based on title, author, and cost. Input Format Enter the total count of books. Enter the book details, such as title, author, category, and cost for the n numbers of books. Output Format Display the sorted of the books. Sample Input 3 Blood Sheldon Crime 500 Tell me your dreams Sidney sheldon Crime 700 Hunger games Suzanne collins Fantasy 800 Sample Output Blood Sheldon Crime 500.00 Hunger games Suzanne collins Fantasy 800.00 Tell me your dreams Sidney sheldon Crime 700.00
Write a program to enter the names of books and their prices as inputs in a Dictionary. Perform the following operations for the purchase of the books by the customer.· Add more details of books to the dictionary· For books priced above 1000-2999 provides a discount of 5%· For books that are priced above 3000- 5000 provide a discount of 3% on the purchase· For books above 5000 provides a discount of 2%.· Books priced below 500 no discount is provided.Input format :The input consists of the book name and price.Then the choice (1 to enter more and 0 to stop).Output format :The output prints the initial and the final dictionary based on the conditions.Refer sample input and output for the formatting specifications.Sample test cases :Input 1 :Applies Stat25001Neural Networks60000Output 1 :[('Applies Stat', 2500), ('Data science Python projects', 300), ('Handbook Statistics', 18000), ('Hands on data science', 1160), ('Machine Learning', 4000), ('Neural Networks', 6000), ('Python and R', 7215)][('Applies Stat', 2375.0), ('Data science Python projects', 300), ('Handbook Statistics', 17640.0), ('Hands on data science', 1102.0), ('Machine Learning', 3880.0), ('Neural Networks', 5880.0), ('Python and R', 7070.7)]Input 2 :Applies Stat25001Neural Networks60001Artificial Intelligence52001Computer Networks25000Output 2 :[('Applies Stat', 2500), ('Artificial Intelligence', 5200), ('Computer Networks', 2500), ('Data science Python projects', 300), ('Handbook Statistics', 18000), ('Hands on data science', 1160), ('Machine Learning', 4000), ('Neural Networks', 6000), ('Python and R', 7215)][('Applies Stat', 2375.0),
1) What are Macros? Explain macros with an example program?2) What are structure pointers? .Write a C program that uses structure pointer to refer structure members(attributes) using the arrow (->) operator?3) Write a C program that uses “array of structures” to store 3(three) “BOOK” records based on“Book_Pages, Book_Price and Book_Name” and to display all the records of 3(three) Books.4) Explain an Array of pointers with syntax and examples.5) Explain about malloc(), calloc() and realloc() with examples? Differentiate between malloc()and calloc().6) What do you mean by conditional compilation in preprocessing directives? Explain with examples.7) Explain the concept of pointers to structures and self referential structure with examples.
Create a structure containing book information like accession number, name of author, book title and flag to know whether book is issued or not.Create a menu in which the following can be done.1 - Display book information2 - Add a new book3 - Display all the books in the library of a particular author4 - Display the number of books of a particular title5 - Display the total number of books in the library6 - Issue a book(If we issue a book, then its number gets decreased by 1 and if we add a book, its number gets increased by 1)
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.