FOR PMY 1733 ONLY

profileMesfer almesfer
pa3_0.zip

pa3/bin/Debug/pa3.exe

pa3/CsvWriter.h

#ifndef CSVWRITER_H #define CSVWRITER_H #include <vector> #include <string> #include <iterator> using namespace std; class CsvWriter { private: vector<string> _lines; int _currentLine; public: CsvWriter() { _currentLine = 0; _lines.push_back(""); } //Adds a new cell to the current row void addText(string text) { string &currentLine = _lines[_currentLine]; if(currentLine.length() > 0) { currentLine += ","; } currentLine += "\"" + text + "\""; } //Moves the CsvWriter to the next line in the CSV file void nextLine() { _lines.push_back(""); _currentLine++; } //Converts the class into a string-based CSV file. string toCsvString() const { string output = ""; for(vector<string>::const_iterator iter = _lines.begin(); iter != _lines.end(); iter++) { output += *iter + "\n"; } return output; } }; #endif

pa3/main.cpp

#include <iostream> #include<queue> #include<vector> #include<cstdlib> #include<fstream> #include "CsvWriter.h" using namespace std; class Customer{ private: int customer_id=0; int arrival_time=0; int service_time=0; int departure_time=0; string line_name=" "; public: static int id_counter; static Customer generateCustomer(int arrival_t,string line){ Customer customer; customer.setArrivalTime(arrival_t); customer.setLineName(line); customer.setCustomerID(Customer::id_counter); customer.setDepartureTime(0); return customer; } void setLineName(string line){ line_name=line; } int getTotalWaitTime(){ return (departure_time-arrival_time); } void setCustomerID(int id){ customer_id=id; } void setArrivalTime(int t){ arrival_time=t; } void setServiceTime(int t){ service_time=t; } void setDepartureTime(int t){ departure_time=t; } int getArrivalTime(){ return arrival_time; } int getCustomerID(){ return customer_id; } int getServiceTime(){ return service_time; } int getDepartureTime(){ return departure_time; } string getLineName(){ return line_name; } }; int Customer::id_counter=0; class CheckoutLine{ private: string line_name; int tick_count=0; queue<Customer> line; queue<Customer>served_customers; public: string getLineName(){ return line_name; } bool isEmpty(){ if(line.empty()) return true; else return false; } void addCustomer(Customer c){ line.push(c); } queue <Customer> getServicedCustomers(){ return served_customers; } void tick(){ tick_count++; } void setLineName(string line){ line_name=line; } Customer getFirst(){ return line.front(); } void pop(){ line.front().setDepartureTime(tick_count); served_customers.push(line.front()); line.pop(); } int getTicks(){ return tick_count; } }; int main() { cout<<"*** Jack's Mart Checkout Simulator ***"<<endl; int checkstands; int probability,random,service,customers; cout << "Enter number of checkstands: "; cin>>checkstands; CheckoutLine stands[checkstands]; for(int i=0;i<checkstands;i++){ stands[i].setLineName(to_string(i)); } Customer::id_counter=0; probability=0; int counter=0; cout << "Performing simulation... \n"; while(counter<720){ bool arrived=false; random=rand()%6; if(probability>=1){ arrived=true; } if(random<=probability){ probability=0; if(arrived){ Customer::id_counter++; service=rand()%4+1; CheckoutLine emptyLine; bool found=false; for(int i=0;i<checkstands;i++){ if(stands[i].isEmpty()){ found=true; stands[i].addCustomer(Customer::generateCustomer(counter,stands[i].getLineName())); break; } } if(!found){ service=rand()%checkstands; stands[service].addCustomer(Customer::generateCustomer(counter,stands[service].getLineName())); } } } else{ probability++; bool found; int dt; for(int i=0;i<checkstands;i++){ if(!stands[i].isEmpty()){ if(stands[i].getFirst().getDepartureTime()==0){ dt=stands[i].getTicks()+stands[i].getFirst().getServiceTime(); stands[i].getFirst().setDepartureTime(dt); } if(stands[i].getFirst().getDepartureTime()<stands[i].getTicks()){ stands[i].pop(); } } stands[i].tick(); } } counter++; } cout<<"Simulation complete. Saving results to output.csv"<<endl; ofstream fout("output.csv"); fout<<"Customers Created:,"<<Customer::id_counter<<"\n"; fout<<"Customer ID,Arrival,Time to Check Out,Departure,Total Wait,Line Number"<<"\n"; queue<Customer>served; for(int i=0;i<checkstands;i++){ Customer outer; served=stands[i].getServicedCustomers(); for(int j=0;j< served.size();j++){ outer=served.front(); fout<<outer.getCustomerID()<<","<<outer.getArrivalTime()<<","<<outer.getArrivalTime()+outer.getServiceTime()<<","<<outer.getServiceTime(); fout<<","<<outer.getTotalWaitTime()<<","<<outer.getLineName()<<"\n"; served.pop(); } } return 0; }

pa3/obj/Debug/main.o

pa3/output.csv

Customers Created: 214
Customer ID Arrival Time to Check Out Departure Total Wait Line Number
1 5 5 0 0 0
2 11 11 0 -2 0
3 14 14 0 -3 0
4 16 16 0 -4 0
5 22 22 0 -6 0
6 26 26 0 -7 0
7 31 31 0 -9 0
8 35 35 0 -11 0
9 39 39 0 -12 0
10 42 42 0 -13 0
11 45 45 0 -14 0
12 47 47 0 -15 0
13 50 50 0 -16 0
14 54 54 0 -18 0
15 58 58 0 -19 0
16 61 61 0 -20 0
17 66 66 0 -21 0
18 70 70 0 -23 0
19 72 72 0 -24 0
20 74 74 0 -25 0
21 77 77 0 -26 0
22 81 81 0 -27 0
23 87 87 0 -30 0
24 91 91 0 -31 0
25 95 95 0 -32 0
26 98 98 0 -34 0
27 103 103 0 -35 0
28 108 108 0 -36 0
29 110 110 0 -37 0
30 114 114 0 -38 0
31 116 116 0 -39 0
32 118 118 0 -40 0
33 122 122 0 -41 0
34 125 125 0 -43 0
35 128 128 0 -44 0
36 131 131 0 -45 0
37 134 134 0 -46 0
38 137 137 0 -47 0
39 140 140 0 -49 0
40 142 142 0 -50 0
41 144 144 0 -51 0
42 147 147 0 -53 0
43 149 149 0 -54 0
44 153 153 0 -55 0
45 157 157 0 -56 0
46 161 161 0 -57 0
47 164 164 0 -58 0
48 167 167 0 -60 0
49 169 169 0 -61 0
50 171 171 0 -62 0
51 174 174 0 -63 0
52 182 182 0 -67 0
53 184 184 0 -68 0
54 187 187 0 -69 0
55 190 190 0 -70 0
56 194 194 0 -71 0
57 198 198 0 -73 0
58 203 203 0 -74 0
59 207 207 0 -77 0
60 209 209 0 -78 0
61 211 211 0 -79 0
62 214 214 0 -80 0
63 217 217 0 -81 0
64 222 222 0 -83 0
65 225 225 0 -84 0
66 230 230 0 -85 0
67 234 234 0 -87 0
68 236 236 0 -88 0
69 239 239 0 -89 0
70 241 241 0 -90 0
71 245 245 0 -91 0
72 247 247 0 -92 0
73 249 249 0 -93 0
74 251 251 0 -94 0
75 254 254 0 -95 0
76 258 258 0 -96 0
77 261 261 0 -97 0
78 264 264 0 -98 0
79 266 266 0 -99 0
80 270 270 0 -100 0
81 272 272 0 -101 0
82 275 275 0 -102 0
83 277 277 0 -103 0
84 279 279 0 -104 0
85 282 282 0 -105 0
86 285 285 0 -106 0
87 289 289 0 -107 0
88 292 292 0 -108 0
89 294 294 0 -109 0
90 296 296 0 -110 0
91 299 299 0 -111 0
92 301 301 0 -112 0
93 305 305 0 -113 0
94 307 307 0 -114 0
95 310 310 0 -115 0
96 314 314 0 -117 0
97 318 318 0 -118 0
98 322 322 0 -119 0
99 328 328 0 -121 0
100 331 331 0 -122 0
101 335 335 0 -123 0
102 337 337 0 -124 0
103 340 340 0 -125 0
104 343 343 0 -126 0
105 345 345 0 -127 0
106 349 349 0 -128 0
107 353 353 0 -129 0

pa3/pa3.cbp

pa3/pa3.depend

# depslib dependency file v1.0 1476107074 source:c:\users\jahguy\documents\c plus plus\pa3\main.cpp <iostream> <queue> <vector> <cstdlib> <fstream> "CsvWriter.h" 1476089785 c:\users\jahguy\documents\c plus plus\pa3\csvwriter.h <vector> <string> <iterator>

pa3/pa3.layout

111111.zip

CsvWriter.h

#ifndef CSVWRITER_H #define CSVWRITER_H #include <vector> #include <string> #include <iterator> using namespace std; class CsvWriter { private: vector<string> _lines; int _currentLine; public: CsvWriter() { _currentLine = 0; _lines.push_back(""); } //Adds a new cell to the current row void addText(string text) { string &currentLine = _lines[_currentLine]; if(currentLine.length() > 0) { currentLine += ","; } currentLine += "\"" + text + "\""; } //Moves the CsvWriter to the next line in the CSV file void nextLine() { _lines.push_back(""); _currentLine++; } //Converts the class into a string-based CSV file. string toCsvString() const { string output = ""; for(vector<string>::const_iterator iter = _lines.begin(); iter != _lines.end(); iter++) { output += *iter + "\n"; } return output; } }; #endif

Capture.GIF

Captu2re.GIF

PA3 (1).docx

CS 211 PA #3

In PA1, we helped Jacks Mart develop a simple checkout system. That system was so successful that they've decided to expand their operations by opening additional checkout lanes. Unfortunately, they are unsure of just how many lanes they need to add. Ideally, Jacks Mart would add enough lanes to satisfy expected demand. However, opening too many lanes would mean that they're paying checkers to staff empty lanes. Your goal is to develop a checkout lane simulation that can be used to determine the optimal number of lanes that Jacks Mart should have open.

Your program should simulate an entire day at Jacks Mart. For this simulation, we will assume that Jacks Mart is open 12 hours (720 minutes) a day. As this is a simulation, you don't actually need to run your program for 12 hours. Instead, consider the time span to be an integer, with each minute being a number. As such, 0 would indicate the start of the simulation, 1 would represent the first minute of the simulation, 2 the second minute, and so on.

Program Flow

Your simulation should operate as follows:

1. Prompt the user for the number of checkstands to simulate

2. Create a data structure that contains the appropriate number of checkstands

3. Set the probability of a new customer arriving equal to 0.

4. For each minute in the simulation

a. Determine if a new customer has arrived.

i. Generate a random number between 0 and 5.

ii. If the random number is less than or equal to the probability of a new customer arriving (Step #3), reset the probability back to 0 and go to Step 4.B.

iii. If the number is greater than the probability of a new customer arriving (Step #3), increment the probability of the new customer arriving by 1. Go to Step 4.C.

b. If a new customer has arrived, create a new customer whose arrival time is equal to the current simulation time and whose service time is a randomly generated number between 1 and 4. Next, try to find an empty checkstand. If one exists, place the customer in the line at that checkstand. If no empty checkstand exists, randomly select a checkstand for the customer to enter.

c. For each checkstand in the simulation:

i. If there is at least one customer in the checkstand, go to 4.C.II. Otherwise, go back to 4.C (look at the next checkstand in the simulation).

ii. If the first customer in line has not received a departure time, calculate one. Departure time = current tick + service time.

iii. If the total time elapsed is greater than the first customer's departure time, then the customer has completed the checkout process. Remove them from the queue.

d. Increment the elapsed time in the simulation

5. After the simulation completes, write the results to a CSV file in the following format: <Customer ID>, <Arrival Time>, <Time to Check Out>, <Departure Time>, <Total Wait>, <Line Number>. Also include the total number of customers generated during the simulation at the top of the CSV file. Note that an example CSV file will be included with this assignment description. I have provided a CsvWriter class to aid in the construction of CSV files.

Required Bits

I'm going to leave more of the design decisions up to you, however, at minimum, your program must use a vector or linked list to store the collection of checkstands. Additionally, each individual checkstand must represent its line of customers using a queue. You may either use the data structures developed in class or those provided to you by the STL.

Optional Bits

For those wanting a bit more direction, my simulation contains two additional classes:

Customer

I use the customer class to contain details about individual customers. Here's the UML diagram:

As you can see, I have private member variables to track all of the customer's information. Note that I have a static integer called "_id_counter" that ensure that each customer receives a unique customer ID number. Each time that I create a new customer, I increment that number. Related to this is the static method generateCustomer(). I use this method to create all my customers, sort of like you would when using a Factory. I also have a method that computes the total wait time, which is simply the arrival time subtracted from the departure time. Finally, I have all the typical getters and setters for my member variables that you would expect.

CheckoutLine

I use CheckoutLine to represent a single checkstand in my simulation. Here's the UML diagram:

Note that each CheckoutLine has a line name. This is so that we can determine what lines serviced which customers when examining the final CSV output file. Also note that each CheckoutLine keeps track of the total minutes, which I call "ticks" (a common term in computer science). Each time the tick() method is called, I increment the _ticks variable. Also, the tick() method is responsible for performing checkstand-specific tasks listed in section 4.C of the simulation algorithm. As part of that method, I move the customers that have finished the checkout process from "_line" into "_serviced_customers", which I use when creating my CSV file. Here's a breakdown of the other methods in this class:

isEmpty

Returns true if our "_line" queue is empty

addCustomer

Adds the supplied customer to our "_line" queue of customers

getServicedCustomers

Returns a reference to our vector of serviced customers. To be used when creating the final CSV file.

Sample Output

Below is a screenshot from my program. Note that while you are free to create your own internal implementation, your program must conform to the output below.

Header Comment, and Formatting

1. Be sure to modify the file header comment at the top of your script to indicate your name, student ID, completion time, and the names of any individuals that you collaborated with on the assignment.

2. Remember to follow the basic coding style guide. A basic list of rules is included with this document.

Deliverables

You must upload your program and reflection as a ZIP file through Canvas no later than midnight on Monday, October 10, 2016. Remember that your submission must either contain a CodeBlocks or Visual Studio project file!

Reflection Essay

In addition to the programming tasks listed above, your submission must include an essay that reflects on your experiences with this homework. This essay must be at least 350 words long. Note that the focus of this paper should be on your reflection, not on structure (e.g. introductory paragraph, conclusion, etc.). The essay is graded on content (i.e. it shows deep though) rather than syntax (e.g. spelling) and structure. Below are some prompts that can be used to get you thinking. Feel free to use these or to make up your own.

· Describe a particular struggle that you overcame when working on this programming assignment.

· Conversely, describe an issue with your assignment that you were unable to resolve.

· Provide advice to a future student on how he or she might succeed on this assignment.

1. Describe the most fun aspect of the assignment.

1. Describe the most challenging aspect of the assignment.

1. Describe the most difficult aspect of the assignment to understand.

1. Provide any suggestions for improving the assignment in the future.

Grading Criteria

Your assignment will be judged by the following criteria. Note that the points for each category will be normalized to be 100%.

Error Free Compile (weight: 5pts)

· [0] Your program contains compiler errors.

· [1] Your program compiles without issue.

Error Free Runtime (weight: 5pts)

· [0] Your program throws a runtime exception.

· [1] Your program does not encounter any runtime exceptions.

Pointer Cleanup (weight: 5pts)

· [0] Your program does not delete any dynamically-created pointers

· [1] Your program remembers to delete some, but not all dynamically-created pointers

· [2] Your program deletes all dynamically-created pointers

Style (weight: 10pts)

· [0] Your program does not contain good style. Variables are poorly named, your program doesn't contain a header, there is little or no documentation, your document isn't properly formatted (indentation, whitespace, etc.), and is generally hard to read.

· [1] Your program contains suboptimal style. Some of the items listed in the [0] section are accounted for

· [2] Your program contains good style. Most of the items listed in the [0] section are accounted for.

· [3] Your program contains excellent style. Almost everything in listed in the [0] section is accounted for.

Implementation (weight: 20pts)

· [0-3] Your program's implementation is inefficient. Class usage is non-existent, your code has a lot of redundancy, and is generally not up to the standards of what is expected of a CptS 122 student.

· [4-6] Your program's implementation is acceptable, but can be improved upon. You may use classes, but they are used poorly. Likewise, some redundancy must exist.

· [7-10] Your program's implementation is exemplar. Classes are used in thoughtful and meaningful ways. There is little, if any, redundancy. If this were kindergarten, you would receive a gold star.

User Interface (weight: 5pts)

· [0] Your program does not even attempt to follow the UI guidelines

· [1] Your program's UI has major inconsistencies when compared to the sample output

· [2] Your program's UI has minor inconsistencies when compared to the sample output

· [3] Your program completely matches the specified user interface guidelines

CSV Correctness (weight: 10pts)

· [0] Your program does not event attempt to create a CSV file

· [1] Your program creates a CSV file but it is corrupted or unreadable

· [2] Your program creates a readable CSV file, but certain data points are missing

· [3] Your program creates a CSV file in the expected format.

Data Structure Usage (weight : 10pts)

· [0-1] Your program uses little to no data structures.

· [2-3] Your program uses the STL data structures or the custom data structures developed in class.

Simulation Algorithm Correctness (weight: 30pts)

· [0-2] You do not implement the simulation algorithm as described in this document

· [3-4] Your algorithm implementation differs significantly from the implementation described in this document

· [5-6] Your algorithm mostly follows the implementation listed in this document, but is lacking a few key components

· [7-8] Your algorithm faithfully implements the supplied simulation algorithm.

Reflection Essay (weight: 10pts)

· [0-10] Your reflection essay meets the requirements specified previously in this document.

image1.png

image2.png

image3.png