hey,
Thanks for all your ideas, I still cannot get it to work right, I have now put this in main
ifstream fin; fin.open (inFile); book cbook[500];loadlist(cbook, fin);
Then this in the loadlist function;
string temp; int total =0; ifstream fin; fin.open (inFile); for (int x = 0; x < 500; x++) { while (!fin.eof()) { getline (fin, temp); total++; }
And I sort of get what I want, but not really. I cannt tell how to manipulate that array I have created, or pass a value to it or take one from it.
Below is the entire code as it lasy so far, and any ideas are awesome... I''m glad I have two weeks to get this working
#include <fstream>#include <iostream>#include <string>#include <cmath>#include <iomanip>#include <cctype>using namespace std;const int total = 5;#define inFile "Booklist.txt"#define outFile "Booklist2.txt"void display();void search();void add();int menu(int);class book{ public: book (); //default constructor book (string, string, string, string, string, string); //non-default string BookCode; string Year, Price; string FName, LName, Title; private: };book::book (){ //cout << "in Default contructor\n"; BookCode = "5555555555"; Year = "2000"; Price = "50"; FName = "John"; LName = "Doe"; Title = "Reading for Dummies";}book::book (string bc, string yr, string pr, string fn, string ln, string ti){ //cout << "In non-default constructor\n"; BookCode = bc; Year = yr; Price = pr; FName = fn; LName = ln; Title = ti;}void loadlist (book[], ifstream &);void main (){ ifstream fin; fin.open (inFile); book cbook[500];//500 is MAX size of book listloadlist(cbook, fin); //menu(1);//MENU TURNED OFF system ("pause");}int menu (int x)//SKELETON MENU SYSTEM{cout << "Welcome to the Book Cataloging System\n please make your choice below: \n";cout << "(1) Display Catalog.\n";cout << "(2) Search the Catalog. \n";cout << "(3) Add a book to the catalog. \n";cout << "(4) Quit. \n";cin >> x;switch (x){ case 1 : display(); break; case 2 : search(); break; case 3: add(); break; case 4 : exit(1); break;}return 1;}void display()//PLACEHOLDER{ cout << "DISPLAYING LIST\n";}void search()//SKELETON FOR SEARCH TOOL{ char y; cout << "Search List by..\n Author (F)irst name, (L)ast name or (B)ook code?\n"; cout << "Enter (F), (L) or (B): " <<endl; cin >> y; switch (y) { case ''f'' : cout << "SEARCHING BY FIRST NAME...\n"; break; case ''F'' : cout << "SEARCHING BY FIRST NAME...\n"; break; case ''l'' : cout << "SEARCHING BY LAST NAME...\n"; break; case ''L'' : cout << "SEARCHING BY LAST NAME...\n"; break; case ''b'' : cout << "SEARCHING BY BOOK CODE...\n"; break; case ''B'' : cout << "SEARCHING BY BOOK CODE...\n"; break; default: cout << "INVALID\n"; break; }}void add()//PLACEHOLDER FOR FUNCTION{ cout << "ADD A BOOK";}void loadlist (book inout[], ifstream & inF ){ string temp; int total =0; ifstream fin; fin.open (inFile); for (int x = 0; x < 500; x++) { while (!fin.eof()) { getline (fin, temp); total++; } } cout << total; system ("pause");fin.seekg(0);//Used to GOTO start of file for (int i = 0; i < total; i++) { getline (inF, inout[i].BookCode, ''\t''); getline (inF, inout[i].FName, ''\t''); getline (inF, inout[i].LName, ''\t''); getline (inF, inout[i].Title, ''\t''); getline (inF, inout[i].Year, ''\t''); getline (inF, inout[i].Price, ''\n''); //inF.ignore (1); cout << inout[i].BookCode; cout << " " << inout[i].FName; cout << " " <<inout[i].LName; cout << " " <<inout[i].Title; cout << " " <<inout[i].Year; cout << " " <<inout[i].Price <<endl; }fin.close ();}
Ok thats it!
I can;t belive how much fun C++ is , although as you can clearly see I''m JUST LEARNING it is a blast!