Answer to Question #297011 in C++ for Ahmad

Question #297011

Write a list of book using structures defining parameters. (5 at least)

o Name (String) – Topic (String) – Pages (int) – IsEnglishLanguage (bool) – Price

(float)


1
Expert's answer
2022-02-12T10:07:53-0500
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: ";
		getline(cin, Name, '\n');
		cout << "Please, enter a Topic of book: ";
		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;
	}
};




int main()
{
	Book a;
	a.SetData();
	a.Display();
	Book b("Amazon`s forest", "Adventures", 300, true, 50);
	b.Display();




}

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