Write a list of book using structures defining parameters. (5 at least)
o Name (String) – Topic (String) – Pages (int) – IsEnglishLanguage (bool) – Price
(float)
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();
}
Comments
Leave a comment