C++ program to simulate customers lining up to buy tickets for some event

Can someone guide me through this assignment?

Create a line class using a linked list that acts as a queue (first in, first out) both enqueue and dequeue. Complete the line class so that customers can be added or removed from the line. Implement the line as a linked list of customer objects that you have developed yourself or use the vector class.
closed account (3qX21hU5)
Have you started to outline what you need to do in code yet? If so what do you have so far (Could you post it)?

Also what are you having trouble with specifically. Now if you were going to say the whole thing or I don't know where to start stop for a second and do this.

First break the problem down in to general things that you need to do to complete the assignment. Now with each of them general things write up tasks that you need to do to accomplish it. Keep on breaking the big tasks up into littler tasks until it all makes sense and you have a general game plan. You will most likely have multiple layers for each task.

Now you should be able to pick one of the general things you need to do and start doing it task by task. This will also help you to be able to tell others what exactly you are having trouble with and what you need to learn.

So for example lets say I need to make a simple menu in the console that has two choices. One of them adds two numbers together and the other subtracts. For that assignment I would do something like this.

• Create the menu class
    o Create a subtraction member function
         Need to add two numbers together
         Need to return the result.

    o Create a addition member function
         Need to subtract two numbers
         Need to return the result

ect. ect.


Now that a really simple example and probably not the best example but it kind of demonstrates it. Basically break the larger problem down into smaller problems that you can solve little by little.
Hi,

Thank you for the reply. Sorry for not being so clear in my previous post. Here's the detailed assignment and the solution(I just outlined it, haven't written much code yet). My question is regarding the Line.cpp (see below). I need some help creating vectors in line.cpp and venue.cpp.

Any help is much appreciated.

Thank you.

Assignment:

Create a program to simulate customers lining up to buy tickets for some entertainment event (your choice). I have
provided a class called Customer and one called Line. The Line class should be a linkedlist that acts as a queue (first in,
first out). Traditionally a queue includes two methods, enqueue and dequeue.
Your assignment:
1. Complete the Line class so that Customers can be added or removed from the Line. Implement the Line as a
linkedlist of Customer objects that you have developed yourself or use the vector class. Change the Line class in
any way that is needed.
2. Write a simulation by completing the venue.cpp file, which has the main method.
a. The venue is selling a 100 tickets for a specific show, movie etc.
b. A method to generate a random number of Customers is included. Place each Customer in the Line.
c. Each Customer is limited to no more than 4 tickets. The number of tickets desired is randomly generated
in the numberOfTickets function.
d. Process the Line, selling the number of tickets desired to each Customer.
i. Stop when the tickets have run out.
ii. A Customer can only buy tickets if the number left is >= the number of desired tickets. Move to
the next Customer if this is not true. No scalping allowed.
iii. If there are not enough tickets left return a negative number from the Customer buyTickets()
function OR throw an exception.
e. Output:
i. Show each Customer and the number of tickets bought. If no tickets available, show that also.
Use operator overloading so that the following will produce the output:
cout << customer
ii. In summary, show the number of Customers who bought tickets and the number who were left
out in the cold.
3. Feel free to add functions as needed to any of the classes or the venue.cpp file, as long as you follow good OOP
practices.
4. Finally, discuss in specifics how you would upgrade this program to include the following:
a. Tickets are priced according to three tiers ($75, $45, $20).
b. Each Customer has a max price which they would be willing to pay.
c. There are 20 Tier1 tickets, 40 Tier2 tickets and 40 Tier3 tickets available.
d. Customers will buy lower-tier ticket(s), but refuse to buy higher-tier ones.


LINE.CPP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "Line.h"

Line::Line(){
	
}//Line()

Line::~Line(){

}//~Line()

//create a vector


Customer& enqueue(Customer &){
//add customer object to the vector

}


void Line::dequeue(){
//process the customers in the queue by calling buyTickets() and remove them from the vector

}

//create a method that will return the size of the vector, this will be helpful with other aspects of the program. 




LINE.H

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef _LINE_H_
#define _LINE_H_

#include <string>
using namespace std;

#include "Customer.h"

class Line
{
public:
	Line();
	~Line();

   void enqueue(Customer &)
   Customer& dequeue();

private:
   

};//class

#endif


CUSTOMER.CPP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "Customer.h"

#include <ctime>

Customer::Customer(){
	numberOfTickets();	
}

//randomly generate number of tickets to order
void Customer::numberOfTickets(){
	tickets = 1 + rand() % 4;
}

int Customer::buyTickets(int left){
	return left >= tickets ? tickets : 0;
}






CUSTOMER.H

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef _CUSTOMER_H_
#define _CUSTOMER_H_

#include <string>
using namespace std;

class Customer 
			
{
	private: 
		int tickets;
		void numberOfTickets();
		
	
	public:  
		Customer();
		int buyTickets(int);
		
};


#endif



VENUE.CPP


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "Line.h"
#include "Customer.h"

int randomCustomers();

int main(){
	//create a variable to hold a number of random customers from the randCustomers() method as well as a variable for the total number of tickets available

	//create a loop to instantiate the that many of random customers and add them to the vector in the Line class using enqueue()

	//create another loop to process the tickets using dequeue()
	
	
	return 0;
}//main

int randomCustomers(){
	srand(time(NULL));
	int number = 1 + rand() % 200;
	return number;
}//randNumCustomer()
Topic archived. No new replies allowed.