Answer to Question #297458 in C++ for Rajen

Question #297458

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.

1
Expert's answer
2022-02-18T07:31:22-0500
#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();	
}

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