c++ calculating book age

Hi guys, I'm new to c++ and i cant seem to figure out a problem I'm having to calculate the ages of multiple books given in a text file (Title, Author, year of publication, dewey number).

I have to calculate the age from the year of publication and then display all the books and their details (title, author, year, dewey, and age) with the oldest on the top. *the age is not given, it must be calculated.

2 book examples of the .txt file where the book details are stored is:

Jane Eyre
Charlotte Bronte
1847
521.34
Biggles of the Camel Squadron
Capt W.E. Johns
1934
389.34

Here is my code so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main () {
string line;
ifstream file ("books.txt");
if (file.is_open())
{
while ( file.good() )
{
getline (file,line);
cout << line << endl;
}
file.close();
}

else cout << "File cannot be opened"; 
system("pause");
return 0;
}


I want to know how to read the lines in the constructor, assign the member variables accordingly and then add the 'Book' object just created to either a 'std::list<Book>' or a 'std::vector<Book>'

any help is greatly appreciated

****

The original question is:

Setup a class to store a book. The data is to include title, author, year of publication, dewey number and age. The class should include functions to read title, author, year and dewey number from a file, to determine the age of the book and to display that book’s details on screen. The main program should contain an array of book objects which are used in conjunction with the file to load all books from the file.
Well what output do you get when you run the program?
I get the full book list with that code. I want that but I want to range it in order. All detail of the books is on separate lines so book 1 is:
Biggles of the Camel Squadron
Capt W.E. Johns
1934
389.34

and book 2:
Jane Eyre
Charlotte Bronte
1847
521.34

and so on, theres about 10 books.
From the age of the book, I want to display in order oldest to youngest books..
Topic archived. No new replies allowed.