0

Hi, this program is supposed to get data from an input file, have the user add new data, then output the new data in an output file. There are also supposed to be inheritance classes for the different titles. The 2 derived classes should be a fiction one and a non-fiction one. I m quite a begginer at classes so i'm not sure how to carry on! Any help would be great, thanks!


------------------------header file------------------------------------------
#ifndef __BOOK_H__
#define __BOOK_H__

class Book
{
private:

char date[11];
int booknum;
char catnum[11];
char title[31];
char author[31];
char type;

public:
//constructor
Book();
//destructor
~Book();

//instance methods
void readdate(); //function to get data from input file
//void adddata(); //function to add new data
void outputdate(); //function to output data into output file


};

#endif

-------------------------------------------------------------------------------

-----------main.cpp---------------------------------------------------------

#include<iostream.h>
#include<stdlib.h>
#include<fstream.h>
#include<cstring>
#include"Book.h"

using namespace std;

int main()
{

return 0;

}
---------------------------------------------------------------------------------
----------implementation file-------------------------------------------------

#include<cstring>
#include"Book.h"

Book::Book()

Book::~Book()

void Book::readdate()
{
ifstream inFile;

inFile.open("BOOKS.dat");

inFile>>date;

cout<<date<<endl;

}

void Book::outputdate()
{
ofstream outFile;

outFile.open("NEWBOOKS.dat");

outFile<<date<<endl;


}

-------------------------------------------------------------------------

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Bench
0

it looks OK so far - Although I would suggest seperating your file input function out away from your book class, unless you want every single book object to hold exactly the same information (When you close a file and re-open it, the file reads from the start of the file again)

If you're satisfied with the book class at the moment, then your next step is probably to write your Fiction and Nonfiction classes

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.