0

Hello, I am asking about true syntax of the following::

I have a class name P and in header file (of this class) ------>

class P
{
public:
	P();
	~P();
	
	void addItem(const int newItem);
	void deleteItem(const int Item);
	
	void showAll();
	

	/** need to proper getter funct. of tail */
private:

	struct Node
	{
		int item;
		Node *next;
		Node *precede;
	};
	
	int size;
	Node *tail;

};

Now I am asking that how I can write getter function of tail ? -class P will be used by another class. Thanks for replying.

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by borchu
0

Show how you think it should be implemented and we will be happy to critique your code. Just don't ask us to do your homework for you... :-(

0

Ok here my whole code;

void RentalSystem::checkoutMovie(const int id, const std::string name, const std::string surname)
{
    bool checkID = false;

    NodeZero *startZero = tailZero->next;
    NodeZero *innerZero = startZero;

    do
    {
        if (id == innerZero->mov.getID())
            checkID = true;

        innerZero = innerZero->next;
    }while (innerZero != startZero);

    if (checkID)
    {
        cout<<"Movie\t"<<id<<"\texists. look at whether person exists or not?"<<endl;
        bool checkString = false;

        Node *start = tail->next;
        Node *inner = start;

        Node *location=NULL;
        do
        {
            if (inner->per.getName().compare(name) == 0
                && inner->per.getSurname().compare(surname) == 0)
                {
                    checkString = true;
                    location = inner;
                    break;
                }


            inner = inner->next;
        }while (inner != start);

        if (checkString)
        {
            cout<<"Movie and Person both exist for checkout."<<endl;

            /** delete Movie from NodeZero */
            deleteMovie(id);
            
            location->per. /** here I need to call proper public getter function for tail typed Node pointer*/
#include "Movie.h"


class Person
{
public:
	Person();
	Person(const std::string, const std::string, const int);

//	void operator=(const Person &);

	~Person();

	void showMovie();

    void addMovie(const int, const std::string, const int);
    void returnMovie(const int);

    bool isEmpty() const;

	void setPersonInfo(const std::string, const std::string, const int);
	std::string getName() const;
	std::string getSurname() const;
	int getYear() const;

	int getSize();



//private:
    struct Node
	{
       Movie  mov;
       Node *next;
	};

	Node *tail;
	int size;


private:

	std::string name, surname;
	int year;

};

Here in person class I have a tail and I want to use private in this class but also I need to access this tail and also size -but size is simple int RentalSystem::getSize() for tail I can not write getter funct. as getter funct. for size. That's only what I am asking, not about implementation. pls help...

0

You need to add some methods to the class P in order to traverse the list. IE, try creating some functions such as P::Node* first(), P::Node* last(), P::Node* next(P::Node* current). However, to do that, you need to make the Node structure public, or external to the class P.

0

Thank for posting, I think this was an unnecessary question I did what u posting about I've added finLoc(id : const int ->to find proper location I use key if (key is equal to some node->mov.getID())) : Node* funct that returns a address of typed Node and I moved to just beginning of header file anyway as I said, again, I understood my mistake, completely have a good day.

This question has already been answered. 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.