In: Computer Science
***The code is provided below***
When trying to compile the code below, I'm receiving three errors. Can I get some assistance on correcting the issues?
I removed the code because I thought I corrected my problem. I used #define to get rid of the CRT errors, and included an int at main(). The code compiles but still does not run properly. When entering the insertion prompt for the call details, after entering the phone number, the program just continuously runs, instead of prompting next for the date, then time, & language. After the call insertion is complete, the program is suppose to go to Idol state and then route the call to an available agent at the prompt. Program is also suppose to display various statuses such as recently routed calls and stored calls.
Can I get some assistance on correcting the issues so the program runs properly? Also, with cleaner code without using #define?
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <time.h>
#include <stdlib.h>
#include <ctime>
#include<string.h>
using namespace std;
int i = 0;
struct call
{
int phno;
char date[100];
char time[100];
int id;
char lan[100];
struct call* link;
};
struct call* front = NULL, * rear = NULL;
class Queue
{
public:
void insert();
void delcall();
void status();
};
void Queue::insert()
{
struct call* p = new call();
srand(time(NULL));
time_t curr_time;
time_t my_time = time(NULL);
tm* curr_tm;
time(&curr_time);
curr_tm = localtime(&curr_time);
cout << endl << "Inbound Call -
Insert to Queue" << endl;
cout << "Insert Phone Number: ";
cin >>
p->phno;
strftime(p->date, 50, " %B %d, %Y", curr_tm);
cout << "Insert Date: ";
cin >>
p->date;
strcpy_s(p->time, ctime(&my_time));
cout << "Insert Time: ";
cin >>
p->time;
cout << "Insert Language: ";
cin >>
p->lan;
p->id = (rand() % 10 + 1) + i;
i++;
p->link = NULL;
if (rear == NULL)
{
front = p;
}
else
{
rear->link = p;
}
rear = p;
}
void Queue::delcall()
{
if (front == NULL)
{
cout << endl
<< "ACW: No call to route to Agent" << endl;
}
else
{
cout << endl
<< "Recently routed call to agent is:" << endl;
cout << "Phone #:
" << front->phno << endl;
cout << "Date: "
<< front->date << endl;
cout << "Call
Time: " << front->time;
cout << "Caller
ID: " << front->id << endl;
cout << "Caller
Language : " << front->lan << endl;
if (front == rear)
{
front = rear = NULL;
}
else
{
front = front->link;
}
}
}
void Queue::status()
{
int j;
struct call* temp = front;
if (front == NULL)
cout << endl
<< "ACW: No call to route to Agent" << endl;
else
{
cout << endl
<< "Caller Information" << endl;
do
{
cout << endl << "Stored call details are:" <<
endl;
cout << "Phone #: " << temp->phno <<
endl;
cout << "Date: " << temp->date << endl;
cout << "Call Time: " << temp->time;
cout << "Caller ID: " << temp->id <<
endl;
cout << "Caller Language: " << temp->lan <<
endl;
temp = temp->link;
cout << endl;
} while (temp !=
NULL);
}
}
int main()
{
cout <<
" Demo
Automatic Call Distributor (ACD) ";
cout << endl <<
"-----------------------------------------------------------"
<< endl;
cout << endl << "ACW (Average Call
Waiting/System Idol)" << endl;
cout << endl << "New call enters the
Queue";
cout << endl << "Call leaves the
Queue and routed to Agent";
int p;
char ch;
Queue ob;
do
{
p = (rand() % 3 +
1);
switch (p)
{
case 1:
ob.insert();
break;
case 2:
ob.delcall();
break;
case 3:
ob.status();
break;
}
cout << endl
<< "ACW/System Idol" <<
endl;
cout <<
"waiting...[y/Y]: ";
cin >> ch;
} while (ch == 'y' || ch == 'Y');
}
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <time.h>
#include <stdlib.h>
#include <ctime>
#include<cstring>
using namespace std;
int i = 0;
struct call
{
int phno;
char date[100];
char time[100];
int id;
char lan[100];
struct call* link;
};
struct call* front = NULL, * rear = NULL;
class Queue
{
public:
void insert();
void delcall();
void status();
};
void Queue::insert()
{
struct call* p = new call();
srand(time(NULL));
time_t curr_time;
time_t my_time = time(NULL);
tm* curr_tm;
time(&curr_time);
curr_tm = localtime(&curr_time);
string flag;//modified
cout << endl << "Inbound Call - Insert to Queue"
<< endl;
cout << "Insert Phone Number: ";
cin >> p->phno;
strftime(p->date, 50, " %B %d, %Y", curr_tm);
cout << "Insert Date: ";
cin >> p->date;
strcpy(p->time, ctime(&my_time));//error in this line
cout << "Insert Time: ";
cin >> p->time;
cout << "Insert Language: ";
cin >> p->lan;
getline(cin,flag);//modified
p->id = (rand() % 10 + 1) + i;
i++;
p->link = NULL;
if (rear == NULL)
{
front = p;
}
else
{
rear->link = p;
}
rear = p;
}
void Queue::delcall()
{
if (front == NULL)
{
cout << endl << "ACW: No call to route to Agent"
<< endl;
}
else
{
cout << endl << "Recently routed call to agent is:"
<< endl;
cout << "Phone #: " << front->phno <<
endl;
cout << "Date: " << front->date << endl;
cout << "Call Time: " << front->time;
cout << "Caller ID: " << front->id <<
endl;
cout << "Caller Language : " << front->lan <<
endl;
if (front == rear)
{
front = rear = NULL;
}
else
{
front = front->link;
}
}
}
void Queue::status()
{
int j;
struct call* temp = front;
if (front == NULL)
cout << endl << "ACW: No call to route to Agent"
<< endl;
else
{
cout << endl << "Caller Information" <<
endl;
do
{
cout << endl << "Stored call details are:" <<
endl;
cout << "Phone #: " << temp->phno <<
endl;
cout << "Date: " << temp->date << endl;
cout << "Call Time: " << temp->time;
cout << "Caller ID: " << temp->id <<
endl;
cout << "Caller Language: " << temp->lan <<
endl;
temp = temp->link;
cout << endl;
} while (temp != NULL);
}
}
int main()
{
cout << " Demo Automatic Call Distributor (ACD) ";
cout << endl <<
"-----------------------------------------------------------"
<< endl;
cout << endl << "ACW (Average Call Waiting/System
Idol)" << endl;
cout << endl << "New call enters the Queue";
cout << endl << "Call leaves the Queue and routed to
Agent";
int p;
string ch;//modified
Queue ob;
do
{
p = (rand() % 3 + 1);
switch (p)
{
case 1:
ob.insert();
break;
case 2:
ob.delcall();
break;
case 3:
ob.status();
break;
}
cout << endl << "ACW/System Idol" << endl;
cout << "waiting...[y/Y]: ";
getline(cin,ch);//modified
} while (ch == "y" || ch == "Y");//modified
}
output:
Demo Automatic Call Distributor (ACD)
-----------------------------------------------------------
ACW (Average Call Waiting/System Idol)
New call enters the Queue
Call leaves the Queue and routed to Agent
ACW: No call to route to Agent
ACW/System Idol
waiting...[y/Y]: y
ACW: No call to route to Agent
ACW/System Idol
waiting...[y/Y]: y
ACW: No call to route to Agent
ACW/System Idol
waiting...[y/Y]: y
ACW: No call to route to Agent
ACW/System Idol
waiting...[y/Y]: y
ACW: No call to route to Agent
ACW/System Idol
waiting...[y/Y]: y
ACW: No call to route to Agent
ACW/System Idol
waiting...[y/Y]: y
Inbound Call - Insert to Queue
Insert Phone Number: 123456789
Insert Date: 12/11/1994
Insert Time: 22-34
Insert Language: english
ACW/System Idol
waiting...[y/Y]: y
Inbound Call - Insert to Queue
Insert Phone Number: 987654321
Insert Date: 9-9-1993
Insert Time: 13-24
Insert Language: chinese
ACW/System Idol
waiting...[y/Y]:n