Create a struct that defines a new type BookType. It should store the following
ID: 3683546 • Letter: C
Question
Create a struct that defines a new type BookType. It should store the following about a book:
The author of the book
The title
The book's ISBN, a 10-character code that uniquely identifies a book
The book's publication year
The book's list price in dollars
Whether the book is hardcover or paperback.
Create a main program. In the main program, create two instances of bookType. Then fill up each record with valid information about two different books, where one is paperback and one is not.
You may simply hardcode this information with assignment statements. (If you want to do inputs, feel free, but that's not really the focus.)
The bookstore is having a sale on paperback books; they're all 10% off.
Check both books and change the prices on the paperbacks.
Sure, you could hardcode the records, but you should assume you don't know what they store and write your code generally.
Then figure out which book is cheaper.
Again, assume you don't know what's stored in records.
Print out the title, author, and price of the cheaper book.
Explanation / Answer
#include <stdio.h>
#include <string.h>
struct Books {
char title[50];
char author[50];
int ISBN[10];
int price;
};
int main( ) {
struct Books Book1;
struct Books Book2;
strcpy( Book1.title, "C");
strcpy( Book1.author, "Nuha Ali");
strcpy( Book1.ISBN, "123467890");
Book1.price = 250;
strcpy( Book2.title, "Telecom Billing");
strcpy( Book2.author, "Zara Ali");
strcpy( Book2.ISBN, "7654345678");
Book2.price = 500;
printf( "Book 1 title : %s ", Book1.title);
printf( "Book 1 author : %s ", Book1.author);
printf( "Book 1 subject : %s ", Book1.ISBN);
printf( "Book 1 book_id : %d ", Book1.price);
printf( "Book 2 title : %s ", Book2.title);
printf( "Book 2 author : %s ", Book2.author);
printf( "Book 2 subject : %s ", Book2.ISBN);
printf( "Book 2 book_id : %d ", Book2.price);
if(Book1.price>Book2.price)
{
printf( "Book 1 title : %s ", Book1.title);
printf( "Book 1 author : %s ", Book1.author);
printf( "Book 1 subject : %s ", Book1.ISBN);
printf( "Book 1 book_id : %d ", Book1.price);
}
else
{
printf( "Book 2 title : %s ", Book2.title);
printf( "Book 2 author : %s ", Book2.author);
printf( "Book 2 subject : %s ", Book2.ISBN);
printf( "Book 2 book_id : %d ", Book2.price);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.