Urgently need someone to help me with adding a procedure to print all of the cars driven by a given driver name. This procedure must accept a name parameter, being the name of the driver. For example, the procedure could be called to print all of the cars driven by "Charlotte". Also, change main to read in the name to check from the user, and then call the newly created procedure.
#include "splashkit.h" #include //Include vector library using namespace std; /** * Represents a Person within the program. * * @field name The name of the person * @field age The person's age */ struct person { string name; int age; }; struct car //Declare car { string description; person driver; //Declaring a variable within the struct, //of type person, which is a struct itself vector passengers; //Dynamic array where each value is a person //that array is called passengers, // a dynamic array of person values }; /** * Read in a line of text from the user. * * @param prompt The message shown to prompt the user to input some text. * @returns The line of text entered at the prompt. */ string read_string ( string prompt ) { string result; write(prompt); result = read_line(); return result; } /** * Read in a whole number (int) from the user. This will validate the user * input and ensure that the value entered is a valid integer. * * @param prompt The message shown to prompt the user to input a number. * @returns The integer value entered by the user. */ int read_integer ( string prompt ) { string line; int result; line = read_string(prompt); result = convert_to_integer(line); return result; } /** * Read in the data for a person. This will read in data for each field of * the person, store it within a local variable, and then return this to * the caller. */ person read_person() { person result; result.name = read_string("Enter the person's name: "); result.age = read_integer("Enter the person's age: "); return result; } /** * Print out the details of from person. This outputs relevant data about * a Person to the terminal. * * @param to_print The person data to be printed. */ void print_person(const person &to_print) { write_line(to_print.name + " " + to_string(to_print.age)); } car read_car() //Function to read in car value { int count; //Declare count variable car result; //Create a variable (result) result.description = read_string("Enter the car's description: "); write_line("Provide the driver's details"); result.driver = read_person(); //Use read_person to read in all the data //about a person, and store that driver count = read_integer("How many passengers: "); //Read in how many passengers to add for(int i = 0; i < count; i++) { person passenger; //Declare person variable passenger = read_person(); //Read passenger data and store in variable result.passengers.push_back(passenger); //Result is the car, inside the car we have //the passengers (vector). Use the push_back //method to add them to next slot in the list. } return result; //Car with all that data in it. // A vector which contains a dynamic array of passengers } void print_car(const car &to_print) //Use the struct value as a parameter { write_line("---------"); write_line(to_print.description); //Details of the car write_line("---------"); write_line("Driver: "); print_person(to_print.driver); //Print out driver details write_line("---------"); write_line("Passengers: "); for(person p : to_print.passengers) //For each person, p, in, the passengers of the car { print_person(p); } write_line("----------"); } void populate_cars(vector &cars) { int count; count = read_integer("How many cars do you want to add: "); for (int i = 0; i < count; i++) { car temp; temp = read_car(); cars.push_back(temp); } //Reads car and pushes back onto vector } void print_all_cars(const vector &cars) { for(car c : cars) //for each car, c, in the vector of cars { print_car(c); //print that car and write_line(); //write a new line } } int main() { vector cars; //Array to add and remove elements to populate_cars(cars); //Procedure that passes in cars by reference print_all_cars(cars); return 0; }