1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <limits>
#include <string>
class BookType {
public:
BookType(std::string title_arg , std::string authors_arg[4],
std::string publisher_arg , int isbn_arg,
double price_arg , int num_copies_arg,
int another_member_arg)
: title { title_arg } , authors { authors_arg[0],
authors_arg[1],
authors_arg[2],
authors_arg[3] },
publisher { publisher_arg} , isbn { isbn_arg},
price { price_arg } , num_copies { num_copies_arg },
another_member { another_member_arg }
{}
private:
std::string title;
std::string authors[4];
std::string publisher;
int isbn;
double price;
int num_copies;
int another_member;
friend std::ostream& operator<<(std::ostream& os, const BookType& rhs)
{
os << "title: " << rhs.title << "; authors: { ";
for(int i{}; i<4; ++i) { os << rhs.authors[i] << ' '; }
os << "};\npublisher: " << rhs.publisher << "; isbn: " << rhs.isbn
<< "; copies: " << rhs.num_copies << "; and also: " << rhs.another_member;
return os;
}
};
void waitForEnter();
int main()
{
BookType book2 { "Sweet", new std::string[4] { "lil", "lool", "lal", "ln" },
"ssss", 2, 12292883.47, 8, 3 };
std::cout << book2 << '\n';
waitForEnter();
return 0;
}
void waitForEnter()
{
std::cout << "\nPress ENTER to continue...\n";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
title: Sweet; authors: { lil lool lal ln };
publisher: ssss; isbn: 2; copies: 8; and also: 3
Press ENTER to continue...
|