Thread: Accessing my class from a queue

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User immy's Avatar
    Join Date
    Apr 2014
    Posts
    33

    Accessing my class from a queue

    Hi guys the question I am attempting is
    The elements stored in a Queue object can be of any type, including other objects.
    Write an application to simulate a queue of people going to the cinema. The user may
    input "j" to join the queue, "l" to leave the queue or "e" to end the program.
    When a person joins the queue, their name and age is input and stored in a queue of
    Person objects.
    This evening, the cinema is showing a film rated as 15. When a person leaves the front
    of the queue, their age is checked and one of the following messages is output:
     <name> has left the queue and has entered the cinema
     <name> has left the queue, but is too young to enter the cinema

    Code:
    //Task 2: Cinema
    #include <iostream>
    #include "Person.h"
    #include <string>
    #include <queue>
    using namespace std;
    int main()
    {
        queue <Person>* myQueue;
        string e;
    
    
        cout << "<j> Join queue, <i> Leave queue, <end> Exit program";
        do
        {
            cout << "\n\nEnter a command: ";
            getline(cin, e);
            if (e == "j")
            {
                myQueue->push()
            }
    
    
            else if (e == "i")
            {
        
            }
    
    
            else
            {
                cout << "Incorrect entry. Please try again!\n";
            }
    
    
        } while (e != "end");
    
    
    
    
        system("PAUSE");
        return 0;
    }

    My problem is that on line 20 I cannot figure out how to access the queue from the person class and access the person methods
    Code:
    myQueue->push(/*Access Class*/)





    //Person c.pp
    Code:
    #include "Person.h"
    
    
    
    
    
    
    Person::Person()
    {
    }
    
    
    
    
    Person::~Person()
    {
    }
    
    
    void Person::setName(string n)
    {
        name = n;
    }
    
    
    string Person::GetName()
    {
        return name;
    }
    
    
    void Person::setAge(int a)
    {
        age = a;
    }
    
    
    int Person::GetAge()
    {
        return age;
    }
    Last edited by immy; 01-10-2017 at 02:00 PM.
    "Don't quit. Suffer now and live the rest of your life as a champion"
    - Muhammad Ali


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 03-11-2016, 01:15 AM
  2. Replies: 11
    Last Post: 01-31-2016, 01:57 PM
  3. Accessing next entry in a queue.
    By peripatein in forum C Programming
    Replies: 84
    Last Post: 06-17-2013, 08:07 PM
  4. (queue*)this)->queue::qput’ does not have class type
    By brack in forum C++ Programming
    Replies: 13
    Last Post: 11-11-2010, 03:41 PM
  5. Base-class pointer, accessing object from derived class
    By Korhedron in forum C++ Programming
    Replies: 15
    Last Post: 09-28-2008, 05:30 AM

Tags for this Thread