Question

In: Computer Science

Create a C structure which stores information about a book. Each book should have the following...

Create a C structure which stores information about a book. Each book should have the following data: Author (string), Title (string), Publisher (string), Year (int), ISBN (int), Genre (string), Price (float). Write a C program which creates an array of 100 of these structures, then prompts the user to enter book information to fill the array. The data entry should stop when the array is full, or when the user enters 0 for the ISBN.

Solutions

Expert Solution

Answer:

Code:

#include <stdio.h>
struct Book {
    char author[20];
    char title[40];
    char publisher[20];
    int year;
    int isbn;
    char genre[5];
    float price;
};
int main(){
    struct Book books[100];
    int count = 0;
    do {
        int isbn;
        printf("\nEnter ISBN (or 0 to stop): ");
        scanf("%d", &isbn);
        if (isbn == 0)
            break;
        books[count].isbn = isbn;
        fflush(stdin);
        printf("Enter author: ");
        scanf("%[^\n]%*c", &books[count].author);
        printf("Enter title: ");
        scanf("%[^\n]%*c", &books[count].title);
        printf("Enter publisher: ");
        scanf("%[^\n]%*c", &books[count].publisher);
        printf("Enter year: ");
        scanf("%d", &books[count].year);
        fflush(stdin);
        printf("Enter genre: ");
        scanf("%[^\n]%*c", &books[count].genre);
        printf("Enter price: ");
        scanf("%f", &books[count].price);
        count += 1;
    }
    while(1);
    // remove lines C1 and C2 to print entered book details
    /*************************************** C1 ************************************************
    for(int i = 0; i < count; i++){
        printf("\nBook %d\nISBN: %d\nAuthor: %s", i+1, books[i].isbn, books[i].author);
        printf("\nTitle: %s\nPublisher: %s", books[i].title, books[i].publisher);
        printf("\nGenre: %s\nYear: %d\nPrice: %f\n", books[i].genre, books[i].year, books[i].price);
    }
    *************************************** C2 ************************************************/
    return 0;
}

Output:

If you want to print book details:

Code:

Output:


Related Solutions

Create a C structure which stores information about a student. Each student should be represented by...
Create a C structure which stores information about a student. Each student should be represented by a student ID (integer), first name, last name, day, month and year of birth, and program code (string). Write a C program which creates an array of 100 of these structures, then prompts the user to enter data from the keyboard to fill the array. If an ID of 0 is entered, data entry should finish, and the list of students should be printed...
Write C code to create a structure called time_of_day, which stores the current time in hours,...
Write C code to create a structure called time_of_day, which stores the current time in hours, minutes, and seconds. All the fields should be integers except for seconds, which should be a floating point value. Write a C function called check_time, which takes a pointer to a time_of_day structure as input, and return 1 if the time is valid (0 to 23 hours, 0 to 59 minutes, 0 to 59.999999 seconds) and 0 otherwise. Assume that times are stored in...
Consider a class Book that contains information about a Book. The class should has the following...
Consider a class Book that contains information about a Book. The class should has the following attributes: • The title of the book • The author of the book • Year of publication (e.g. 1994) • The number of people that have rated this book as a 1 (Terrible) • The number of people that have rated this book as a 2 (Bad) • The number of people that have rated this book as a 3 (OK) • The number...
In C create a program that stores contact info. The program must have the following features:...
In C create a program that stores contact info. The program must have the following features: Able to store First Name, Phone Number and Birthday (MM/DD/YYYY) Able to search for a specific contact using First Name, Phone Number and Birthday (find) Able to delete a specific contact using First Name, Phone Number and Birthday (delete) Print entire contact list Show number of entries in contact list Able to save Contact List to file (save) Able to load Contact List from...
In C#, declare structure named Person. The structure should have the following attributes of first name,...
In C#, declare structure named Person. The structure should have the following attributes of first name, last name, zip code, and phone number.
The following information is available after the Cash Book of T Stores was compared with their...
The following information is available after the Cash Book of T Stores was compared with their Bank Statement at 28 February 2018. Information 1. The Cash Book showed an overdraft of GHS10,100. 2. The Bank Statement showed a debit balance of GHS10,568. 3. The deposit of GHS7,654 does not appear on the Bank Statement. 4. Cheques not yet presented for payment:                      Nr. 511 GHS805                      Nr. 516 GHS690 5. The bank recorded the following in the current bank account...
C++ programming Complete the code to input and store all the information in the structure Book:...
C++ programming Complete the code to input and store all the information in the structure Book: title, author, year and pages. Complete the function print() with arguments and code to print a Book variable in the following format: Book title: <title> Book author: <name> Published in <year> Number of pages: <pages> #include <iostream> using namespace std; struct Book { string title; string author; string year; int pages; }; void print(/*arguments*/) { //Complete function } int main() { //Declare structure variable...
Java (a) Create a class Router which stores the information of a router. It includes the...
Java (a) Create a class Router which stores the information of a router. It includes the brand, the model number (String) and the price (double, in dollars). Write a constructor of the class to so that the information mentioned is initialized when a Router object is created. Also write the getter methods for those variables. Finally add a method toString() to return the router information in the following string form. "brand: Linksys, model number: RVS4000, price: 1080.0" Copy the content...
(a) Create a class Webcam which stores the information of a webcam. It includes the brand,...
(a) Create a class Webcam which stores the information of a webcam. It includes the brand, the model number (String) and the price (double, in dollars). Write a constructor of the class to so that the information mentioned is initialized when a Webcam object is created. Also write the getter methods for those variables. Finally add a method toString() to return the webcam information in the following string form. "brand: Logitech, model number: B525, price: 450.0" Copy the content of...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT