#include<iostream>
using namespace std;
class Book{
private:
string bookTitle, author, publication;
int yearOfPublication;
double price;
public:
void setBookDetails(string title, string a, string pub, int year, double pr){
cout<<"Enter the title of the book\n ";
cin>>title;
cout<<"Enter the author of the book\n ";
cin>>a;
cout<<"Enter the publication of the book\n ";
cin>>pub;
cout<<"Enter the book's year of publication\n ";
cin>>year;
cout<<"Enter the book's price\n ";
cin>>pr;
bookTitle = title;
author = a;
publication = pub;
yearOfPublication = year;
price = pr;
}
void display(){
cout<<"Book Title: "<<bookTitle<<endl;
cout<<"Book Author: "<<author<<endl;
cout<<"Book Publication: "<<publication<<endl;
cout<<"Book Year Of Publication: "<<author<<endl;
cout<<"Book Price: "<<price<<endl;
}
string getName(){
return bookTitle;
}
string getAuthor(){
return author;
}
double getPrice(){
return price;
}
};
int main(){
int n;
cout<<"Enter the number of books\n";
cin>>n;
Book books[n];
cout<<"Enter the details for the books\n";
for(int i=0; i<n; i++){
string title;
string a;
string pub;
int year;
double pr;
Book j;
cout<<"Book "<<(i+1)<<endl;
j.setBookDetails(title,a, pub,year, pr);
books[i] = j;
}
cout<<"The Details Entered are: \n";
for(int i=0; i<n; i++){
cout<<"Book "<<(i+1)<<endl;
books[i].display();
}
cout<<"\n\nDisplaying the Books' Names\n";
cout<<"Book Names:\n";
for(int i=0; i<n; i++){
cout<<books[i].getName()<<endl;
}
string author;
cout<<"\n\nEnter the name of the Author to display all books the author owns\n";
cin>>author;
for(int i=0; i<n; i++){
if(books[i].getAuthor()==author){
books[i].display();
}
}
cout<<"\n\nThe books having prices greater than 2000\n";
for(int i=0; i<n; i++){
if(books[i].getPrice() >2000){
books[i].display();
}
}
}
Comments
Leave a comment