Problem 1: bookType
Design a bookType class that defines the book as an ADT. Some of the characteristics of a book are the title, author(s), publisher, ISBN, price, and year of publication. You only need to design the interface (.h file) and not the implementation (.cpp file)
bookType.h :
#include <iostream>
#include <vector>
#include<string>
#include <algorithm>
using namespace std;
class bookType
{
private:
string title;
int nauthor;
vector <string> author;
string publisher;
string ISBN;
int copies;
int price;
string YearOfPub;
public:
bookType()
{
vector <string> temp(0,"");
title = "";
nauthor = 0;
author = temp;
publisher = "";
ISBN = "";
copies = 0;
price=0;
YearOfPub = "";
}
bookType(string t,vector <string> a,string p,string i, int c,int pr,string y)
{
title = t;
author = a;
nauthor = author.size();
publisher = p;
ISBN = i;
copies = c;
price=pr;
YearOfPub = y;
}
void setTitle(string s)
{
title = s;
}
bool isTitle(string s)
{
return (s==title);
}
string getTitle()
{
return title;
}
void setCopies(int n)
{
copies = n;
}
int getCopies()
{
return copies;
}
void updateCopies(int n)
{
setCopies(n);
}
void setPublisher(string s)
{
publisher = s;
}
string getPublisher()
{
return publisher;
}
bool isPublisher(string s)
{
return (publisher==s);
}
void setISBN(string s)
{
ISBN = s;
}
string getISBN()
{
return ISBN;
}
bool checkISBN(string s)
{
return (ISBN==s);
}
void setPrice(int n)
{
price = n;
}
int getPrice()
{
return price;
}
void updatePrice(int n)
{
setPrice(n);
}
void addAuthor(string s)
{
author.push_back(s);
nauthor++;
}
void removeAuthor(string s)
{
vector <string>::iterator it =find(author.begin(),author.end(),s);
if(it !=author.end())
{
author.erase(it);
nauthor--;
}
else
cout <<s<<" not found in the list of authors";
}
bool isAuthor(string s)
{
vector <string>::iterator it = find(author.begin(),author.end(),s);
return(it!=author.end());
}
vector <string> getAuthor()
{
vector <string> temp;
if(nauthor>0)
return author;
else
cout<<"No authors added";
return temp;
}
void setYearOfPub(string s)
{
YearOfPub = s;
}
string getYearOfPub()
{
return YearOfPub;
}
bool isYearOfPub(string s)
{
return YearOfPub==s;
}
int getNAuthor()
{
return nauthor;
}
void printAuthor()
{
if(author.size()==0)
cout<<"No authors added";
else
{
for(int i=0; i < author.size(); i++)
cout << author.at(i) << "\n";
}
}
};
main(for testing) :
#include "bookType.h"
int main()
{
vector <string> temp(0,"");
bookType book1("Charles Darwin",temp,"Penguin Publishiong","ISBN1201231",10,100,"1984");
cout<<book1.getPrice()<<"\n"<<book1.getYearOfPub()<<"\n"<<book1.getISBN()<<"\n"<<book1.getCopies()<<"\n"<<book1.getTitle()<<"\n";
book1.addAuthor("Hello");
book1.addAuthor("Mr Beast");
book1.printAuthor();
book1.removeAuthor("Hello");
book1.printAuthor();
cout<<book1.isAuthor("Mr Beast");
vector <string> a = book1.getAuthor();
cout<<a[0];
book1.setPrice(10);
book1.setTitle("Charles Darwin");
book1.addAuthor("Mike Pence");
book1.setYearOfPub("1984");
return 10;
}
I've tested all the methods that I found complex, please let me know if it works!
Get Answers For Free
Most questions answered within 1 hours.