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()
| |