1. Write a list of book defining parameters. (5 at least)
o Name (String) – Topic (String) – Pages (int) – IsEnglishLanguage (bool) – Price
(float). 2.Declare and initialize the variables of book parameters. 3.Take input from user and output all parameters given by the user. 4.Create a Function to analyze book parameter taken from user.
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class Book
{
string Name;
string Topic;
int Pages;
bool IsEnglishLanguage;
float Price;
public:
Book(){}
Book(string _Name, string _Topic, int _Pages, bool _IsEnglishLanguage,
float _Price):Name(_Name),Topic(_Topic),Pages(_Pages),
IsEnglishLanguage(_IsEnglishLanguage),Price(_Price){}
void SetData()
{
cout<<"Please, enter a Name of book: ";
cin>>Name;
cout<<"Please, enter a Topic of book: ";
cin.ignore(256,'\n');
getline(cin,Topic,'\n');
cout<<"Please, enter a number of Pages in book: ";
cin>>Pages;
cout<<"Is book in English Language? [y/n]: ";
char c;
cin>>c;
if(c=='y'||c=='Y')IsEnglishLanguage=true;
else IsEnglishLanguage=false;
cout<<"Please, enter Price of book: ";
cin>>Price;
}
void Display()
{
cout<<"\nInfo about book:"
<<"\nName: "<<Name
<<"\nTopic: "<<Topic
<<"\nPrice: "<<Price
<<"\nIn English: "<<boolalpha<<IsEnglishLanguage
<<"\nPrice: "<<Price;
}
bool Analize(const Book& b)
{
if(Name==b.Name&&Topic==b.Topic&&Pages==b.Pages&&
IsEnglishLanguage==b.IsEnglishLanguage&&Price==b.Price)
return true;
else
return false;
}
};
int main()
{
Book a;
a.SetData();
a.Display();
Book b("Amazon`s forest","Adventures",300,true,50);
Book c("Sea Walker","Adventures",250,true,40);
Book d("Amazon`s forest","Adventures",300,true,50);
cout<<endl;
if(b.Analize(c))
cout<<"Books b and c is equal";
else
cout<<"Books b and c is not equal";
cout<<endl;
if(b.Analize(d))
cout<<"Books b and d is equal";
else
cout<<"Books b and d is not equal";
}
Comments
Leave a comment