Create a class Book with title, author, and cost as data members. Include a constructor and a member function show Book () to set and print the member values respectively. Write main a method to demonstrate the Book class.
#include<iostream>
#include<string>
using namespace std;
class Book
{
string title;
string author;
double cost;
public:
Book(){}
Book(string _title, string _author, double _cost)
:title(_title), author(_author), cost(_cost){}
void SetBook()
{
cout<<"\nPlease, enter a title of book: ";
getline(cin,title,'\n');
cout<<"Please, enter an author of book: ";
getline(cin,author,'\n');
cout<<"Please, enter a cost of book: ";
cin>>cost;
}
void ShowBook()
{
cout<<"Title of book: "<<title
<<"\nAuthor of book: "<<author
<<"\nCost of book: "<<cost;
}
};
int main()
{
Book a("Adventures of Dunno","Nikolay Nosov",25);
a.ShowBook();
Book b;
b.SetBook();
b.ShowBook();
}
Comments
Leave a comment