Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This must be in C++. Create a struct that defines a new type BookType. It should

ID: 3683482 • 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

Hi below i have written the code for your reference,

#include "stdafx.h"

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

//! Main class of BookType.

class bookType {

private:

//! Data members.

string title;

string authors[4];

int n_authors;

string ISBN;

string publisher;

int year;

double price;

int copies;

public:

//! Constructor of objects.

bookType();

//! Destructor.

~bookType();

//! Set and get values.

void set_title(string str);

string get_title();

void clear_authors();

void add_author(string str);

string get_author(int number);

void set_ISBN(string str);

string get_ISBN();

void set_publisher(string str);

string get_publisher();

void set_year(int n);

int get_year();

void set_price(double n);

double get_price();

void set_copies(int n);

int get_copies();

void update_copies(int n);

//! Actions.

void show_title();

void show_copies();

void show_ISBN();

void show_publisher();

void show_price();

void show_authors();

void show_year();

//! 1 - equal, 0 - non-equal.

int compare_title(string str);

};

bookType::bookType() {

title = "";

authors[0] = "";

authors[1] = "";

authors[2] = "";

authors[3] = "";

n_authors = 0;

ISBN = "";

publisher = "";

year = 0;

price = 0;

copies = 0;

}

bookType::~bookType() {

}

void bookType::set_title(string str) {

title = str;

}

string bookType::get_title() {

return title;

}

void bookType::clear_authors() {

n_authors = 0;

}

void bookType::add_author(string str) {

if (n_authors < 4) {

authors[n_authors] = str;

n_authors++;

}

}

string bookType::get_author(int number) {

if (n_authors < number) {

return authors[number - 1];

}

else {

return "";

}

}

void bookType::set_ISBN(string str) {

ISBN = str;

}

string bookType::get_ISBN() {

return ISBN;

}

void bookType::set_publisher(string str) {

publisher = str;

}

string bookType::get_publisher() {

return publisher;

}

void bookType::set_year(int n) {

year = n;

}

int bookType::get_year() {

return year;

}

void bookType::set_copies(int n) {

if (n >= 0) copies = n;

}

int bookType::get_copies() {

return copies;

}

void bookType::set_price(double n) {

if (n >= 0) price = n;

}

double bookType::get_price() {

return price;

}

void bookType::update_copies(int n) {

if (n >= 0) copies += n;

}

void bookType::show_title() {

cout

<< "Title:"

<< title

<< endl;

}

void bookType::show_copies() {

cout

<< "Copies in stock:"

<< copies

<< endl;

}

void bookType::show_ISBN() {

cout

<< "ISBN:"

<< ISBN

<< endl;

}

void bookType::show_publisher() {

cout

<< "Publisher:"

<< publisher

<< endl;

}

void bookType::show_price() {

cout

<< "Price:"

<< setprecision(2)

<< fixed

<< price

<< endl;

}

void bookType::show_year() {

cout

<< "Year of publish:"

<< year

<< endl;

}

void bookType::show_authors() {

int i = 0;

cout

<< "Author(s):"

<< n_authors

<< endl;

for(i = 0;i < n_authors; i++) {

cout << authors[i] << " ";

}

cout << endl;

}

int bookType::compare_title(string str) {

int x = (str == title);

return x;

}

int main()

{

bookType a[100];

int i;

for(i = 0; i < 5; i++) {

a[i].add_author("Newton");

a[i].add_author("Kepler");

a[i].set_copies(100-i);

a[i].set_ISBN("123-123-123");

a[i].set_price(100.01+i*i);

a[i].set_publisher("Piter");

a[i].set_title("Star moving");

a[i].set_year(1660+i);

}

for(i = 0; i < 5; i++) {

a[i].show_authors();

a[i].show_copies();

a[i].show_ISBN();

a[i].show_price();

a[i].show_publisher();

a[i].show_title();

a[i].show_year();

}

cout << "Compare(one) " << a[0].compare_title("No one") << endl;

cout << "Compare(two) " << a[0].compare_title("Star moving") << endl;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote