Homework Solution: Objectives: The two main objectives of this project is to test your ability to (1) create and use structs with arra…

    Code must be in C++. Thank you for your time! Objectives: The two main objectives of this project is to test your ability to (1) create and use structs with arrays, (2) work with pointers, pointer arithmetic, pass by-Value, pass by-Reference, pass by-Address, and (3) design, implement and test a solution to a given problem. A review of your knowledge of arrays, iostream, file I/O and C-style strings is also included. Description: For this project, you are to create a program that will assist users who want to rent a car. You are given a datafile with 5 different cars file (the file is a priori known to have exactly 5 entries, each following the same data lavout), and you must read in all of the car data from the file and store it in an array of structs. You must also create a menu with the functionality defined below Although an example file is provided (Cars.txt), for grading purposes your project will be tested against a different test file that will not be provided to you beforehand. Our test file will be in the same format as the example file. The RentalCar struct will contain the following data members: year, an int (year of production) make, a C-string (char array of 10 maximum size) model, a C-string (char array of 10 maximum size) price, a float (price per day) available, a bool (1true, 0 - false; try to display true/false using the std: boolalpha manipulator like: cout << boolalpha << boolVariable;) The menu must have the following entries, each implementing a functionality: 1) Ask the user for the input file name, and then read ALL data from that file. The data have to be stored into an array of structs 2) Print out ALL data for all of the cars to the terminal 3) Print out ALL data for all of the cars to a separate output file (when the user chooses menu entry 2, they should also get asked for an output file name) 4) Sort the cars (i.e. sort the array of structs) by ascending price. 5) Ask the user for how many days they want to rent a car. Then print to the terminal only the available cars, sorted by ascending price, as well as the total estimated cost to make the rent (number of days multiplied by price per day) 6) Ask the user which car they want to rent (expected user input is an index number for the array of structs) and for how many days. If the corresponding car is not available, print a warning message to terminal. If it is available, mark it as rented (modify the available member appropriately) and print out to terminal a success message that mentions the total cost (number of days multiplied by price per day) 7 Exit program
    Objectives: The two main objectives of this project is to test your ability to (1) create and use structs with arrays, (2) work with pointers, pointer arithmetic, pass by-Value, pass by-Reference, pass by-Address, and (3) design, implement and test a solution to a given problem. A review of your knowledge of arrays, iostream, file I/O and C-style strings is also included. Description: For this project, you are to create a program that will assist users who want to rent a car. You are given a datafile with 5 different cars file (the file is a priori known to have exactly 5 entries, each following the same data lavout), and you must read in all of the car data from the file and store it in an array of structs. You must also create a menu with the functionality defined below Although an example file is provided (Cars.txt), for grading purposes your project will be tested against a different test file that will not be provided to you beforehand. Our test file will be in the same format as the example file. The RentalCar struct will contain the following data members: year, an int (year of production) make, a C-string (char array of 10 maximum size) model, a C-string (char array of 10 maximum size) price, a float (price per day) available, a bool (1true, 0 - false; try to display true/false using the "std: boolalpha" manipulator like: cout

    Expert Answer

     
    // C++ code #include <iostream>

    Code must be in C++. Thank you coercion your time!

    Objectives: The couple deep objectives of this artifice is to criterion your power to (1) constitute and representation structs with determined-in-orders, (2) result with pointers, pointer arithmetic, by by-Value, by by-Reference, by by-Address, and (3) artifice, tool and criterion a key to a fond amount. A criticism of your information of determined-in-orders, iostream, refine I/O and C-phraseology strings is to-boot intervening. Description: Coercion this artifice, you are to constitute a program that earn benefit representationrs who shortness to fissafe a car. You are fond a factsrefine with 5 diffefissafe cars refine (the refine is a priori unreserved to enjoy precisely 5 entries, each subjoined the identical facts lavout), and you must recognize in every of the car facts from the refine and provision it in an determined-in-order of structs. You must to-boot constitute a menu with the exerciseality defined adown Although an issue refine is supposing (Cars.txt), coercion grading purposes your artifice earn be criterioned despite a diffefissafe criterion refine that earn referable be supposing to you preparedly. Our criterion refine earn be in the identical coercionmat as the issue refine. The FissurealCar struct earn inclose the subjoined facts constituents: year, an int (year of evolution) coercionm, a C-string (char determined-in-order of 10 climax extent) standard, a C-string (char determined-in-order of 10 climax extent) appraisement, a transport (appraisement per day) beneficial, a bool (1true, 0 - fiction; probe to ostentation penny/fiction using the std: boolalpha manipulator like: cextinguished << boolalpha << boolVariable;) The menu must enjoy the subjoined entries, each tooling a exerciseality: 1) Ask the representationr coercion the input refine spectry, and then recognize ALL facts from that refine. The facts enjoy to be provisiond into an determined-in-order of structs 2) Sculpture extinguished ALL facts coercion every of the cars to the marginal 3) Sculpture extinguished ALL facts coercion every of the cars to a disconnected extinguishedput refine (when the representationr adopts menu enprobe 2, they should to-boot achieve asked coercion an extinguishedput refine spectry) 4) Manner the cars (i.e. manner the determined-in-order of structs) by ascending appraisement. 5) Ask the representationr coercion how multifarious days they shortness to fissafe a car. Then sculpture to the marginal merely the beneficial cars, mannered by ascending appraisement, as polite as the completion estimated consume to coercionm the fissafe (sum of days various by appraisement per day) 6) Ask the representationr which car they shortness to fissafe (expected representationr input is an renunciation sum coercion the determined-in-order of structs) and coercion how multifarious days. If the corresponding car is referable beneficial, sculpture a admonition intimation to marginal. If it is beneficial, trace it as fissureed (variegate the beneficial constituent correctly) and sculpture extinguished to marginal a luck intimation that mentions the completion consume (sum of days various by appraisement per day) 7 Exit program

    Objectives: The couple deep objectives of this artifice is to criterion your power to (1) constitute and representation structs with determined-in-orders, (2) result with pointers, pointer arithmetic, by by-Value, by by-Reference, by by-Address, and (3) artifice, tool and criterion a key to a fond amount. A criticism of your information of determined-in-orders, iostream, refine I/O and C-phraseology strings is to-boot intervening. Description: Coercion this artifice, you are to constitute a program that earn benefit representationrs who shortness to fissafe a car. You are fond a factsrefine with 5 diffefissafe cars refine (the refine is a priori unreserved to enjoy precisely 5 entries, each subjoined the identical facts lavout), and you must recognize in every of the car facts from the refine and provision it in an determined-in-order of structs. You must to-boot constitute a menu with the exerciseality defined adown Although an issue refine is supposing (Cars.txt), coercion grading purposes your artifice earn be criterioned despite a diffefissafe criterion refine that earn referable be supposing to you preparedly. Our criterion refine earn be in the identical coercionmat as the issue refine. The FissurealCar struct earn inclose the subjoined facts constituents: year, an int (year of evolution) coercionm, a C-string (char determined-in-order of 10 climax extent) standard, a C-string (char determined-in-order of 10 climax extent) appraisement, a transport (appraisement per day) beneficial, a bool (1true, 0 – fiction; probe to ostentation penny/fiction using the “std: boolalpha” manipulator like: cout

    Expert Exculpation

     

    // C++ code

    #include <iostream>
    #include <iomanip>
    #include <fstream>

    using spectryspace std;
    const int CAR_COUNT = 10;

    struct fissurealCar {
    char coercionm[20];
    char standard[20];
    int year;
    transport appraisement;
    bool beneficial;
    };

    void picked(int &selection);
    void recognizeFile(rentalCar cars[]);
    void sculptureCars(bool beneficialOnly, fissurealCar cars[]);
    void estimatePrice(rentalCar cars[]);
    void mostExpensive(rentalCar cars[]);

    main() {
    /* Ostentation Menu */
    int pickedion = 0; // trusts pickedion sum
    do {
    /* Sculpture Menu Title */
    cextinguished << determinedfill(‘-‘) << determinedw(80) << “-” << endl
    << “Rent-A-Vehicle” << endl << determinedfill(‘-‘)
    << determinedw(80) << “-” << endl;

    /* Ostentation Items */
    cextinguished << “[1] Recognize facts from refine” << endl;
    cextinguished << “[2] Sculpture extinguished every facts coercion every cars” << endl;
    cextinguished << “[3] Estimate car fissureal consume” << endl;
    cextinguished << “[4] Find most dear car” << endl;
    cextinguished << “[5] Sculpture extinguished every beneficial cars” << endl;
    cextinguished << “[6] Exit program” << endl;
    cextinguished << determinedfill(‘-‘) << determinedw(80) << “-” << endl;

    /* Achieve Menu Pickedion */
    select(selection);

    rentalCar cars[CAR_COUNT]; // constitute determined-in-order of cars

    switch (selection) {
    case 1:
    readFile(cars); // hurry recognizeRefine exercise and provide the cars determined-in-order
    break;
    case 2:
    printCars(false, cars); // hurry sculptureCars exercise
    break;
    case 3:
    estimatePrice(cars); // hurry estimateAppraisement exercise and provide the cars determined-in-order
    break;
    case 4:
    mostExpensive(cars); // hurry mostDear exercise and provide the cars determined-in-order
    break;
    case 5:
    printCars(true, cars); // hurry sculptureCars exercise
    break;
    case 6:
    cextinguished << “Exiting program” << endl; // referableify representationr that the program is exiting
    break;
    default:
    cextinguished << “Incorrect input” << endl; // referableify representationr that the input is wrong
    }

    } suitableness (segregation != 6); // remain loop as desire as representationr did referable adopt to exit

    return 0;
    }

    void picked(int &selection) {
    cextinguished << “Selection: “;
    cin >> pickedion; // achieve representationr input and obviate it to pickedion variable
    cextinguished << determinedfill(‘-‘) << determinedw(80) << “-” << endl;
    }

    void recognizeFile(rentalCar cars[]) {
    iftendency fin; // Constitute input tendency variable
    char ifileName[20]; // Constitute var to trust input refine spectry
    cextinguished << “Enter input refine spectry: “;
    cin >> ifileName; // Obviate representationr input to refine spectry
    fin.open(ifileName); // notorious representationr-definied refine
    if (fin.is_open()) // Stay if refine notorioused correctly
    {
    coercion (int i = 0; i < CAR_COUNT; i++) { // loop through each car in cars determined-in-order
    /* Populate cars determined-in-order with facts from representationr-defined refine */
    fin >> cars[i].year >> cars[i].form >> cars[i].model
    >> cars[i].appraisement >> cars[i].available;
    }
    cextinguished << “Facts from ” << ifileSpecendeavor << ” recognize luckfully” << endl;

    } else { cextinguished << “Failed to notorious refine spectryd ” << ifileName; }
    }

    void sculptureCars(bool beneficialOnly, fissurealCar cars[]) {
    if (availableMerely != penny) { // stay beneficialMerely flag
    cextinguished << “Every facts coercion every cars:” << endl;
    } else {
    cextinguished << “Every facts coercion beneficial cars:” << endl;
    }

    /* Sculpture extinguished consideration labels */
    cextinguished << determinedfill(‘~’) << determinedw(51) << “~” << endl
    << determinedfill(‘ ‘) << left << determinedw(8) << “YEAR” << determinedw(10) << “MAKE”
    << determinedw(11) << “MODEL” << determinedw(13) << “PRICE/DAY” << “AVAILABLE” << endl
    << determinedfill(‘~’) << determinedw(51) << “~” << endl;

    coercion (int i = 0; i < CAR_COUNT; i++) { // loop through each car in cars determined-in-order
    /* If beneficialMerely is penny, coercionm safe to merely sculpture cars with beneficial determined to penny */
    if (cars[i].beneficial != fiction || beneficialMerely != penny) {
    /* Sculpture and phraseology each car’s facts */
    cextinguished << determinedfill(‘ ‘) << left << determinedw(8) << cars[i].year
    << determinedw(10) << cars[i].form << determinedw(11) << cars[i].model
    << ‘$’ << determinedw(12) << cars[i].appraisement << determinedw(7)
    << boolalpha << cars[i].beneficial << endl;
    }
    }
    }

    void estimatePrice(rentalCar cars[]) {
    int carNumber; // constitute var to trust car sum choice
    int dayCount; // constitute var to trust day compute choice
    cextinguished << “Enter car sum (1-10): “;
    cin >> carNumber; // achieve representationr input and obviate to carNumber
    cextinguished << “Enter sum of days you shortness to fissure: “;
    cin >> dayCount;// achieve representationr input and obviate to dayCount

    transport consume = cars[carNumber-1].price*dayCount; // weigh developed consume
    cextinguished << “Your estimated completion consume is: $” << consume << endl;
    }

    void mostExpensive(rentalCar cars[]) {
    int mostExpensiveRenunciation = 0; // Renunciation of the most dear car
    coercion (int i = 0; i < CAR_COUNT; i++) { // loop through each car in cars determined-in-order
    if (cars[i].appraisement > cars[mostExpensiveIndex].price) { // if this appraisement is bigger than the biggest..
    mostExpensiveRenunciation = i; // determined the biggest to this
    }
    }

    cextinguished << “Most dear car: ”
    << cars[mostExpensiveIndex].year << ” ”
    << cars[mostExpensiveIndex].form << ” ”
    << cars[mostExpensiveIndex].standard << endl;
    }

    =========================================

    car.txt

    2012 Honda CRV 85.10 0
    2014 Toyota Tacoma 115.12 1
    2015 Coerciond Fusion 90.89 0
    2013 GMC Yukon 110.43 0
    2009 Dodge Neon 45.25 1
    2011 Toyota Rav4 65.02 1
    2012 Mazda CX5 86.75 1

    ============================================

    sample extinguishedput: