Question & Answer: Any help on this error? I get this when run the code pasted below……

Any help on this error? I get this when run the code pasted below.

Microsoft Visual C++Runtime Library Debug Assertion Failed! Program: C:windowsisystem321MSVCP140D.dl File: c:program files (x86)microsoft visual studio 14.0vcu ncludellist Line: 211 Expression: listit erator not derefrencable For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application) Abort Retry Ignore

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: Any help on this error? I get this when run the code pasted below……
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

#include “stdafx.h”

#include <iostream>

#include <queue>

#include <list>

#include <fstream>

#include <stdlib.h>

#include <string>

using namespace std;

//customer class to hold information pulled from notepad

class Customer

{

//all information on the customer pulled from notepad

int number;

int arrival_time;

int serv_time;

public:

Customer()

{

number = 0;

arrival_time = 0;

serv_time = 0;

}

void set_number(int x)

{

number = x;

}

void set_arrival_time(int x)

{

arrival_time = x;

}

int get_arrival_time()

{

return arrival_time;

}

void set_serv_time(int x)

{

serv_time = x;

}

int get_serv_time()

{

return serv_time;

}

};

//Cashier class to act as 5 queues for customer info to be held in

class Cashier

{

int timer; //minutes in use

char status; // ‘a’ -available, ‘i’ – inactive

queue<int> time_limit; //depends on customer serv_time

int in_line;

public:

Cashier()

{

timer = 0;

status = ‘a’;

in_line = 0;

}

char get_status()

{

return status;

}

void inc_timer()

{

timer++;

}

int get_timer()

{

return timer;

}

int get_in_line()

{

return in_line;

}

void add_customer(int serv_time)

{

//sets timer to 0 for first input, since i reset it on pop its

//needed for first entry.

if (time_limit.empty())

{

timer = 0;

}

//puts the serv_time on the queue of time_limits

time_limit.push(serv_time);

//add customer to line

in_line++;

if (in_line == 6)

{

status = ‘i’;

}

}

int get_curr_cust_time_limit()

{

return time_limit.front();

}

void rmv_frnt_cust()

{

time_limit.pop();

timer = 0;

in_line–;

status = ‘a’;

}

};

//Sim_data_type class to hold overall simulation data

class Sim_data_type

{

int time_cnt; // ranges in values from 0 to 600

int num_serviced; // number of customers serviced so far

long tot_wait_time; // of all customers in the queues

int num_turned_away; // count of customers turned away

public:

Sim_data_type()

{

time_cnt = 0;

num_serviced = 0;

tot_wait_time = 0;

num_turned_away = 0;

}

void inc_cnt()

{

time_cnt++;

}

int get_cnt()

{

return time_cnt;

}

void inc_num_turned_away()

{

num_turned_away++;

}

int get_num_turned_away()

{

return num_turned_away;

}

void inc_num_serviced()

{

num_serviced++;

}

int get_num_serviced()

{

return num_serviced;

}

int get_avg_wait_time()

{

return tot_wait_time / num_serviced;

}

void add_tot_wait_time(int x)

{

tot_wait_time = tot_wait_time + x;

}

};

#include <iostream>

#include <queue>

#include <list>

#include <fstream>

#include <stdlib.h>

using namespace std;

int main(void)

{

//setting up the 5 lines of cashiers

Cashier cashier1;

Cashier cashier2;

Cashier cashier3;

list<Cashier> lines;

list<Cashier>::iterator curr = lines.begin();

list<Cashier>::iterator next = lines.begin();

for (int i = 0; i < 5; i++)

{

lines.push_back(cashier1);

}

//creating Customer variable to temporarily hold input

Customer cust;

//creating queue to hold input from file

queue<Customer> custInput;

//creating variable to hold simulation data

Sim_data_type sim;

//file for getting input

ifstream in_file;

//used to temperarily hold the line obtained from the file

string line;

//used to temperarily hold the selected substring

string substring;

//opening file

in_file.open(“output.txt”);

if (in_file.fail())

{

cout << “Could not open file.n”;

return 0;

}

else

{

//get data from file until end of file

while (!in_file.eof())

{

//gets input until new line

getline(in_file, line);

//if extracted string isn’t empty

if (line.length() > 0)

{

//getting the first digits for (number)

substring = line.substr(0, 2);

cust.set_number(atoi(substring.c_str()));

//getting the next digits for (arrival_time)

substring = line.substr(4, 4);

cust.set_arrival_time(atoi(substring.c_str()));

//getting the next digits for (serv_time)

substring = line.substr(9, 3);

cust.set_serv_time(atoi(substring.c_str()));

//adding newly created customer to the data queue

custInput.push(cust);

}

}

//closing file

in_file.close();

}

//while store not closed

while (sim.get_cnt() < 600)

{

//increment minutes

sim.inc_cnt();

for (int i = 0; i < 5; i++)

{

cashier1 = *curr;

curr++;

cashier1.inc_timer();

*curr = cashier1;

}

//move cashiers to proper positions

curr = lines.end();

next = lines.end();

next–;

while (curr != lines.begin())

{

curr–;

next–;

cashier1 = *curr;

cashier2 = *next;

if (cashier1.get_in_line() < cashier2.get_in_line())

{

//swap placements so cashier with the smallest line is in

//front

cashier3 = cashier2;

cashier2 = cashier1;

cashier1 = cashier3;

}

}

//while customers can still be served

if (sim.get_cnt() < 570)

{

//set cust to temporarily hold front of custInput

cust = custInput.front();

//put customer in smallest line

curr = lines.begin();

cashier1 = *curr;

//if the front of queue is ready to join line

while (cust.get_arrival_time() == sim.get_cnt())

{

//flag to see if more than one customer has arrived at the

//same time

int flag = 0;

//if another round move to next line

if (flag > 0)

{

curr++;

cashier1 = *curr;

}

//set the customer to the first available/shortest

//lane; if none are open turn them away

if (cashier1.get_status() == ‘a’)

{

//adding customers serv time to cashiers queue

cashier1.add_customer(cust.get_serv_time());

//removing customer from input we added to queue

custInput.pop();

//setting cust to new front so while checks correctly

cust = custInput.front();

}

else

{

sim.inc_num_turned_away();

}

flag++;

}

}

//increment sim variables for output later

//if cashiers timer = the serv time of cust

//then remove that cust

curr = lines.begin();

cashier1 = *curr;

for (int i = 0; i < 5; i++)

{

if (cashier1.get_timer() == cashier1.get_curr_cust_time_limit())

{

//add the customer-to-be-removed’s wait time to total wait

sim.add_tot_wait_time(cashier1.get_curr_cust_time_limit());

//remove it front queue

cashier1.rmv_frnt_cust();

//increment the total number serviced

sim.inc_num_serviced();

}

curr++;

cashier1 = *curr;

}

}

//final output

cout << “Total number of customers serviced: ” << sim.get_num_serviced();

cout << endl << “Total number of customers turned away: ”

<< sim.get_num_turned_away();

cout << endl << “Average wait time: ” << sim.get_avg_wait_time() << endl;

//exit program

return 0;

}

Show transcribed image textMicrosoft Visual C++Runtime Library Debug Assertion Failed! Program: C:windowsisystem321MSVCP140D.dl File: c:program files (x86)microsoft visual studio 14.0vcu ncludellist Line: 211 Expression: listit erator not derefrencable For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application) Abort Retry Ignore

Expert Answer

 

//Note: Please include the output.txt file to your code while executing the code.

//Project Structure

Question & Answer: Any help on this error? I get this when run the code pasted below...... 1

//Code Image

Question & Answer: Any help on this error? I get this when run the code pasted below...... 2

Question & Answer: Any help on this error? I get this when run the code pasted below...... 3

Question & Answer: Any help on this error? I get this when run the code pasted below...... 4

Question & Answer: Any help on this error? I get this when run the code pasted below...... 5

Question & Answer: Any help on this error? I get this when run the code pasted below...... 6

Question & Answer: Any help on this error? I get this when run the code pasted below...... 7

Question & Answer: Any help on this error? I get this when run the code pasted below...... 8

Question & Answer: Any help on this error? I get this when run the code pasted below...... 9

Question & Answer: Any help on this error? I get this when run the code pasted below...... 10

Question & Answer: Any help on this error? I get this when run the code pasted below...... 11

Question & Answer: Any help on this error? I get this when run the code pasted below...... 12

//Sample Output

Question & Answer: Any help on this error? I get this when run the code pasted below...... 13

//Code to copy

//Customer.cpp

#include “stdafx.h” //header works in visual studio

#include <iostream>

#include <queue>

#include <list>

#include <fstream>

#include <stdlib.h>

#include <string>

using namespace std;

//customer class to hold information pulled from notepad

class Customer

{

//all information on the customer pulled from notepad

int number;

int arrival_time;

int serv_time;

public:

/*Default Constructor*/

Customer()

{

number = 0;

arrival_time = 0;

serv_time = 0;

}

void set_number(int x)

{

number = x;

}

void set_arrival_time(int x)

{

arrival_time = x;

}

int get_arrival_time()

{

return arrival_time;

}

void set_serv_time(int x)

{

serv_time = x;

}

int get_serv_time()

{

return serv_time;

}

};

//Cashier.cpp

#pragma once

#ifndef _QUEUE_H

#define _QUEUE_H

#include <queue>

#include <iostream>

#include <queue>

#include <list>

#include <fstream>

#include <stdlib.h>

#include <string>

using namespace std;

class Cashier

{

int timer; //minutes in use

char status; // ‘a’ -available, ‘i’ – inactive

queue<int> time_limit; //depends on customer serv_time

int in_line;

public:

/*Default Constructor*/

Cashier()

{

timer = 0;

status = ‘a’;

in_line = 0;

}

char get_status()

{

return status;

}

void inc_timer()

{

timer++;

}

int get_timer()

{

return timer;

}

int get_in_line()

{

return in_line;

}

void add_customer(int serv_time)

{

//sets timer to 0 for first input, since i reset it on pop its

//needed for first entry.

if (time_limit.empty())

{

timer = 0;

}

//puts the serv_time on the queue of time_limits

time_limit.push(serv_time);

//add customer to line

in_line++;

if (in_line == 6)

{

status = ‘i’;

}

}

int get_curr_cust_time_limit()

{

return time_limit.front();

}

void rmv_frnt_cust()

{

time_limit.pop();

timer = 0;

in_line–;

status = ‘a’;

}

};

#endif

//Sim_data_type.cpp

#include<iostream>

#include <queue>

#include <list>

#include <fstream>

#include <stdlib.h>

#include <string>

class Sim_data_type

{

int time_cnt; // ranges in values from 0 to 600

int num_serviced; // number of customers serviced so far

long tot_wait_time; // of all customers in the queues

int num_turned_away; // count of customers turned away

public:

/*Default Constructor*/

Sim_data_type()

{

time_cnt = 0;

num_serviced = 0;

tot_wait_time = 0;

num_turned_away = 0;

}

void inc_cnt()

{

time_cnt++;

}

int get_cnt()

{

return time_cnt;

}

void inc_num_turned_away()

{

num_turned_away++;

}

int get_num_turned_away()

{

return num_turned_away;

}

void inc_num_serviced()

{

num_serviced++;

}

int get_num_serviced()

{

return num_serviced;

}

int get_avg_wait_time()

{

return tot_wait_time / num_serviced;

}

void add_tot_wait_time(int x)

{

tot_wait_time = tot_wait_time + x;

}

};

// main.cpp : Defines the entry point for the console application.

//

#include “stdafx.h” //header work in visual studio only

#include <iostream>

#include <queue>

#include <list>

#include <fstream>

#include <stdlib.h>

#include “Cashier.cpp”

#include “Customer.cpp”

#include “Sim_data_type.cpp”

using namespace std;

int main(void)

{

//setting up the 5 lines of cashiers

Cashier cashier1;

Cashier cashier2;

Cashier cashier3;

list<Cashier> lines;

list<Cashier>::iterator curr = lines.begin();

list<Cashier>::iterator next = lines.begin();

for (int i = 0; i < 5; i++)

{

lines.push_back(cashier1);

}

//creating Customer variable to temporarily hold input

Customer cust;

//creating queue to hold input from file

queue<Customer> custInput;

//creating variable to hold simulation data

Sim_data_type sim;

//file for getting input

ifstream in_file;

//used to temperarily hold the line obtained from the file

string line;

//used to temperarily hold the selected substring

string substring;

//opening file

in_file.open(“output.txt”);

if (in_file.fail())

{

cout << “Could not open file.n”;

system(“pause”); //work in visual studio only

return 0;

}

else

{

//get data from file until end of file

while (!in_file.eof())

{

//gets input until new line

getline(in_file, line);

//if extracted string isn’t empty

if (line.length() > 0)

{

//getting the first digits for (number)

substring = line.substr(0, 2);

cust.set_number(atoi(substring.c_str()));

//getting the next digits for (arrival_time)

substring = line.substr(4, 4);

cust.set_arrival_time(atoi(substring.c_str()));

//getting the next digits for (serv_time)

substring = line.substr(9, 3);

cust.set_serv_time(atoi(substring.c_str()));

//adding newly created customer to the data queue

custInput.push(cust);

}

}

//closing file

in_file.close();

}

//while store not closed

while (sim.get_cnt() < 600)

{

//increment minutes

sim.inc_cnt();

for (int i = 0; i < 5; i++)

{

cashier1 = *curr;

curr++;

cashier1.inc_timer();

*curr = cashier1;

}

//move cashiers to proper positions

curr = lines.end();

next = lines.end();

next–;

while (curr != lines.begin())

{

curr–;

next–;

cashier1 = *curr;

cashier2 = *next;

if (cashier1.get_in_line() < cashier2.get_in_line())

{

//swap placements so cashier with the smallest line is in

//front

cashier3 = cashier2;

cashier2 = cashier1;

cashier1 = cashier3;

}

}

//while customers can still be served

if (sim.get_cnt() < 570)

{

//set cust to temporarily hold front of custInput

cust = custInput.front();

//put customer in smallest line

curr = lines.begin();

cashier1 = *curr;

//if the front of queue is ready to join line

while (cust.get_arrival_time() == sim.get_cnt())

{

//flag to see if more than one customer has arrived at the

//same time

int flag = 0;

//if another round move to next line

if (flag > 0)

{

curr++;

cashier1 = *curr;

}

//set the customer to the first available/shortest

//lane; if none are open turn them away

if (cashier1.get_status() == ‘a’)

{

//adding customers serv time to cashiers queue

cashier1.add_customer(cust.get_serv_time());

//removing customer from input we added to queue

custInput.pop();

//setting cust to new front so while checks correctly

cust = custInput.front();

}

else

{

sim.inc_num_turned_away();

}

flag++;

}

}

//increment sim variables for output later

//if cashiers timer = the serv time of cust

//then remove that cust

curr = lines.begin();

cashier1 = *curr;

for (int i = 0; i < 5; i++)

{

if (cashier1.get_timer() == cashier1.get_curr_cust_time_limit())

{

//add the customer-to-be-removed’s wait time to total wait

sim.add_tot_wait_time(cashier1.get_curr_cust_time_limit());

//remove it front queue

cashier1.rmv_frnt_cust();

//increment the total number serviced

sim.inc_num_serviced();

}

curr++;

cashier1 = *curr;

}

}

//final output

cout << “Total number of customers serviced: ” << sim.get_num_serviced();

cout << endl << “Total number of customers turned away: ”

<< sim.get_num_turned_away();

cout << endl << “Average wait time: ” << sim.get_avg_wait_time() << endl;

//exit program

system(“pause”); //work in visual studio only

return 0;

}

Still stressed from student homework?
Get quality assistance from academic writers!