i am trying to implement a database of books and i am have to use linked lists and possibly dynamic arrays for the first time so i am a bit confused..i just wanted to know if this is how i should b going about my constructors and if theres anything i should add or help me with..thanks

#include "library.h"
#include <iostream>
#include <string>
#include <cassert>
using namespace std;

Library::Library() //Creates an empty library without books and without authors.
{
   first = NULL;            
   last = NULL;
   count = 0;
}

Library::~Library() //Destructor
{
                         
}

void Library::add(string title, string authors[], int nAuthors) // Add a book
{
                   
}

void Library::print() const  // Print the list of all books ordered by book title.
{
     bookType *current;

	current = first;
	
	while (current != NULL)
	{
	   cout << current->info << " ";
	   current = current->link;
	}
     
}

void Library::printByAuthor(string author) const //Print the list of books of a given author, ordered by book title.
{
     
}

Recommended Answers

All 3 Replies

I think you should use std library, which is now language standard. Safe and free of bugs list, queues, stuff with operators overloaded and many usefull constuctors waiting for you.

http://www.cppreference.com/

im not allowed to use stl..i have to use pointer structures (dynamic arrays and/or linked lists)

You already included namespace std...


As far as i remember from school you have to implement something like this:

struct ListElement
{
    int nSomeData;
    ListElement *previous, *next;
}

Then make functions like add(), delete(), etc...
You can close all these into class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.