#include <iostream>
#include <string>
using namespace std;
class Book
{
private:
string publisher; // book publisher
string name; // name of a book
int quantity; // quantity of a book
double price; // price of one book
public:
Book(): publisher(""), name(""), quantity(1), price(0.0) { }
Book(string publish, string nam, int quantit, double pric):
publisher(publish), name(nam), quantity(quantit), price(pric) { }
~Book() { }
void Set(string pu, string na, int qu, double pr);
void SetName(string pu);
void SetPrice(double pr);
string GetPublisher() { return publisher; };
string GetName() { return name; };
int GetQuantity() { return quantity; };
double GetPrice() { return price; };
bool operator > (const Book & next);
};
void Book::Set(string pu, string na, int qu, double pr)
{
publisher = pu;
name = na;
quantity = qu;
price = pr;
}
void Book::SetName(string na)
{
name= na;
}
void Book::SetPrice(double pr)
{
price = pr;
}
bool Book::operator > (const Book & next)
{
return (price > next.price);
}
//----------------------
class Books
{
public:
static const int Cn = 100; // maximum number of books
private:
Book K[Cn]; // books data
int n; // quantity of books
public:
Books(): n(0) { }
~Books() { }
int Get() // returns quantity of books
{ return n; };
void Set(Book newBook) // add a new book to array of books
{ K[n++] = newBook; } // and pluses one to quantity of books
Book Get(int ind) // returns object by index
{ return K[ind]; }
double Sum();
};
double Books::Sum()
{
double sum = 0;
for (int i = 0; i < n; i++)
sum += K[i].GetPrice();
return sum;
}
double MaxPrice(Books & A) // finds maximum price of a book
{
if(A.Get() == 0) return -1;
Book curExpensiveBook = A.Get(0);
for (int i = 1; i < A.Get(); i++)
{
if(A.Get(i) > curExpensiveBook)
curExpensiveBook = A.Get(i);
}
return curExpensiveBook.GetPrice();
}
int main() {
// your code goes here
Books collection;
collection.Set(Book("John", "Book 1", 1, 10.0));
collection.Set(Book("Jack", "Book 1", 1, 5.0));
collection.Set(Book("John", "Book 1", 1, 20.0));
printf("Max price: %f\n", MaxPrice(collection));
return 0;
}