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 58 59 60 61 62 63 64 65 66 67 68 69 70
|
// Book Library.cpp : main project file.
#include<iostream>
#include<string>
#include <vector>
using namespace std;
struct BOOK
{
string NAME; // you don't need this to be an array; removed [100]
int YEAR;
int PAGES;
string FIRSTNAME;
string LASTNAME;
string LANGUAGE;
bool READ;
int SCORE;
// constructor
BOOK( const string & name, int year, int pages, string firstname, string lastname, string language, bool read, int score )
: NAME(name), YEAR( year ), PAGES( pages ), FIRSTNAME( firstname ), LASTNAME( lastname ), LANGUAGE( language ), READ( read ), SCORE( score ) {};
};
// Then, to construct a single BOOK object:
vector< BOOK > container;
container.push_back( BOOK( "Eragon", 2002, 509, "Christopher", "Paolini", "eng", true, 7 ) );
container.push_back( BOOK( "Eldest", 2005, 668, "Christopher", "Paolini", "eng", true, 6 ) );
container.push_back( BOOK( "Brisingr", 2008, 748, "Christopher", "Paolini", "eng", true, 7 ) );
container.push_back( BOOK( "Fellowship Of The Ring", 1954, 531, "Christopher", "Tolkien", "eng", true, 10 ) );
container.push_back( BOOK( "The Hobbit", 1937, 310, "Christopher", "Tolkien", "eng", true, 10 ) );
container.push_back( BOOK( "Ender's Game", 1985, 357, "Orson Scott", "Card", "eng", true, 10 ) );
container.push_back( BOOK( "Lost Symbol", 2009, 639, "Dan", "Brown", "eng", false, 8 ) );
container.push_back( BOOK( "Harry Potter and the Philosopher's Stone", 1997, 309, "Joanne", "Rowling", "eng", false, 8 ) );
container.push_back( BOOK( "A brief history of time", 1988, 256, "Stephen", "Hawking", "eng", true, 10 ) );
container.push_back( BOOK( "Game of thrones", 1996, 672, "George Raymond Richard", "Martin", "eng", true, 8 ) );
container.push_back( BOOK( "Eye of the World", 1990, 688, "Robert", "Jordan", "eng", true, 10 ) );
container.push_back( BOOK( "The Great Hunt", 1990, 660, "Robert", "Jordan", "eng", false, 8 ) );
container.push_back( BOOK( "The Dragon Reborn", 1991, 628, "Robert", "Jordan", "eng", true, 9 ) );
container.push_back( BOOK( "The Shadow Rising", 1992, 1001, "Robert", "Jordan", "eng", true, 10 ) );
container.push_back( BOOK( "Dune", 1965, 412, "Frank", "Herbert", "eng", true, 9 ) );
container.push_back( BOOK( "Beginning C++ through game programming, 3rd Ed.", 2011, 410, "Michael", "Dawson", "eng", true, 10 ) );
int main()
{
//FILE *Library;
//Library = fopen("BOOK", "r");
// process book
for( std::vector< BOOK >::iterator i = container.begin(); i != container.end(); ++i )
{
BOOK & book = *i;
cout << book.NAME<< " " << book.YEAR << " " << Book.PAGES << " " << Book.FIRSTNAME << " " << Book.LASTNAME << " " << Book.LANGUAGE << " " << Book.SCORE;
if ( Book.READ == true)
cout << " READ\n";
else
cout << " NOT READ\n";
if((i+1)%5==0)
{
cout << "\n\nPress any key for next 5 titles..\n";
cin.ignore();
}
}
return 0;
}
|