class bookType {public: void set BookTitle (string s)//sets the bookTitle to s v
ID: 3842847 • Letter: C
Question
class bookType {public: void set BookTitle (string s)//sets the bookTitle to s void set BookISBN (string ISBN)//sets the private member book ISBN to the parameter void setBookPrice (double cost);//sets the private member bookPrice to cost void setCopiesInstock (int noofCopies);//sets the private member copies Instock to noofcopies void print Info() const://prints the bookTitle, bookISBN, the bookPrice and the//copies Instock string getBookISBN() const;//returns the bookISBN double getBookPrice const;//returns the book Price int showQuantity Instock() const;//returns the quantity in stock void update Quantity (int addBooks);//adds addBooks to the quantityInstock, so that the quantity//in stock now has it original value plus the parameter sent//to this function Private: string bookTitle: string book ISBN: double price; int quantity;};Explanation / Answer
#ifndef BOOKTYPE
#define BOOKTYPE
#include <iostream>
#include <string>
using namespace std;
class BookType {
public :
void setBookTitle(string s);
void setBookISBN(string ISBN);
void setBookPrice(double const);
void setCopiesInStock(int noOfCopies);
void printInfo() const;
string getBookISBN() const;
double getBookPrice() const;
int showQuantityInStock() const;
void updateQuantity(int addBooks);
private:
string bookTitle;
string bookISBN;
double price;
int quantity;
};
#endif
---------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <string>
#include "BookType.h"
using namespace std;
void BookType::setBookTitle(string s)
{
bookTitle = s;
}
void BookType::setBookISBN(string isbn)
{
bookISBN = isbn;
}
void BookType::setBookPrice(double const p)
{
if (p >= 0)
price = p;
}
void BookType::setCopiesInStock(int noOfCopies)
{
if (noOfCopies >= 0)
quantity = noOfCopies;
}
string BookType::getBookISBN() const
{
return bookISBN;
}
double BookType::getBookPrice() const
{
return price;
}
int BookType::showQuantityInStock() const
{
return quantity;
}
void BookType::updateQuantity(int addBooks)
{
if (addBooks > 0)
quantity += addBooks;
}
void BookType::printInfo() const
{
cout << "[Title = " << bookTitle << ", ISBN = " << bookISBN << ", Price = " << price << ", Quantity = " << quantity << "] "<< endl;
}
---------------------------------------------------------------------------------------------------------------------------
// File to test the BookType class
#include<iostream>
#include <string>
#include "BookType.h"
using namespace std;
int main()
{
BookType
b1;
b1.setBookTitle("Wuthering Heights");
b1.setBookISBN("9987 4268 7625 7281");
b1.setCopiesInStock(100);
b1.setBookPrice(45.98);
b1.printInfo();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.