This must be in C++. Create a struct that defines a new type BookType. It should
ID: 3683483 • 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
#include <iostream>
#include <stdio.h>
using namespace std;
struct BookType
{
string author;
string title;
string ISBN;
string year;
float price;
bool paperback;
};
struct BookType book[2];
int main()
{
book[0].author = "Udit Chawla";
book[0].title = "What Went wrong";
book[0].ISBN = "CN12232111";
book[0].year = "12-07-1984";
book[0].price = 22.64;
book[0].paperback = 1;
book[1].author = "Chetan bhagat";
book[1].title = "2 States";
book[1].ISBN = "GG12327685";
book[1].year = "31-06-1991";
book[1].price = 22.14;
book[1].paperback = 0;
if(book[0].paperback == 1) // check for paperback
{
book[0].price = book[0].price - book[0].price*0.1; // 10% discount
}
if(book[0].price < book[1].price) // find cheaper book
{
cout << "Sale on paperback books ";
cout << "Cheaper book: ";
cout << "Title: " << book[0].title << endl;
cout << "Author: " << book[0].author << endl;
cout << "Price: " << book[0].price << endl;
}
else
{
cout << "Cheaper book: ";
cout << "Title: " << book[1].title << endl;
cout << "Author: " << book[1].author << endl;
cout << "Price: " << book[1].price << endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.