This must be in C++. Create a struct that defines a new type BookType. It should
ID: 3683479 • Letter: T
Question
This must be in C++.
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.
The bookstore is having a sale on paperback books; they're all 10% off.
Check both books and change the prices on the paperbacks.
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
Answer -
#include <iostream>
#include <string>
using namespace std;
struct BookType
{
string author, title, ISBN, publication_year, binding;
int book_price;
};
int main()
{
BookType b1,b2;
b1.author="mike james";
b1.title="a tale";
b1.ISBN="a1b1c1d1e1";
b1.publication_year="2010";
b1.book_price=100;
b1.binding="hardcover";
b2.author="Steve james";
b2.title="saga story";
b2.ISBN="a2b2c2d2e2";
b2.publication_year="2011";
b2.book_price=100;
b2.binding="paperback";
if(b1.binding=="paperback")
{
b1.book_price=b1.book_price-(b1.book_price/10);
}
if(b2.binding=="paperback")
{
b2.book_price=b2.book_price-(b2.book_price/10);
}
if(b1.book_price>b2.book_price)
{
cout<<" Author Name : "<<b2.author;
cout<<" Book title : "<<b2.title;
cout<<" Book ISBN : "<<b2.ISBN;
cout<<" Publication Year : "<<b2.publication_year;
cout<<" Book Price : "<<b2.book_price;
cout<<" Binding : "<<b2.binding;
}
else
{
cout<<" Author Name : "<<b1.author;
cout<<" Book title : "<<b1.title;
cout<<" Book ISBN : "<<b1.ISBN;
cout<<" Publication Year : "<<b1.publication_year;
cout<<" Book Price : "<<b1.book_price;
cout<<" Binding : "<<b1.binding;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.