|
|
|
list<T>
Class Problem - Book List
Problem description.
% cat book_list.cpp
// list class example
#include <iostream>
#include <iomanip>
using namespace std;
#include <list>
#include <string>
#include "item.h"
#include "book.h"
void display( list<Book> );
void inventory( list<Book> );
int main()
{
list<Book> book_list;
Book b1("Advanced C++", 125.50, 42, "John B. Good", 2008);
Book b2("Computers and You", 37.75, 9, "Jane Doe",
1992);
Book b3("All Who Wander", 25.50, 3, "Bilbo Baggins", 1937);
Book b4("Learn to Love Exams", 99.95, 987, "P. L. Ato",
2004);
book_list.push_back(b1);
book_list.push_back(b2);
book_list.push_back(b3);
book_list.push_back(b4);
display(book_list);
cout << "Reorder the following books:\n\n";
inventory(book_list);
return 0;
}
void display(list<Book> bList)
{
for( list<Book>::iterator it = bList.begin();
it != bList.end(); it++ )
{
(*it).invoice(cout);
cout
<< endl;
}
}
void inventory(list<Book> bList)
{
for( list<Book>::iterator it = bList.begin();
it != bList.end(); it++ )
{
if(
(*it).getInvent() < 10 )
{
(*it).invoice(cout);
cout << "Inventory = " << (*it).getInvent() <<
endl << endl;
}
}
}
% g++ book_list.cpp item.cpp book.cpp
% a.out
Book: Advanced C++
Author: John B. Good
Published: 2008
Price = $125.50
Book: Computers and You
Author: Jane Doe
Published: 1992
Price = $37.75
Book: All Who Wander
Author: Bilbo Baggins
Published: 1937
Price = $25.50
Book: Learn to Love Exams
Author: P. L. Ato
Published: 2004
Price = $99.95
Reorder the following books:
Book: Computers and You
Author: Jane Doe
Published: 1992
Price = $37.75
Inventory = 9
Book: All Who Wander
Author: Bilbo Baggins
Published: 1937
Price = $25.50
Inventory = 3
|
|