Hi, I am creating a library class, but i am a little confused on how to do these things:
-shows all library cards, and all library books, from an output file.
The library should initialize itself from 2 files (1 for library card data,
1 for book data) on startup, and save these config files on shutdown.
how would i go about doing this? create an object of library and assign it to ifstream file??? and what about the saving part?
-able to check in a book, check out a book.
For loop here, removing books from the array of books i've created???
-and able to add new books and and new cards.
dynamically allocate 'new' books and cards???
Any help/suggestions, would be greatly appreciated, Thank you.
Three classes i've made, Card, Book and Library.
below is the class Library:
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
|
#include <iostream>
#include "Card.h"
#include "Book.h"
using namespace std;
#ifndef LIBRARY_H
#define LIBRARY_H
class Library
{
private:
int numCards;
int numBooks;
Card numCardss[500];
Book numBookss[500];
//Book book;
//Card card;
public:
Library();
Library(int numCards, int numBooks);
void addBook()
{
//allocate new books here???
}
void addCard()
{
//allocate new cards here???
}
void showMenu()
{
cout << "Press 1 to view library cards: " << endl;
cout << "Press 2 to view current books: " << endl;
cout << "Press 3 to checkin a book: " << endl;
cout << "Press 4 to checkout a book: " << endl;
//cout << "Press 0 to exit the program. " << endl;
}
int doCommand(int command)
{
switch(command)
{
case 1:
cout << numCards << endl;
break;
case 2:
cout << numBooks << endl;
break;
case 3:
cout << addBook << endl;
case 4:
cout << addCard << endl;
default:
cout << "Invalid input, please try again." << endl;
}
}
};
#endif
|
and main:
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
|
#include <iostream>
#include <fstream>
#include "Library.h"
#include <string.h>
using namespace std;
void main()
{
ifstream infile; //input file
ofstream outfile; //output file
infile.open("cards.txt");
infile.open("books.txt");
/*if (!infile) //input file check
{
cerr << "One or more File(s) could not be opened!" << endl;
exit(1);
}*/
Library lib;
int command;
bool do_exit = false;
do
{
lib.showMenu();
cin >> command;
do_exit = lib.doCommand( command );
}
while ( do_exit == false );
infile.close();
outfile.close();
//system("pause");
}
|