In: Computer Science
Please write in C++ as simple as possible
I want you to create a Book Class for a bookstore. I am not going to tell you what variables should go into it, that is for you to figure out (but you should have at least 5+). And then you must create a UML with all the variables and methods (like: the getters and setters, a default constructor, and a constructor that takes all the variables and finally the printValues() ).
Once you have the UML then create the three code files for the the Book.cpp file, and the Book.h file and the Main. In the main() create three book objects with values.
Book.h
#include<iostream>
#include<iomanip>
using namespace std;
class Book
{
private:
int ISBN;
string title, author, publication;
int rating;
double price;
public:
Book();
Book(int, string, string, string, int, double);
int getISBN();
string getTitle();
string getAuthor();
string getPublication();
int getRating();
double getPrice();
void setISBN(int);
void setTitle(string);
void setAuthor(string);
void setPublication(string);
void setRating(int);
void setPrice(double);
void printValues();
};
CODE SCREENSHOT :
Book.cpp
#include "Book.h"
Book::Book()
{
this->ISBN = 0;
this->title = this->author =
this->publication = "";
this->rating = 0;
this->price = 0.0;
}
Book::Book(int ISBN, string title, string author, string
publication, int rating, double price)
{
this->ISBN = ISBN;
this->title = title;
this->author = author;
this->publication = publication;
this->rating = rating;
this->price = price;
}
int Book::getISBN() { return ISBN; }
string Book::getTitle() { return title; }
string Book::getAuthor() { return author; }
string Book::getPublication() { return publication; }
int Book::getRating() { return rating; }
double Book::getPrice() { return price; }
void Book::setISBN(int ISBN) { this->ISBN = ISBN; }
void Book::setTitle(string) { this->title = title; }
void Book::setAuthor(string) { this->author = author; }
void Book::setPublication(string) { this->publication =
publication; }
void Book::setRating(int) { this->rating = rating; }
void Book::setPrice(double) { this->price = price; }
void Book::printValues()
{
cout << "ISBN: " << getISBN() <<
"\nTitle: " << getTitle() << "\nAuthor: " <<
getAuthor() << "\nPublication: " <<
getPublication()
<< "\nrating: " <<
getRating() << "\nPrice: $" << setprecision(2) <<
fixed << getPrice() << endl;
}
CODE SCREENSHOT :
Main.cpp
#include "Book.h"
int main()
{
Book book1(27718828, "Caesar and Cleopatra", "George
Bernard Shaw", "ABC Publishers", 4, 874.45);
Book book2(40012556, "Gulliver’s Travels", "Jonathan
Swift", "XYZ Publishers", 4, 520);
Book book3(18005351, "Invisible man", "H. G. Wells",
"DERF Publishers", 3, 389.99);
cout << "DISPLAYING ALL
BOOKS:\n---------------------\nBOOK 1:\n";
book1.printValues();
cout << "\n\nBOOK 2:\n";
book2.printValues();
cout << "\n\nBOOK 3:\n";
book3.printValues();
cout << endl << endl;
return 0;
}
CODE SCREENSHOT :
UML DIAGRAM :