ASAP C++ Assignment Help
This assignment gives you experience working with the queueclass template we developed in lecture. Your program will model twolanes--an express lane and normal lane--in a grocery store, using aQueue object for each. You'll read a file telling you when eachcustomer arrives and how long they'll take, use that information tofill a pair of queues, and then empty each queue to simulate theprocess of serving customers.
Input specification
The only user input to this program is a file name. Your programshould open and read the specified file, which always contains 10input lines representing 10 customers. Each line contains thefollowing information:
So, for example, the first three lines of the input filefile1.txt represent two express lane customers and one normal lanecustomer arriving at times 2, 7, and 8, with service times 3, 1,and 4:
Output specification and grading rubric
Your program is essentially broken into two parts: reading thefile and filling the queues, then emptying the queues to simulateserving customers. The test cases use two separate input files,file1.txt and file2.txt. I've collected the full program outputbased on each input file in a pair of files, file1_output.txt andfile2_output.txt, which are provided below as downloadable files.Remember, your program doesn't print to a file--it prints to thescreen!
Reading the file (10 points)
To show that your program reads the file correctly, the programmust do the following:
For example, here's the output my program generates whilereading file1.txt. The file name on the first line is user input;the program prints everything else:
Serving customers (40 points)
This part of the program is a loop that runs as long as at leastone of four conditions is satisfied:
While those conditions control when the loop ends, your loopalso needs a variable representing time, which starts at 1 andincrements every loop iteration. Each time through the loop, yourprogram may take at least one of four actions (although it may donone of these), each of which should be indicated by a line ofoutput:
To start serving a new customer from either lane, threeconditions have to be satisfied:
Each customer's service time tells you how many cycles you needto spend serving them. Once that time is up, you can treat thecurrent customer as done and you'll be available to serve a newcustomer. Note that:
The output my program generates while serving the customersrepresented in file1.txt is below:
Items in queue
You can use the array-based queue template we designed in class(or, if you're feeling unnecessarily ambitious, redesign it), whichis provided below. You do need some way of representing the datastored in each queue entry, though. I used the QItem class that'salso provided with the assignment, which stores each customer'snumber, arrival time, and service time. I'll let you decide whatfunctions are necessary for your solution; feel free to redefinethat class or completely ignore it.
File handling hints
We talked briefly about file I/O in Lecture 3, covering ifstreamobjects for input and noting that you can use an ifstream the sameway you use cin.
While there's an eof() function for ifstream objects, you don'tnecessarily need it. A statement using the input extractionoperator >> returns false if it fails to read anything, whichyou can use to your advantage. If myfile.txt contains a list ofintegers, the code below will read all of those values:
Customer service hints
Did you carefully read the description of the customer serviceprocess, particularly the short lists that describe:
prog4main.cpp (Has to be modified)
/**************************************************************** I BELIEVE YOU'LL NEED TO INCLUDE ALL OF THESE HEADER FILES;** FEEL FREE TO MODIFY THIS LIST AS NEEDED ****************************************************************/#include "Queue.h"#include "QItem.h"#include <fstream>#include <iostream>#include <string>
using namespace std;
int main() {
/***************************************************************** VARIABLE DECLARATIONS SHOULD INCLUDE (BUT NOT BE LIMITEDTO):* - VARIABLES TO READ FROM THE FILE (INPUT STREAM, STRING FORNAME,* ETC.)* - TWO QUEUES REPRESENTING THE TWO LANES YOU'RE MODELING* - AT LEAST ONE TEMPORARY QItem VARIABLE TO STORE USER INPUT* BEFORE ADDING IT TO EACH "LANE"* (YOU MAY WANT A SECOND TEMP VARIABLE SO YOU CAN USE THE* TEMP VARIABLES TO REPRESENT THE CUSTOMERS YOU'RE* SERVING, AND HAVE THE QUEUES JUST HOLD WAITING CUSTOMERS)* - A VARIABLE TO COUNT TIME* - SOMETHING TO TRACK (1) WHETHER YOU'RE SERVING A CUSTOMERFROM* EACH QUEUE AND (2) HOW LONG THAT CUSTOMER HAS LEFT****************************************************************/
/****************************************************************** START WITH FILE HANDLING AS DESCRIBED IN THE SPEC* (THE TEST CASES ARE DESIGNED SO YOU CAN TEST THE FILEHANDLING* WITHOUT IMPLEMENTING ANYTHING ELSE IN THE REST OF THEPROGRAM!)****************************************************************//****************************************************************** THEN, ADD THE LOOP THAT TRACKS TIME AND HANDLES CUSTOMERSERVICE****************************************************************/
return 0;}
QItem.h (has to be modified)
#ifndef QITEM_H#define QITEM_H
class QItem {public:/*********************************************************************** MODIFY THIS CLASS AS YOU SEE FIT--MY SOLUTION USED THE DATAMEMBERS* SHOWN BELOW AND HAD FUNCTIONS THAT ALLOWED ME TO MODIFY ANDREAD* THEM AS NEEDED, BUT YOU MAY COME UP WITH SOMETHINGDIFFERENT*********************************************************************/
private:unsigned cNum; // Customer numberunsigned arrTime; // Arrival timeunsigned svcTime; // Time required to service customer};
Queue.h
#include <iostream>using std::cout;
template <class T>class Queue {public:Queue(unsigned maxSize = 1024);~Queue();bool empty() const;void enqueue(const T &val);void dequeue();T getFront();private:T* list;int front, back;unsigned cap;};
// Constructortemplate <class T>Queue<T>::Queue(unsigned maxSize) : front(0), back(0),cap(maxSize){list = new T[maxSize];}
// Destructortemplate <class T>Queue<T>::~Queue(){delete [] list;}
// True if list is emptytemplate <class T>bool Queue<T>::empty() const {return (front == back); // Returns true if front == back// false otherwise}
// Add new value to back of queuetemplate <class T>void Queue<T>::enqueue(const T &val) {if ((back + 1) % cap == front) // Queue is fullcout << "error\n";
else { // At least one empty spot in queuelist[back] = val;back = (back + 1) % cap;}}
// Remove element at front of Queuetemplate <class T>void Queue<T>::dequeue() {if (!empty()) // Can't remove from empty queuefront = (front + 1) % cap;}
// Retrieve value of element at top of Queuetemplate <class T>T Queue<T>::getFront() {if (!empty())return list[front];// Empty queue--return garbage dataelse {cout << "error: empty queue\n";return list[cap - 1];}}
QItem.cpp
/************************************************** FILE TO HOLD DEFINITIONS FOR QItem FUNCTIONS* ***********************************************/
ASAP C++ Assignment Help This assignment gives you experience working with the queue class template we developed in lect
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am