I am creating a database that allows a user to add, search, browse, delete and edit a book into the system, which saves into a CSV file. I am trying to use three-tier hierarchical structure, 3 levels of inheritance, a double/linked list or a binary tree with as many of my functions throw exceptions and call exceptions being put in a catch block.
I have been trying many things and it got to the point where I was getting so many errors that I have decided to restart and take it one step at a time. The first structure I built was quite poor and my classes were not correct at all!
This time round, I am fairly confident with my classes but I am struggling to understand how to pull access to private member functions. I have created my classes in a header file
#include <string>
using std::string;
//Root class that all books will inherit from
class bookBase
{
private:
string publisher;
string title;
public:
void setBookPublisher(string bookPublisher)
{
publisher = bookPublisher;
}
string getBookPublisher()
{
return publisher;
}
void setBookTitle(string bookTitle)
{
title = bookTitle;
}
string getBookTitle()
{
return title;
}
};
//searchable book
class searchableBook : public bookBase
{
private:
double ISBNNumber;
public:
void setBookISBN(int bookISBN)
{
ISBNNumber = bookISBN;
}
int getBookISBN()
{
return ISBNNumber;
}
};
//general book class
class book : public searchableBook
{
private:
string author;
public:
void setBookAuthor(string bookAuthor)
{
author = bookAuthor;
}
string getBookAuthor()
{
return author;
}
};
//proceedings book class
class proceedingsBook : public searchableBook
{
private:
string editor;
int conferenceDate;
public:
void setBookEditor(string bookEditor)
{
editor = bookEditor;
}
string getBookEditor()
{
return editor;
}
void setBookConfDate(int bookConfDate)
{
conferenceDate = bookConfDate;
}
int getBookConfDate()
{
return conferenceDate;
}
};
and my main code in the .cpp file which is where the problem lies.
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include "bookSystem.h"
using namespace std;
book* buildG(string dataLine);
proceedingsBook* buildP(string dataLine);
void displayG(book* gPtr);
void displayP(proceedingsBook* pPtr);
string extractLastString(string & st);
int extractLastInt(string & st);
int _tmain(int argc, _TCHAR* argv[])
{}
void displayG(book* gPtr)
{
cout << "Book Title: " << gPtr->title << endl;
cout << "Book Author: " << gPtr->author << endl;
cout << "Book Publisher: " << gPtr->publisher << endl;
cout << "Book ISBN Number: " << gPtr->ISBNNumber << endl;
}
void displayP(proceedingsBook* pPtr)
{
cout << "Book Title: " << pPtr->title << endl;
cout << "Book Editor: " << pPtr->editor << endl;
cout << "Book Publisher: " << pPtr->publisher << endl;
cout << "Book Conference Date: " << pPtr->conferenceDate << endl;
cout << "Book ISBN Number: " << pPtr->ISBNNumber << endl;
}
book* buildG(string dataLine)
{
book* ptr = new book;
ptr->title = extractLastString(dataLine);
ptr->author = extractLastString(dataLine);
ptr->publisher = extractLastString(dataLine);
ptr->ISBNNumber = extractLastInt(dataLine)
return ptr;
}
proceedingsBook* buildP(string dataLine)
{
proceedingsBook* ptr = new proceedingsBook;
ptr->title = extractLastString(dataLine);
ptr->editor = extractLastString(dataLine);
ptr->publisher = extractLastString(dataLine);
ptr->conferenceDate = extractLastInt(dataLine);
ptr->ISBNNumber = extractLastInt(dataLine);
return ptr;
}
string extractLastString(string & st)
{
unsigned posLastComma = st.find_last_of(","); // find last ',' in string
string result = st.substr(posLastComma+1); // extract && save everything after the last ,
st = st.substr(0,posLastComma); // remove chars from last , including ,
return result; // return extracted substring
}
int extractLastInt(string & st)
{
string numAsString = extractLastString(st); // extract number as string
istringstream iss(numAsString); // research input stringstreams
int result;
iss >> result;
return result;
}
As to be expected, I am generating errors when I call attributes from the classes and I really need some help in figuring out why!
Also, I wanted to ask this: I am incorporating a linked list and at the moment I have a struct at the top of my .h file called "Books";
struct Books
{
string title;
string author;
string publisher;
//string editor;
//int conferenceDate;
string isbn;
};
Is it possible to use my classes that I have created and two of my variables ideally I would like to be an int, but is string the only option I have?
Any help is appreciated

New Topic/Question
Reply



MultiQuote





|