How to write class that represent a book in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

class Book
{
public:
	void show(void);
	void set_title(char *s) { strcpy(title, s); };
	void set_author(char *s) { strcpy(author, s); };
	void set_edition(char *s) { strcpy(edition, s); };
	void set_price(float p) { price = p; };
	void set_date(char *m, int d, int y) { strcpy(month, m); day = d; year = y; };
	void set_review(char *s) { strcpy(review, s); };
	void set_language(char *s) { strcpy(language, s); };
	void set_ISBN10(char *s) { strcpy(ISBN10, s); };
	void set_ISBN13(char *s) { strcpy(ISBN13, s); };
	void set_pages(int p) { pages = p; };
	void set_publisher(char *s) { strcpy(publisher, s); };
private:
	char title[128];
	char author[32];
	char edition[24];
	float price;
	char month[10];
	int day, year;
	char review[1024];
	char language[24];
	char ISBN10[24];
	char ISBN13[24];
	int pages;
	char publisher[64];
};

void Book::show(void)
{
	cout << title << ", " << edition << " - " << month << " " << day << ", " << year << endl;
	cout << "by " << author << endl;
	cout << "Price: $" << price << endl;
	cout << "Review: " << endl;
	cout << review << endl;
	cout << "Language: " << language << endl;
	cout << "ISBN-10: " << ISBN10 << endl;
	cout << "ISBN-13: " << ISBN13 << endl;
	cout << "Publisher: " << publisher << endl;

};

int main()
{
	Book cpp;

	cpp.set_title("The C++ Programming Language");
	cpp.set_author("Bjarne Stroustrup ");
	cpp.set_edition("4th Edition");
	cpp.set_price(58.49);
	cpp.set_date("May", 19, 2013);
	cpp.set_review("The definitive new guide from C++ creator Bjarne Stroustrup. The "
		           "brand-new edition of the worlds most trusted and widely read "
		           "guide to C++, it has been comprehensively updated for the "
		           "long-awaited C++11 standard.");
	cpp.set_language("English");
	cpp.set_ISBN10("0321563840");
	cpp.set_ISBN13("978-0321563842");
	cpp.set_pages(1368);
	cpp.set_publisher("Addison-Wesley Professional");

	cpp.show();

	return 0;
}

/*
run:

The C++ Programming Language, 4th Edition - May 19, 2013
by Bjarne Stroustrup
Price: $58.49
Review:
The definitive new guide from C++ creator Bjarne Stroustrup. The brand-new editi
on of the worlds most trusted and widely read guide to C++, it has been comprehe
nsively updated for the long-awaited C++11 standard.
Language: English
ISBN-10: 0321563840
ISBN-13: 978-0321563842
Publisher: Addison-Wesley Professional

*/

 



answered Mar 18, 2018 by avibootz
edited Mar 19, 2018 by avibootz

Related questions

2 answers 210 views
1 answer 223 views
1 answer 167 views
1 answer 324 views
1 answer 218 views
1 answer 189 views
...