Untitled
unknown
plain_text
10 months ago
9.4 kB
41
Indexable
book.h file #pragma once #include <iostream> #include "string" #include "vector" using namespace std; class Book{ int ISBNno; string name; string author; float cost; int status; vector<string> additionalAuthors; vector<string> bookcategory; public: Book(int ISBNno,string name,string author,float cost,int status); int getISBNno(void)const; string getAuthorname(void)const; string getBookname(void)const; void setStatus(int status); float getcost(void)const; void setcost(float cost); int getstatus(void)const; const vector<string> &getAdditionalAuthors(void)const; void addAdditionalAuthor(string author); void addAdditionalAuthor(vector<string> authors); const vector<string> &getCategories(void)const; void addCategories(string category); void addCategories(vector<string> categories); virtual void Lend(); virtual void Return(); virtual void Lost(); virtual void bookdetails()const; }; book.cpp #include "book.h" using namespace std; Book::Book(int ISBNno, string name, string author, float cost, int status) :ISBNno(ISBNno),name(name),author(author),cost(cost),status(status) { } int Book::getISBNno() const { return this->ISBNno; } string Book::getAuthorname() const { return this->author; } string Book::getBookname() const { return this->name; } float Book::getcost() const { return this->cost; } void Book::setcost(float cost) { this->cost = cost; } int Book::getstatus() const { return this->status; } const vector<string> &Book::getAdditionalAuthors(void) const { return this->additionalAuthors; } void Book::addAdditionalAuthor(string author) { this->additionalAuthors.push_back(author);} void Book::addAdditionalAuthor(vector<string> authors) { for(auto val: authors){ this->additionalAuthors.push_back(val); } } const vector<string> &Book::getCategories(void) const { return this->bookcategory; } void Book::addCategories(string category) { this->bookcategory.push_back(category); } void Book::addCategories(vector<string> categories) { for(auto val: categories){ this->bookcategory.push_back(val); } } void Book::Lend() { if(this->status == 0){ this->status=1; cout<<"you have succcessfully lended the book :"<<this->name<<endl; } else{ cout<<"The Book your are looking for is not available"<<endl; } } void Book::Return() { if(this->status==1){ this->status=0; cout<<"you have returned lended the book succcessfully :"<<this->name<<endl; } else{ cout<<"Book is not lended"<<endl; } } void Book::Lost() { if(this->status!=2){ this->status=2; cout<<this->name<<"Book is marked as Lost:"<<endl; } else{ cout<<"Book is already marked as Lost"<<endl; } } void Book::bookdetails() const { cout<<"ISBN NUmber is"<<this->ISBNno<<", Book name is " <<this->name<<" , AuthorName - "<<this->author<<" ,cost -"<<this->cost << ", status - "<<this->status << endl; cout << "Categories: "; for (auto val: this->bookcategory) { cout << val << ", "; } cout << endl; // Print additional authors cout << "Additional Authors: "; for (auto val:this->additionalAuthors) { cout << val << ", "; } cout << endl; } void Book::setStatus(int status) { this->status = status; } encylopedia.h #pragma once #include <iostream> #include "string" #include "vector" #include "book.h" using namespace std; class Encylopedia : public Book{ int type; string publisher; public: Encylopedia(int ISBNno,string name,string author,float cost,int type,string publisher); int getType(void) const; void setType(int type); const string getPublisher(void); void Refer(void); void Return(void) override; }; encylopedia.cpp #include "encylo.h" Encylopedia::Encylopedia(int ISBNno, string name, string author, float cost, int type, string publisher) : Book(ISBNno, name, author, cost, 1), type(type), publisher(publisher) { } void Encylopedia::Refer(void) { if (getstatus() == 1) { setStatus(4); } } void Encylopedia::Return(void) { if (getstatus() == 2 || getstatus() == 4) { setStatus(1); } } int Encylopedia::getType(void) const { return this->type; } void Encylopedia::setType(int type) { this->type=type; } const string Encylopedia::getPublisher(void) { return this->publisher; } fiction.h #pragma once #include <iostream> #include "string" #include "book.h" #include "vector" using namespace std; class Fiction : public Book{ int type; string region; public: Fiction(int ISBNno,string name,string author,float cost,int type,string region); int getType(void) const; const string getRegion(void); void setRegion(string region); void Buy(void); }; ficiton.cpp #include "fiction.h" Fiction::Fiction(int ISBNno, string name, string author, float cost, int type, string region) :Book(ISBNno,name,author,cost,1),type(type),region(region) { } int Fiction::getType(void) const { return this->type; } const string Fiction::getRegion(void) { return this->region; } void Fiction::setRegion(string region) { this->region=region; } void Fiction::Buy(void) { } movie.h #pragma once #include "string" using namespace std; class Movie{ protected: string title; string genere; int year; float rating; int status; public: Movie(string title,string genere,int year,float rating,int status); void Dispalydetails(); bool checkAvailablity(); void setAvailability(int availability); void Lend(); void returnmovie(); void lost(); }; movie.cpp #include "movie.h" using namespace std; #include <iostream> Movie::Movie(string title, string genere, int year, float rating,int status) :title(title),genere(genere),year(year),rating(rating),status(status) { ; } void Movie::Dispalydetails() { cout<<"Title :"<< this->title<<endl; cout<<"Genere :"<< this->genere<<endl; cout<<"Year :"<< this->year<<endl; cout<<"Rating :"<< this->rating<<endl; cout<<"Availability :"<< ((this->status ==1)? "Available":"Not Available")<<endl; } bool Movie::checkAvailablity() { if(this->status == 1){ return true; } else{ return false; } } void Movie::setAvailability(int availability) { this->status = availability; } void Movie::Lend() { if(this->status == 1){ this->status=2; cout<<"you have succcessfully lended the movie :"<<this->title<<endl; } else{ cout<<"The movie you are looking for is not available"<<endl; } } void Movie::returnmovie() { if(this->status==2){ this->status=1; cout<<"you have returned lended the movie succcessfully :"<<this->title<<endl; } else{ cout<<"movie is not lended"<<endl; } } void Movie::lost() { if(this->status!=3){ this->status=3; cout<<this->title<<"movie is marked as Lost:"<<endl; } else{ cout<<"movie is already marked as Lost"<<endl; } } cdmovie.h #pragma once #include "string" #include "movie.h" using namespace std; class CdMovie: public Movie{ public: CdMovie(string title,string genere,int year,float rating); void Refer(); void lend(); }; cdmovie.cpp #include "cdmovies.h" #include <iostream> using namespace std; CdMovie::CdMovie(string title, string genere, int year, float rating) :Movie(title,genere,year,rating,1) { } void CdMovie::Refer() { if(checkAvailablity()){ cout<<"you are refering to Title of the movie is :"<<this->title<<endl; } else{ cout<<"Title of the movie is not available to refer:"<<this->title<<endl; } } void CdMovie::lend() { if(checkAvailablity()){ cout<<" you have lend the cd movie"<<this->title<<endl; } else{ cout<<"Title of the movie is not available to lend:"<<this->title<<endl; } } webmovie.h #pragma once #include "string" #include "movie.h" using namespace std; class WebMovie: public Movie{ string url; int validdate; public: WebMovie(string title,string genere,int year,float rating,string url,int validdate); void Buy(); }; webmovie.cpp #include "webmovies.h" #include <iostream> using namespace std; WebMovie::WebMovie(string title, string genere, int year, float rating, string url, int validdate) :Movie(title,genere,year,rating,true),url(url),validdate(validdate) { } void WebMovie::Buy() { if(checkAvailablity()){ cout<<"you bought the movie :"<<this->title<<endl; setAvailability(false); } else{ cout<<"Movie is not available to purchase:"<<this->title<<endl; } } main.cpp #include "movie.h" #include <iostream> #include "webmovies.h" #include "cdmovies.h" #include <string> using namespace std; int main() { Movie movie("Harry porter","Fantasy",2000,4.5,1); CdMovie movie1("charlie","comedy",2018,4.9f); WebMovie movie2("avatar","fantasy",2010,5.9f,"ww.movies.com",3); movie1.lend(); movie1.Lend(); movie.Dispalydetails(); movie1.Dispalydetails(); movie1.returnmovie(); movie2.Dispalydetails(); movie2.Buy(); movie2.Buy(); return 0; }
Editor is loading...
Leave a Comment