Write a program that immplements a pointer based linked list with the following functions:
a. Construct/ constructor
b.empty
c. dispaly a node/ search
d.display all nodes
e. delate a node
f. delete all nodes
g. insert a node
The program displays a menu of operations below.

string AuthorTitle;
int BookCode;
double Price;

but I'm having a problem about the main program..
could you help me.. please.. I'm just a beginner...


Immplementation

#include <iostream>
#include <string>
using namespace std;

class Book{
private:
    class NODE{
    public:
        string AuthorTitle;
        int BookCode;
        double Price;
        NODE *next;
    };
    typedef NODE *NodePointer;
    NodePointer ptr, first, predptr, newptr, temp, deleteNode;

	 string in1;
     int in2;
	 double in3;

public:
    void book(){
        first = new NODE;
        first = NULL;
        ptr = first;
    }
    bool Empty(){
        return first == NULL;
    }
    void Insert(){
        newptr = new NODE;
        predptr = ptr;
        
        cout << "Enter the Author or Title of the Book, Book code, and the price of the Book: ";
        cin >> in1 >> in2 >> in3;
        
        newptr -> AuthorTitle = in1;
        newptr -> BookCode = in2;
        newptr -> Price = in3;
        
        if (ptr != 0){
            newptr -> next = predptr -> next;
            predptr -> next = newptr;
        }
        else {
            newptr -> next = first;
            first = newptr;
        }
    }
    void Delete(){
        cout << "Enter the Element that you want to delete[Author or Title and Book Code]: ";
        cin >> in1 >> in2;
        predptr = first;
        
        while (temp -> AuthorTitle != in1 && temp -> BookCode != in2){
            predptr = predptr -> next;
        }
        
        if (deleteNode != NULL){
            ptr = predptr -> next;
            predptr -> next = ptr -> next;
        }
        else {
            ptr = first;
            first = ptr -> next;
            delete ptr;
        }
    }
    void Display(){
        temp = first;
        
        while (temp != NULL){
            cout << temp -> AuthorTitle << " " << temp -> BookCode << " " << temp -> Price;
            
            temp = temp -> next;      
        }
        cout << "This is the end of the List!" << endl;
    }
	void Traverse(){
		cout << "Enter The Author or Title, and Book Code of the book: ";
		cin >> in1 >> in2;
		temp = first;

		if(Empty()){
			cout << "The List is Empty" << endl;
		}
		else {
			while((temp -> next != NULL) && (temp -> AuthorTitle != in1 && temp -> BookCode));
			temp = temp -> next;
		}
		if (temp -> AuthorTitle == in1 && temp -> BookCode == in2){
			cout << "The data is found" << endl;
			cout << temp -> AuthorTitle << " " << temp -> BookCode << " " << temp -> next << " " << temp -> Price;
		}
		else {
			cout << "The data was not found" << endl;
		}
	}
};


Main

#include <iostream>
#include <string>

using namespace std;

int main() {
	char option;
	Book x;

	if(x.Empty()){
		cout << "List is not Empty!" << endl;
	}
	else {
		cout << "List is Empty!" << endl;
	}
	do {
		cout << "I - Insert ,D - Dispaly ,N - deleteNode ,S - Search" << endl;
		cout << "E - Exit" << endl;
		cout << "Enter the letter you want to view";
		cout << endl;
		cin >> option;
		cout << endl;
		switch (option){
			case 'I': x.Insert();
				break;
			case 'D': x.Dispaly();
				break;
			case 'N': x.Delete();
				break;
			case 'S': x.Traverse();
				break;
			case 'E':
				break;
			default:
				break;
		}
	}
	while(option != 'E');
	return 0;
}

Thnks...

>Immplementation
for starters you can post well indented code within 'code tags'. like this(read the 'help with code tags')

..
your code

>but I'm having a problem about the main program..
secondly you can mention the exact problem you are facing so we can focus directly at that point.

What is the problem you are having?

(8) : error C2065: 'Book' : undeclared identifier
(8) : error C2146: syntax error : missing ';' before identifier 'x'
(8) : error C2065: 'x' : undeclared identifier
(10) : error C2228: left of '.Empty' must have class/struct/union type is ''unknown-type''
(26) : error C2228: left of '.Dispaly' must have class/struct/union type is ''unknown-type''
(28) : error C2228: left of '.Delete' must have class/struct/union type is ''unknown-type''
(30) : error C2228: left of '.Traverse' must have class/struct/union type is ''unknown-type''


this are the error that occured in the main program.. sorry.. i have difficulties in making programs since i'm just a beginner.. do help me..

(8) : error C2065: 'Book' : undeclared identifier
(8) : error C2146: syntax error : missing ';' before identifier 'x'
(8) : error C2065: 'x' : undeclared identifier
(10) : error C2228: left of '.Empty' must have class/struct/union type is ''unknown-type''
(26) : error C2228: left of '.Dispaly' must have class/struct/union type is ''unknown-type''
(28) : error C2228: left of '.Delete' must have class/struct/union type is ''unknown-type''
(30) : error C2228: left of '.Traverse' must have class/struct/union type is ''unknown-type''


this are the error that occured in the main program.. sorry.. i have difficulties in making programs since i'm just a beginner.. do help me..

Can't see exactly what you are doing wrong, partly because i prefer having function definitions split from the class prototypeing.

However you have a function void book() now, i'm curious as to what this is supposed to do, since you never call it; yet it looks to me as though it should be called immediately, I.E as the constructor. If it is supposed to be the constructor then shouldn't it have the form Book() .

Also you are working with alot of pointers and you have no descutor which is freeing up memory, I have a feeling this is going to lead to memory leak heaven!

Chris

I'm also confused since our prof gave us assignment which is not properly expalined.. so i'm just basing my prog from my book and other sources...

AH now I see why, you haven't included your header file into your main cpp file #include "yourheaderfile.h" :D

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.