Question: Analyze the working of given code and complete the code for sortByMake() function and paste it in the provided space. (20 Marks) #include using namespace

  1. Analyze the working of given code and complete the code for sortByMake()function and paste it in the provided space. (20 Marks)
  2. #include

    using namespace std;

    struct Date {

    int day;

    int year;

    string month;

    };

    struct Vehicle {

    string make;

    string model;

    int engCapacity;

    string color;

    Date DOR;

    };

    void showData(Vehicle ve[5]);//shows contents of data input by user

    Vehicle inputData (); //gets input from user

    void sortByMake(Vehicle ve[5]); // sort arrays of structure by Car Make

    int main()

    {

    Vehicle v[5];

    //Getting Input from user

    for (int i=0;i<5;i++)

    {

    v[i] = inputData(); //Input unsorted e.g car make suzuki, then honda, the tesla etc

    }

    //Displaying the contents of Input Array

    cout<<" Car Particulars are : ";

    showData(v);

    //Diplaying the Contents of array of structure after sorting

    cout<<" Car Particulars after sorting are : ";

    sortByMake(v); // you have to write the code for sorting by car make in this function

    }

    void showData (Vehicle ve[5])

    {

    for(int i=0;i<5;i++)

    {

    cout<<"Make : "<

    cout<<" Date of Regtration "<

    }

    }

    Vehicle inputData () {

    Vehicle car;

    cout<<"Enter Data For Car : ";

    cout<<"Make : ";

    cin>>car.make;

    cout<<"Model : ";

    cin>>car.model;

    cout<<"Engine Capacity : ";

    cin>>car.engCapacity;

    cout<<"Color : ";

    cin>>car.color;

    cout<<"Day of Reg : ";

    cin>>car.DOR.day;

    cout<<"Year of Reg : ";

    cin>>car.DOR.year;

    cout<<"Month of Reg : ";

    cin>>car.DOR.month;

    return car;

    }

    void sortByMake(Vehicle ve[5])

    {

    //Write the code for sorting structure of array, input by user by Car Make in Ascending Order

    showData(ve);

    }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!