Answer to Question #296487 in C++ for Fatimah

Question #296487

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.

1
Expert's answer
2022-02-11T07:43:54-0500
#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";


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog