Hi, I am doing a assignment in which I have to create classes to store information about my books. However it is not working because I am getting crazy output and I don't know what's wrong. I keep on trying different things but I cannot get it to work. I'd appreciate it if someone could look at it. I think the problem may lie in the data file, but I'm not sure. Here is my program:
This is my data file:Code:#include <iostream> #include <fstream> #include <string> using namespace std; const int SIZE = 15; ifstream file_in; ofstream file_out; class cover { public: string title; string first; string last; }; class inside { public: string genre; string publisher; int year; int pagenums; }; class book { public: cover coverinfo; inside insideinfo; }; void readdata (book [], int &); void printdata (book [], int); int main () { int n; book library [SIZE]; file_in.open ("program8in.dat"); file_out.open ("program8.out"); readdata (library, n); printdata (library, n); return 0; } void readdata (book library [], int &n) { file_in >> n; for (int count = 0; count < n; count++) { file_in >> library[count].coverinfo.title; file_in >> library[count].coverinfo.first; file_in >> library[count].coverinfo.last; file_in >> library[count].insideinfo.genre; file_in >> library[count].insideinfo.publisher; file_in >> library[count].insideinfo.year; file_in >> library[count].insideinfo.pagenums; } return; } void printdata (book library [], int n) { for (int count= 0; count < n; count++) { file_out << "\t" << library[count].coverinfo.title; file_out << "\t" << library[count].coverinfo.first; file_out << "\t" << library[count].coverinfo.last; file_out << "\t" << library[count].insideinfo.genre; file_out << "\t" << library[count].insideinfo.publisher; file_out << "\t" <<library[count].insideinfo.year; file_out << "\t" << library[count].insideinfo.pagenums; } return; }
And this is my output:Code:7 Harry Potter JK Rowling SciFi Scholastic 2003 870
I'm sorry about the length, I know it's rather long but I'm stuck.Code:Harry Potter JK Rowling SciFi 205936 196984 196984 196984 27 512 152 -2141497075 -445879994 2358840 198376 2089878893 211408 211408



LinkBack URL
About LinkBacks


