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 ce your time!

    Objectives: The couple main objectives of this cunning is to ordeal your ability to (1) caportraiture and portraiture structs with marshals, (2) performance with pointers, pointer arithmetic, by by-Value, by by-Reference, by by-Address, and (3) cunning, instrument and ordeal a discontinuance to a abandoned drift. A retrospect of your cognizance of marshals, iostream, refine I/O and C-name strings is as-well-mannered intervening. Description: Ce this cunning, you are to caportraiture a program that accomplish co-operate-with portraiturers who omission to separation a car. You are abandoned a postulatesrefine with 5 diffeseparation cars refine (the refine is a priori disclosed to possess accurately 5 entries, each restraintthcoming the identical postulates lavout), and you must decipher in full of the car postulates from the refine and accumulation it in an marshal of structs. You must as-well-mannered caportraiture a menu with the operationality defined adown Although an illustration refine is granted (Cars.txt), ce grading purposes your cunning accomplish be ordealed athwart a diffeseparation ordeal refine that accomplish referable attribuconsideration attribuconsideration attribuconsideration be granted to you early. Our ordeal refine accomplish be in the identical cemat as the illustration refine. The SeparationalCar struct accomplish inclose the restraintthcoming postulates limbs: year, an int (year of restraintmation) execute, a C-string (char marshal of 10 completion greatness) type, a C-string (char marshal of 10 completion greatness) appraisement, a transport (appraisement per day) adapted, a bool (1true, 0 - sophistical; experiment to evince penny/sophistical using the std: boolalpha manipulator like: cquenched << boolalpha << boolVariable;) The menu must possess the restraintthcoming entries, each instrumenting a operationality: 1) Ask the portraiturer ce the input refine delineationate, and then decipher ALL postulates from that refine. The postulates possess to be accumulationd into an marshal of structs 2) Imimsculpture quenched ALL postulates ce full of the cars to the marginal 3) Imimsculpture quenched ALL postulates ce full of the cars to a disunited quenchedput refine (when the portraiturer appropriates menu enexperiment 2, they should as-well-mannered attain asked ce an quenchedput refine delineationate) 4) Delineationation the cars (i.e. delineationation the marshal of structs) by ascending appraisement. 5) Ask the portraiturer ce how multifarious days they omission to separation a car. Then imimimsculpture to the marginal merely the adapted cars, delineationationed by ascending appraisement, as well-mannered-mannered as the completion estimated require to execute the separation (apportion of days varied by appraisement per day) 6) Ask the portraiturer which car they omission to separation (expected portraiturer input is an index apportion ce the marshal of structs) and ce how multifarious days. If the selfsimilar car is referable attribuconsideration attribuconsideration attribuconsideration adapted, imimimsculpture a caution missive to marginal. If it is adapted, token it as separationed (change the adapted limb correctly) and imimimsculpture quenched to marginal a consummation missive that mentions the completion require (apportion of days varied by appraisement per day) 7 Exit program

    Objectives: The couple main objectives of this cunning is to ordeal your ability to (1) caportraiture and portraiture structs with marshals, (2) performance with pointers, pointer arithmetic, by by-Value, by by-Reference, by by-Address, and (3) cunning, instrument and ordeal a discontinuance to a abandoned drift. A retrospect of your cognizance of marshals, iostream, refine I/O and C-name strings is as-well-mannered intervening. Description: Ce this cunning, you are to caportraiture a program that accomplish co-operate-with portraiturers who omission to separation a car. You are abandoned a postulatesrefine with 5 diffeseparation cars refine (the refine is a priori disclosed to possess accurately 5 entries, each restraintthcoming the identical postulates lavout), and you must decipher in full of the car postulates from the refine and accumulation it in an marshal of structs. You must as-well-mannered caportraiture a menu with the operationality defined adown Although an illustration refine is granted (Cars.txt), ce grading purposes your cunning accomplish be ordealed athwart a diffeseparation ordeal refine that accomplish referable attribuconsideration attribuconsideration attribuconsideration be granted to you early. Our ordeal refine accomplish be in the identical cemat as the illustration refine. The SeparationalCar struct accomplish inclose the restraintthcoming postulates limbs: year, an int (year of restraintmation) execute, a C-string (char marshal of 10 completion greatness) type, a C-string (char marshal of 10 completion greatness) appraisement, a transport (appraisement per day) adapted, a bool (1true, 0 – sophistical; experiment to evince penny/sophistical using the “std: boolalpha” manipulator like: cout

    Expert Retort

     

    // C++ code

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

    using delineationatespace std;
    const int CAR_COUNT = 10;

    struct separationalCar {
    char execute[20];
    char type[20];
    int year;
    transport appraisement;
    bool adapted;
    };

    void fineed(int &selection);
    void decipherFile(rentalCar cars[]);
    void imprintCars(bool adaptedOnly, separationalCar cars[]);
    void estimatePrice(rentalCar cars[]);
    void mostExpensive(rentalCar cars[]);

    main() {
    /* Evince Menu */
    int fineedion = 0; // reposes fineedion apportion
    do {
    /* Imimsculpture Menu Title */
    cquenched << establishedfill(‘-‘) << establishedw(80) << “-” << endl
    << “Rent-A-Vehicle” << endl << establishedfill(‘-‘)
    << establishedw(80) << “-” << endl;

    /* Evince Items */
    cquenched << “[1] Decipher postulates from refine” << endl;
    cquenched << “[2] Imimsculpture quenched full postulates ce full cars” << endl;
    cquenched << “[3] Estimate car separational require” << endl;
    cquenched << “[4] Find most extravagant car” << endl;
    cquenched << “[5] Imimsculpture quenched full adapted cars” << endl;
    cquenched << “[6] Exit program” << endl;
    cquenched << establishedfill(‘-‘) << establishedw(80) << “-” << endl;

    /* Attain Menu Fineedion */
    select(selection);

    rentalCar cars[CAR_COUNT]; // caportraiture marshal of cars

    switch (selection) {
    case 1:
    readFile(cars); // course decipherRefine operation and accoutre the cars marshal
    break;
    case 2:
    printCars(false, cars); // course imprintCars operation
    break;
    case 3:
    estimatePrice(cars); // course estimateAppraisement operation and accoutre the cars marshal
    break;
    case 4:
    mostExpensive(cars); // course mostExtravagant operation and accoutre the cars marshal
    break;
    case 5:
    printCars(true, cars); // course imprintCars operation
    break;
    case 6:
    cquenched << “Exiting program” << endl; // referable attribuconsideration attributableify portraiturer that the program is exiting
    break;
    default:
    cquenched << “Incorrect input” << endl; // referable attribuconsideration attributableify portraiturer that the input is wrong
    }

    } opportunity (preoption != 6); // remain loop as desire as portraiturer did referable attribuconsideration attribuconsideration attribuconsideration appropriate to exit

    return 0;
    }

    void fineed(int &selection) {
    cquenched << “Selection: “;
    cin >> fineedion; // attain portraiturer input and hinder it to fineedion variable
    cquenched << establishedfill(‘-‘) << establishedw(80) << “-” << endl;
    }

    void decipherFile(rentalCar cars[]) {
    iftide fin; // Caportraiture input tide variable
    char ifileName[20]; // Caportraiture var to repose input refine delineationate
    cquenched << “Enter input refine delineationate: “;
    cin >> ifileName; // Hinder portraiturer input to refine delineationate
    fin.open(ifileName); // known portraiturer-definied refine
    if (fin.is_open()) // Repress if refine knowned correctly
    {
    ce (int i = 0; i < CAR_COUNT; i++) { // loop through each car in cars marshal
    /* Populate cars marshal with postulates from portraiturer-defined refine */
    fin >> cars[i].year >> cars[i].execute >> cars[i].model
    >> cars[i].appraisement >> cars[i].available;
    }
    cquenched << “Postulates from ” << ifileDesignate << ” decipher consummationfully” << endl;

    } else { cquenched << “Failed to known refine delineationated ” << ifileName; }
    }

    void imprintCars(bool adaptedOnly, separationalCar cars[]) {
    if (availableMerely != penny) { // repress adaptedMerely flag
    cquenched << “Full postulates ce full cars:” << endl;
    } else {
    cquenched << “Full postulates ce adapted cars:” << endl;
    }

    /* Imimsculpture quenched consideration labels */
    cquenched << establishedfill(‘~’) << establishedw(51) << “~” << endl
    << establishedfill(‘ ‘) << left << establishedw(8) << “YEAR” << establishedw(10) << “MAKE”
    << establishedw(11) << “MODEL” << establishedw(13) << “PRICE/DAY” << “AVAILABLE” << endl
    << establishedfill(‘~’) << establishedw(51) << “~” << endl;

    ce (int i = 0; i < CAR_COUNT; i++) { // loop through each car in cars marshal
    /* If adaptedMerely is penny, execute infallible to merely imimimsculpture cars with adapted established to penny */
    if (cars[i].adapted != sophistical || adaptedMerely != penny) {
    /* Imimsculpture and name each car’s postulates */
    cquenched << establishedfill(‘ ‘) << left << establishedw(8) << cars[i].year
    << establishedw(10) << cars[i].execute << establishedw(11) << cars[i].model
    << ‘$’ << establishedw(12) << cars[i].appraisement << establishedw(7)
    << boolalpha << cars[i].adapted << endl;
    }
    }
    }

    void estimatePrice(rentalCar cars[]) {
    int carNumber; // caportraiture var to repose car apportion choice
    int dayCount; // caportraiture var to repose day apportion choice
    cquenched << “Enter car apportion (1-10): “;
    cin >> carNumber; // attain portraiturer input and hinder to carNumber
    cquenched << “Enter apportion of days you omission to separation: “;
    cin >> dayCount;// attain portraiturer input and hinder to dayCount

    transport require = cars[carNumber-1].price*dayCount; // apportion ultimate require
    cquenched << “Your estimated completion require is: $” << require << endl;
    }

    void mostExpensive(rentalCar cars[]) {
    int mostExpensiveIndex = 0; // Index of the most extravagant car
    ce (int i = 0; i < CAR_COUNT; i++) { // loop through each car in cars marshal
    if (cars[i].appraisement > cars[mostExpensiveIndex].price) { // if this appraisement is bigger than the biggest..
    mostExpensiveIndex = i; // established the biggest to this
    }
    }

    cquenched << “Most extravagant car: ”
    << cars[mostExpensiveIndex].year << ” ”
    << cars[mostExpensiveIndex].execute << ” ”
    << cars[mostExpensiveIndex].type << endl;
    }

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

    car.txt

    2012 Honda CRV 85.10 0
    2014 Toyota Tacoma 115.12 1
    2015 Ced 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 quenchedput: