QuestionQuestion

Transcribed TextTranscribed Text

Re-write you bike rental shop program with STL list and shared pointers. You will need to have just one list to keep the bikes. And I want you to keep the original order of the bikes in that list. But I still want you to print bikes ordered by the id, and manufacturer name, which means the list will have to be sorted every time before you do print. But if you sort the list, you lose the original order. How to solve that problem? You will need to create a copy of the original list before you do sort. But I do not want you to do a copy of the list yourself. What to do? Here is the hint: Recall, that in C++ everything is passed by the value to the calling function. Make a compiler to do a work for you. That's what I will be looking at among other things. To sort a list you will need to have two additional functions to tell STL how do you want to sort the list. Here is one (I'm always ready and willing to do an easiest work): bool comp_id(Bike * b1, Bike * b2) { return b1->id < b2->id; } You will need to write a second function to compare manufacturer names.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

//
// bikes.cpp
//

#include <string.h>

#include "bikes.h"

#ifndef BIKE_CPP
#define BIKE_CPP

//Functions:

/*
*init:-
*Purpose: This function initializes the new Bike's object to all default values
*(char array should be initialized to ""
*/

void init(Bike* newBike) {
    newBike->cost_per_day = 0.0;
    newBike->deleted = false;
    newBike->id_num = 0;
    newBike->manufact[0] = '\0';
    newBike->next = NULL;
    newBike->next_id = NULL;
    newBike->next_manuf = NULL;
    newBike->rented_code = NOT_RENTED;
    newBike->size = 0;
    newBike->to_whom[0] = '\0';
}

/*
* printBikesOnStatus() function accepts a Bike pointer. This pointer might
* be a Bike's next pointer or next_id pointer or next_manuf pointer.
* So that this might print the list according to the pointer passed and
* also depending of the currStatus value
*/
void printBikesOnStatus(Bike* headPtr, status currStatus) {
    if (headPtr->deleted == false) {
       fstream out;
       out.open("run.txt", ios::app);
       ;
       // condition to check whether the rented_code is
       // RENTED
       if (headPtr->rented_code == currStatus) {
            // call the printSingleBike() function
            // to print a single bike information
            cout << setw(10) << left << headPtr->id_num << setw(15) << left << headPtr->manufact;

            cout << setw(15) << left << headPtr->rented_code << setw(15) << left;
            cout << headPtr->to_whom << setw(10) << left;
            cout << headPtr->size << setw(5) << left << headPtr->cost_per_day << endl;

            out << setw(10) << left << headPtr->id_num << setw(15) << left << headPtr->manufact;

            out << setw(15) << left << headPtr->rented_code << setw(15) << left;
            out << headPtr->to_whom << setw(10) << left;
            out << headPtr->size << setw(5) << left << headPtr->cost_per_day << endl;
       }// condition to check whether the rented_code is
            // NOT_RENTED
       else if (headPtr->rented_code == currStatus) {
            cout << setw(10) << left << headPtr->id_num << setw(15) << left << headPtr->manufact;
            cout << setw(15) << left << headPtr->rented_code << setw(15) << left;
            cout << " - " << setw(10) << left;
            cout << headPtr->size << setw(5) << left << headPtr->cost_per_day << endl;

            out << setw(10) << left << headPtr->id_num << setw(15) << left << headPtr->manufact;
            out << setw(15) << left...
$21.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats