Question

In: Computer Science

write a c++ code for following application You have been hired by XYZ Car Rental to...

write a c++ code for following application You have been hired by XYZ Car Rental to develop a software system for their business.
Your program will have two unordered lists, one of Cars and one of Reservations. 

The Car class will have the following data:
        string plateNumber (this is the key)
        string make
        string model
        enum vehicleType (VehicleType Enumeration of options: sedan, suv, exotic)
        double pricePerDay
        bool isAvailable

        isAvailable should be set to true on initialization, and a public setter method should
        be exposed SetAvailable(bool available); 

Reservation will have the following:
        string name (key)
        string vehicleRented (plate of the car which is our key for the list)


The Program class will be composed of the two lists. 
There will also be a method to display a menu that will have the following options, 
Create a method to process the user's input and call appropriate methods to perform the operation requested.
(Use a switch statement and call the appropriate methods based on the number the user puts in)

    -------------------------------------------
    XYZ Car Rental
    -------------------------------------------
    1. List all cars
    2. Add car to inventory
    3. Remove car from inventory
    4. List all reservations
    5. Add a reservations
    6. Cancel reservation
    7. Exit

Option 1: 
    List all the cars in the unordered list of cars
     (Overload the << operator like my example to print each car's info)

Option 2: 
    Prompt for all the information for a vehicle. 
    Create the vehicle and add it to the list of available vehicles

Option 3:
    Remove a vehicle from the list of available cars. 
    If the car is not available (a user has rented it) return an error message and don't remove the vehicle

Option 4: 
    List all the reservations. Use the key in the reservation to retrieve the vehicle details from the list of vehicles

Option 5: 
    Prompt the user for a name. 
    List all the cars that are available (isAvailable=true):
        1. Nissan Sentra (sedan) $24/day
            2. ...
            n+1. Cancel
    
    Prompt the user to enter an option. Your list will need to implement a GetItemAtIndex
    method which will let you select a vehicle based on the menu option. For example if the user selects 1, you would call GetItemAtIndex(choice - 1). 
    Make sure this returns a car reference: Car& GetItemAtIndex(int index) 
    Create a reservation object with this car's plate and the user's name, and call the car's SetAvailable method with  false passed as the argument; 
    If cancel is pressed, show all the original options again

Option 6:
    Propt the user for a name. Remove the reservation object from the list if that user's name is a key. 
    Use the plate number to find the car in the list and set available to true (Make sure the GetItem method returns a reference)

At the end of each option's method (except Exit) make sure ot list the menu options again.
For Exit, quit the program. 

Solutions

Expert Solution

#include<iostream>
#define MAX 100
using namespace std;
enum vehicleType{sedan,suv,exotic};
class car
{
   private:
       string plateNumber;
       string make;
       string model;
       //vehicleType VT;
       double pricePerDay;
       bool isAvailable;
   public:
       car()
       {
           isAvailable=true;
       }
       string getplateNumber()
       {
           return plateNumber;
       }
       void setPlateNumber(string plateNumber_)
       {
           plateNumber=plateNumber_;
       }
       string getMake()
       {
           return make;
       }
       void setMake(string make_)
       {
           make=make_;
       }
       string getModel()
       {
           return model;
       }
       void setModel(string model_)
       {
           model=model_;
       }
//       int getVehicleType()
//       {
//           return VT;
//       }
//       void setVehicleType(vehicleType VT_)
//       {
//           VT=VT_;
//       }
       double getPrice()
       {
           return pricePerDay;
       }
       void setPrice(double price)
       {
           pricePerDay=price;
       }
       bool getIsAvailable()
       {
           return isAvailable;
       }
       void setIsAvailable(bool val)
       {
           isAvailable=val;
       }
};
class reservation
{
   private:
       string name;
       string vehicleRented;
   public:
       string getName()
       {
           return name;
       }
       void setName(string name_)
       {
           name=name_;
       }
       string getVehicleRented()
       {
           return vehicleRented;
       }
       void setVehicleRented(string val)
       {
           vehicleRented=val;
       }
};
int getChoice()
{
   int ch;
   cout<<"1. List all cars\n";
   cout<<"2. Add car to inventory\n";
   cout<<"3. Remove car from inventory\n";
   cout<<"4. List all reservations\n";
   cout<<"5. Add a reservation\n";
   cout<<"6. Cancel reservation\n";
   cout<<"7. Exit\n";
   cout<<" Enter your choice:";
   cin>>ch;
   return ch;
}
class carList
{
   private:
       class car list[MAX];
       int size;
   public:
       carList()
       {
           size=0;
       }
       car GetItemByIndex(int index)
       {
           if(index<size)
           {
               return list[index];
           }
           else
           {
               cout<<"\nInvalid Index\n";
           }
  
       }
       void ViewCar()
       {
           if(size>0)
           {
              
               class car tempCar;
               for(int i=0;i<size;i++)
               {
                   tempCar=GetItemByIndex(i);
                  
                   cout<<"Plate Number: "<<tempCar.getplateNumber()<<" Make: "<<tempCar.getMake()<<" Model: "<<tempCar.getModel()<<" VehicleType: "/*<<tempCar.getVehicleType()*/<<" Price Per Day: "<<tempCar.getPrice()<<" Available: "<<(tempCar.getIsAvailable()?"Yes":"No")<<endl;
               }
           }
           else
           {
               cout<<"\nNo data in the list\n";
           }
       }
       void addNewCar()
       {
           class car newCar;
string tempdata;
double price;
//VehicleType VT;
cout<<"Car plate detail:";
cin>>tempdata;
newCar.setPlateNumber(tempdata);
cout<<"Car make detail:";
cin>>tempdata;
newCar.setMake(tempdata);
cout<<"Car model detail:";
cin>>tempdata;
newCar.setModel(tempdata);
// cout<<"Car Vehicle Type detail:";
// cin<<VT;
// newCar.setVehicleType(VT);
cout<<"Car price detail:";
cin>>price;
newCar.setPrice(price);
list[size]=newCar;
size++;
}
int getVehicleByPlateNumber(string plateNumber)
{
   for(int i=0;i<size;i++)
   {
       if(list[i].getplateNumber()==plateNumber)
       {
           return i;
               }
           }
   return -1;
       }
       void RemoveCar()
       {
          
           cout<<"\nEnter Plate number:";
           string vehiclePlate_;
           cin>>vehiclePlate_;
           int index=getVehicleByPlateNumber(vehiclePlate_);
           if(index>=0)
           {
               list[index]=list[size-1];
               size--;
           }
           else
           {
               cout<<"\nno vehicle found\n";
           }
       }
       void setAvailablityByindex(int index,bool val)
       {
           if(index<size&&index>=0)
           {
               list[index].setIsAvailable(val);
           }
       }
       bool getAvailablityByindex(int index)
       {
           if(index<size&&index>=0)
           {
               return list[index].getIsAvailable();
           }
           return false;
       }
  
};

class reservationList
{
   private:
       class reservation list[MAX];
       int size;
   public:
       reservationList()
       {
           size=0;
       }
       reservation GetItemByIndex(int index)
       {
           if(index<size)
           {
               return list[index];
           }
           else
           {
               cout<<"\nInvalid Index\n";
           }
  
       }
       void ViewReservation()
       {
           if(size>0)
           {
              
               class reservation tempReservation;
               for(int i=0;i<size;i++)
               {
                   tempReservation=GetItemByIndex(i);
                  
                   cout<<"Name: "<<tempReservation.getName()<<" Vehicle Rented: "<<tempReservation.getVehicleRented()<<endl;
               }
           }
           else
           {
               cout<<"\nNo data in the list\n";
           }
       }
       void addNewReservation(class carList *cList)
       {
           class reservation newreservation;
string tempdata;
double price;
cout<<"Customer name:";
cin>>tempdata;
newreservation.setName(tempdata);
cout<<"Vehicle Rented(Plate Number):";
cin>>tempdata;
int index=cList->getVehicleByPlateNumber(tempdata);
if(index>=0)
{
   if(cList->getAvailablityByindex(index))
   {
       cList->setAvailablityByindex(index,false);
       newreservation.setVehicleRented(tempdata);
       list[size]=newreservation;
       size++;
               }
               else
               {
                   cout<<"\nVehicle Not Available\n";
               }
           }
  
}
int getReservationByName(string name)
{
   for(int i=0;i<size;i++)
   {
       if(list[i].getName()==name)
       {
           return i;
               }
           }
   return -1;
       }
       void cancelReservation(class carList *cList)
       {
          
           cout<<"\nEnter name:";
           string name;
           cin>>name;
           int index=getReservationByName(name);
           if(index>=0)
           {
               //getReservationByIndex(index).getVehicleRented();
               int carIndex=cList->getVehicleByPlateNumber(GetItemByIndex(index).getVehicleRented());
              
               cList->setAvailablityByindex(carIndex,true);
               list[index]=list[size-1];
               size--;
           }
           else
           {
               cout<<"\nNo reservation found\n";
           }
       }
  
};
void callFunction(int ch, class carList *cList,class reservationList *rList)
{
switch(ch)
{
case 1:
cList->ViewCar();
break;
case 2:
cList->addNewCar();
break;
case 3:
cList->RemoveCar();
break;
case 4:
rList->ViewReservation();
break;
case 5:
rList->addNewReservation(cList);
break;
case 6:
rList->cancelReservation(cList);
break;
default:
if(ch!=7)
cout<<"\nInvalid choice\n";
  
}
}
int main()
{
int ch = -1;
class carList cList;
class reservationList rList;
while (ch != 7)
{
ch = getChoice ();
callFunction(ch,&cList,&rList);
}
return 0;
}


Related Solutions

You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays...
You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays the cost of a customer’s yogurt purchase. Use a validation loop to prompt for and get from the user the number of yogurts purchased in the range 1-9. Then use a validation loop to prompt for and get from the user the coupon discount in the range 0-20%. Calculate the following:         ● Subtotal using a cost of $3.50 per yogurt.         ● Subtotal...
You've been hired by Avuncular Addresses to write a C++ console application that analyzes and checks...
You've been hired by Avuncular Addresses to write a C++ console application that analyzes and checks a postal address. Prompt for and get from the user an address. Use function getline so that the address can contain spaces. Loop through the address and count the following types of characters:         ● Digits (0-9)         ● Alphabetic (A-Z, a-z)         ● Other Use function length to control the loop. Use functions isdigit and isalpha to determine the character types. Use formatted...
You've been hired by Water Wonders to write a C++ console application that analyzes lake level...
You've been hired by Water Wonders to write a C++ console application that analyzes lake level data. MichiganHuronLakeLevels.txt. Place the input file in a folder where your development tool can locate it (on Visual Studio, in folder \). The input file may be placed in any folder but a path must be specified to locate it. MichiganHuronLakeLevels.txt Down below: Lake Michigan and Lake Huron - Average lake levels - 1860-2015 Year    Average level (meters) 1860    177.3351667 1861    177.3318333 1862    177.316...
You've been hired by Water Wonders to write a C++ console application that analyzes lake level...
You've been hired by Water Wonders to write a C++ console application that analyzes lake level data. Place the input file in a folder where your development tool can locate it (on Visual Studio, in folder <project-name>\<project-name>). The input file may be placed in any folder but a path must be specified to locate it. The input file has 158 lines and looks like this: Lake Michigan and Lake Huron - Average lake levels - 1860-2015 Year    Average level (meters)...
Lab 10-2:You've been hired by Yogurt Yummies to write a C++ console application that calculates and...
Lab 10-2:You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays the cost of a customer’s yogurt purchase. Use a validation loop to prompt for and get from the user the number of yogurts purchased in the range 1-9. Then use a validation loop to prompt for and get from the user the coupon discount in the range 0-20%. Calculate the following:           ● Subtotal using a cost of $3.50 per yogurt. ● Subtotal...
You have been hired by XYZ as a consultant. They are currently facing a union organizing campaign.
You have been hired by XYZ as a consultant. They are currently facing a union organizing campaign. You have been asked to write a briefing memo for senior management. Your memo must address:a. What are the basic differences, from the employer's viewpoint, in operating in a union-free environment vs. a unionized environment?b. What is management representatives permitted to say and do during the campaign? What, if any, actions or statements are prohibited?
You have been hired by a used-car dealership to modify the price of cars that are...
You have been hired by a used-car dealership to modify the price of cars that are up for sale. You will get the information about a car, and then change its price tag depending on a number of factors. Write a program (a script named: 'used_cars.m' and a function named 'car_adjust.m').The script passes the file name 'cars.dat' to the function. The following information is stored inside the file: Ford, 2010 with 40,000 miles and no accident at marked price of...
1. Write pseudocode for the following program. You do not have to write actual C++ code....
1. Write pseudocode for the following program. You do not have to write actual C++ code. Assume you have a text file, that has been encrypted by adding 10 to the ASCII value of each character in the message. Design a decryption program that would reverse this process, and display the original message to the console.to the new array. 2.Write the code for the specified program. Use proper style and naming. Test and upload your code as a CPP file....
You have been recently hired as an assistant controller for XYZ Industries, a large, publically held...
You have been recently hired as an assistant controller for XYZ Industries, a large, publically held manufacturing company. Your immediate supervisor is the controller who also reports directly to the VP of Finance. The controller has assigned you the task of preparing the year-end adjusting entries. In the receivables area, you have prepared an aging accounts receivable and have applied historical percentages to the balances of each of the age categories. The analysis indicates that an appropriate estimated balance for...
Data Scenario: You have just been hired into a management position which requires the application of...
Data Scenario: You have just been hired into a management position which requires the application of your budgeting skills. You find out that budgeting has not been a priority of the company and that they have been experiencing cash shortages. You have contacted various areas on the organization and have accumulated the information below to assist you in preparing a comprehensive budget.                                                                                                                               The following is actual information that relates to the operations of a merchandiser named Sled Company, a wholesaler...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT