CSC160 (UG20) 01
    TPS 11: Structs II
    Skip To Content
    Dashboard
    • Login
    • Dashboard
    • Calendar
    • Inbox
    • Help
    Close
    • My Dashboard
    • CSC160 (UG20) 01
    • Assignments
    • TPS 11: Structs II
    SP 2021 (UNDG)
    • Home
    • Assignments
    • Modules
    • TC/WC Appt Scheduler
    • Collaborations
    • WSJ Context
    • EvaluationKIT Course
    • EvaluationKIT
    • Barnes & Noble Bookstore

    TPS 11: Structs II

    • Due Apr 14, 2021 by 10am
    • Points 1
    • Submitting a file upload
    • File Types doc and docx
    • Available after Apr 14, 2021 at 9am

    Consider the following program and complete the three TODOs.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    //==============================================================================
    // File:    tps11.cpp
    // Author:  Hank Feild
    // Date:    14-Apr-2021
    // Purpose: Demonstrates using vectors of structs.
    //==============================================================================
    #include <iostream>
    #include <vector>
    using namespace std;
    
    struct Car {
        string make, model;
        int year, miles;
        bool has4WheelDrive;
    };
    
    /**
     * Reads in a car's information from the user.
     * 
     * @return A Car populated with user input.
     */
    Car ReadCarFromUser(){
        Car car;
        string fourWheelDriveResponse;
    
        cout << "Please enter the following data about the car:" << endl;
    
        cout << "Make (Ford/Toyota/etc.): ";
        getline(cin, car.make);
    
        cout << "Model (F-150, Corolla, etc.): ";
        getline(cin, car.model);
    
        cout << "Year: ";
        cin >> car.year;
    
        cout << "Miles: ";
        cin >> car.miles;
    
        cout << "Does it have 4WD? [yes/no]: ";
        getline(cin, fourWheelDriveResponse);
        car.has4WheelDrive = fourWheelDriveResponse == "yes";
    
        return car;
    }
    
    /**
     * Prints out a Car in a nice format:
     * 
     *   <year> <make> <model> with <miles> miles with<out?> 4-wheel drive
     * 
     * @param car The Car to display.
     */
    void PrintCar(Car car){
        cout << car.year << " " << car.make << " " << car.model
             << " with " << car.miles << " miles with";
        if(!car.has4WheelDrive){
            cout << "out";
        }
        cout << " 4-wheel drive" << endl;
    }
    
    /**
     * Asks the user for three cars, then prints them out.
     * 
     * @return The exit status of the program; 0 is good.
     */
    int main(){
        // TODO 1: Declare a vector named `cars` that hold Car instances.
    
        // Read three cars in from the user.
        cars.push_back(ReadCarFromUser());
        cars.push_back(ReadCarFromUser());
        cars.push_back(ReadCarFromUser());
    
        // TODO 2: add 10 miles to each car's mileage.
    
        // Print the cars.
        for(int i = 0; i < cars.size(); i++){
            // TODO 3: Print the current car using the PrintCar function.
        }
    
        return 0;
    }
    

    After we've completed the group share portion, upload a copy of your updated TPS document.

    1618408800 04/14/2021 10:00am
    Additional Comments:
    Rating max score to > pts

    Rubric

     
     
     
     
     
     
     
         
    Can't change a rubric once you've started using it.  
    Find a Rubric
    Find Rubric
    Title
    You've already rated students with this rubric. Any major changes could affect their assessment results.
    Title
    Criteria Ratings Pts
    Edit criterion description Delete criterion row
    This criterion is linked to a Learning Outcome Description of criterion
    threshold: 5 pts
    Edit rating Delete rating
    5 to >0 pts
    Full Marks
    blank
    Edit rating Delete rating
    0 to >0 pts
    No Marks
    blank_2
    This area will be used by the assessor to leave comments related to this criterion.
    pts
      / 5 pts
    --
    Additional Comments
    Total Points: 5 out of 5