Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m stuck on this program I need to get the output correct here is the problem

ID: 3621449 • Letter: I

Question

I'm stuck on this program I need to get the output correct here is the problem Problem statement: The purpose of this program is to simulate the operation of a taxi company that serves customers around town and to generate a report that summarizes the operation of the company. In this assignment, the company may have multiple cabs serving customers. A cab may be sent to a garage for maintenance occasionally. Use classes provided below (The Vehicle class is slight modified). • The company will process events in the order as they appear in the file “event.dat”, which can contain the following types of events: o customer request: customer(s) require the service of the company. This event is the same as in the previous assignment. o A cab is sent to a garage for maintenance. o A cab has finished its maintenance and is back for service. Each line of the file “event.dat” can be one of the following forms: o C Customer1 12 24 60 80 3 // customer request (id, x1, y1, x2, y2, n) o S 1 // Sending the cab with id 1 to the garage for maintenance o R 3 // Returning the cab with id 3 for service • Print the report that summarizes each customer request processing o The location of customer, origin location, and destination location o Id of cab dispatched with related information: ?? the location of the cab dispatched, ?? the amount of fuel before and after the service ?? total miles traveled ?? the amount of gas refueled (possibly zero) • Print the event information as the taxi is sent to the garage and returned. • ListP.h and an incomplete ListP.cc are provided in $PUB/OLA/OLA5. You should complete 3 incomplete member functions (copy constructor, find, and insert). Assumption: • The company operates 5 cabs. Initially, all of them are at the location (0, 0) and are ready to serve customers. Each cab has full tank (20 gallons) of gas and no passenger on board. • The cab ids are 1, 2, 3, 4, and 5. • For simplicity, the company can process the next event only if the current event has been processed. For example, if the current event is a customer request, then the company can process the next event only if the customers have been dropped off at the destination. • To serve the customer as soon as possible, the company always dispatches the closest cab to the waiting customer. If multiple cabs are the same distance from the customer, the cab with a smaller cab ID will be dispatched. • For simplicity, a cab will be dispatched, pickup and drop off customer(s) instantaneously. It means that we do not consider a service time. • Events will be processed in the same order as it is listed in the file. • When a cab is sent to garage for maintenance, the driving distance and consumed gas to the garage is ignored. • When a cab is returned from the garage, it is returned to the last location before doing maintenance. (if it is returned to the location (0, 0), we have to provide another member function for class Vehicle to reset vehicle’s location.) • The maintenance doesn’t reset or change the totalMilesTravelled and totalFuelConsumed of a cab. • A location at this program is represented by a pair of integers as x and y coordinates. • It is guaranteed that there are no more than 5 customers per customer request. • It is guaranteed that at least one cab is ready to serve customers at any time. Class design: A cab used in this program is an instantiation of Vehicle class. Use the following class diagram that defines this class which is modified from OLA4. The underlined members are newly added for OLA5. (You may add more methods and/or data members as needed.) Vehicle - cab ID - passenger: integer - remainingFuel: double - totalMilesTraveled: double - totalFuelConsumed: double - x: int - y: int + Vehicle() + Vehicle( int id ) + pickupCustomer(int, int, int) + dropoffCustomer(int, int) + getLocation (int, int) + getID( ) - moveTo (int, int) - loadPassenger (int) - unloadPassenger ( ) - fillUpGas ( ) When a customer requests for a cab: • A cab which is located nearest to the customer will be dispatched to serve the customer. • A cab will be dispatched to customer’s location (x-location,y-location) to pick up number-ofpassengers and drive to the destination (x-destination, y-destination). • Cab will fill the gas tank to its capacity if it finds it cannot reach the destination with the remaining fuel – i.e., it will compute the amount of fuel needed to drive to the destination, and it will fill up the gas tank if it does not have enough gas. The gas mileage of the vehicle is given without any passenger (We do not count the driver as a passenger.) Each passenger on the vehicle will reduce the gas mileage by 5 %. For example the gas mileage changes as the following table. Number of passenger Gas mileage (mpg) 0 30.0 1 30*95%=28.5 2 30*90%=27.0 3 30*85%=25.5 4 30*80%=24.0 5 30*75%=22.5 Sample input data: C Customer1 12 24 60 80 3 C Customer2 35 26 57 65 2 C Customer3 99 10 10 100 4 S 2 C Customer4 300 300 150 300 1 S 1 Customer5 350 200 500 100


this is what I have:

// *********************************************************
// Implementation file ListP.cc for the ADT list.
// Pointer-based implementation.
// *********************************************************
#include "ListP.h" // header file
#include // for NULL
#include // for assert()
#include

using namespace std;
List::List(): size(0), head(NULL)
{
} // end default constructor

// Copy Constructor: Deep copy
List::List(const List& aList): size(aList.size)
{
/* **********************************
Complete this function member
**************************************/

if (aList.head == NULL)
head= NULL;

else
{
  head= new ListNOde;
  head->item= alist.head->item;
  
  ListNOde *newPtr= head;
  for(ListNode *origPtr= aLIst.head->next;origPtr !=NULL;origPtr= origPtr->next)
  {
   newPtr->next= new ListNode;
   newPtr = newPtr->next;
   newPtr->item= origPtr->item;
  }
  newPtr->next= NULL;
}  
} // end copy constructor

List::~List()
{
   while (!isEmpty())
      remove(1);
} // end destructor

bool List::isEmpty() const
{
   return bool(size == 0);
} // end isEmpty

int List::getLength() const
{
   return size;
} // end getLength

// --------------------------------------------------
// find function: Locates a specified node in a linked list.
// Precondition: index is the number of the
// desired node.
// Postcondition: Returns a pointer to the desired
// node. If index < 1 or index > the number of
// nodes in the list, returns NULL.
// --------------------------------------------------
List::ListNode *List::find(int index) const
{
/* **********************************
Complete this function member
**************************************/

if( (index<1)|| (index>getLength()))
return NULL;

else
{
ListNode *cur= head;
for(int skip=1;skip    cur= cur->next;
   return cur;
}

} // end find

void List::retrieve(int index,
                    ListItemType& dataItem) const
{
   if ((index < 1) || (index > getLength()))
cout << "ListOutOfRangeException: retrieve index out of range";
   else
   { // get pointer to node, then data in node
      ListNode *cur = find(index);
      dataItem = cur->item;
   } // end if
} // end retrieve


// insert member function
void List::insert(int index, ListItemType newItem)
{
/* **********************************
Complete this function member
**************************************/
int newLength= getLength()+1;

if((index<1) || (index > newLength))
    throw ListIndexOutOfRangeException("ListIndexOutOfRangeException:insert index out of range");
   
    else
    {
    size= newLength;
    newPtr->item= newItem;
   
    if(index==1)
    {
      newPtr->next= head;
      head= newPtr;
  }
  else
  {
   ListNode *prev= find(index-1);
   newPtr->next= prev->next;
   prev->next= newPtr;
  }
}
}// end insert


void List::remove(int index)
{
   ListNode *cur;

   if ((index < 1) || (index > getLength()))
cout << "ListOutOfRangeException: remove index out of range";
   else
   { --size;
      if (index == 1)
      { // delete the first node from the list
         cur = head; // save pointer to node
         head = head->next;
      }

      else
      { ListNode *prev = find(index-1);
         // delete the node after the
         // node to which prev points
         cur = prev->next; // save pointer to node
         prev->next = cur->next;
      } // end if

      // return node to system
      cur->next = NULL;
      delete cur;
      cur = NULL;
   } // end if
} // end remove


// *********************************************************
// Header file ListP.h for the ADT list.
// Pointer-based implementation.
// *********************************************************

// Must define ListItemType before compilation
#include
#include "Vehicle.h"
typedef Vehicle ListItemType;

class List
{
public:
// constructors and destructor:
List(); // default constructor
List(const List& aList); // copy constructor
~List(); // destructor

// list operations:
bool isEmpty() const;
int getLength() const;
void insert(int index, ListItemType newItem);
void remove(int index);
void retrieve(int index, ListItemType& dataItem) const;

private:
struct ListNode // a node on the list
{
ListItemType item; // a data item on the list
ListNode *next; // pointer to next node
}; // end struct

int size; // number of items in list
ListNode *head; // pointer to linked list of items

ListNode *find(int index) const;
// Returns a pointer to the index-th node
// in the linked list.
}; // end class
// End of header file.

this is the main program:

#include "Vehicle.h"
#include <stdlib.h>
#include <fstream>
#include <string>
#include <iostream>

using namespace std;

int main()
{
ifstream Infile;
string fileName;
string customerid;
int xlocation;
int ylocation;
int xdestination;
int ydestination;
int numpassengers;

Vehicle Cab(0, 0, 20.0, 0);

while(!Infile)
{
  cout<<"File could not open"<<endl;
  cout<<"Enter file again:";
  cin>> fileName;
  Infile.open(fileName.c_str());
}

Infile>> event;

while(Infile)
{
  switch(event)
  {
   case C:
    Infile>>customerId>>x-cust-loc>>y-cust-loc>>x-destination>>y-destination>>no-customer;
    picupCustomer(x-cust-loc, y-cust-loc);
    retrieve(theCab,loc);
    remove(loc,cabList list);
    pickupCustomer(x-cust-loc, y-cust-loc);
    dropoffCustomer(x-destination, y-destination);
    break;
   case S:
    cin>>cabID;
    //Find the cab in the list and send it to the garage list using for-loop
    for-loop (i=1;i<=cabList.getLength();i++)
    retrieve(aCab,cabList);
    
       if( aCab.getID()) == ( cabID) (equal to)
    {
     remove(i,cabList);
     insert(aCab,1);
    break;
   case R:
    cin>>cabID;
    
    return cabId;
  }
   Infile>> event;
   default;
}
     
return 0;
}

Explanation / Answer

Dear, Here is the code //Header file section #include #include #include #include using namespace std; //Defining class class Vehicle { public: Vehicle(); Vehicle(int , int , double , double ); void pickupCustomer(); void dropoffCustomer(); void PrintRequest(); void RequestProccesing(string , int ,int ,int , int , int ); private: int passenger; int xlocation; int ylocation; int numpassengers; double remainingFuel; int xdistance; int ydistance; double needGas; string customerid; double totalMilesTraveled; double totalFuelConsumed; void moveTo(int,int,int,double); void loadPassenger(); void unloadPassenger(); void fillUpGas(); }; //defining constructor Vehicle::Vehicle(int x, int y, double rf, double tf) { xlocation= x; ylocation= y; remainingFuel= rf; totalFuelConsumed= tf; } //Member function definitions void Vehicle::RequestProccesing(string Id, int Clx, int Cly,int Xd,int Yd, int np) { customerid= Id; xlocation= Clx; ylocation= Cly; xdistance= Xd; ydistance= Yd; numpassengers= np; } void Vehicle::PrintRequest() { cout