#include <iostream> #include <string> struct Car { float length; float clearance; float…
- User
#include #include
struct Car { float length; float clearance; float engineVolume; int enginePower; int wheelDiameter; std::string color; std::string transmissionType; };
void setValues(Car& car, float length, float clearance, float engineVolume, int enginePower, int wheelDiameter, const std::string& color, const std::string& transmissionType) { car.length = length; car.clearance = clearance; car.engineVolume = engineVolume; car.enginePower = enginePower; car.wheelDiameter = wheelDiameter; car.color = color; car.transmissionType = transmissionType; }
void displayValues(const Car& car) { std::cout << "Length: " << car.length << std::endl; std::cout << "Clearance: " << car.clearance << std::endl; std::cout << "Engine Volume: " << car.engineVolume << std::endl; std::cout << "Engine Power: " << car.enginePower << std::endl; std::cout << "Wheel Diameter: " << car.wheelDiameter << std::endl; std::cout << "Color: " << car.color << std::endl; std::cout << "Transmission Type: " << car.transmissionType << std::endl; }
bool findValue(const Car& car, const std::string& value) { return car.color == value || car.transmissionType == value; }
int main() { Car myCar; setValues(myCar, 4.5, 0.2, 2.5, 350, 18, “red”, “automatic”);
displayValues(myCar); std::string searchValue = “red”; if (findValue(myCar, searchValue)) { std::cout << “Car has the value “” << searchValue << “”” << std::endl; } else { std::cout << “Car does not have the value “” << searchValue << “”” << std::endl; } return 0;}
- Assistant
The code defines a struct
Carthat represents a car with several attributes such as length, clearance, engine volume, engine power, wheel diameter, color, and transmission type.The
setValuesfunction takes aCarobject and assigns the given values to its attributes.The
displayValuesfunction prints out the values of a givenCarobject.The
findValuefunction checks if a given value matches either the color or transmission type of a givenCarobject.In the
mainfunction:- A
CarobjectmyCaris created. - The
setValuesfunction is called to assign specific values tomyCar. - The
displayValuesfunction is called to print out the values ofmyCar. - A search value is assigned to
searchValue. - The
findValuefunction is called to check ifmyCarcontains the search value. If it does, a message indicating that the car has the value is printed. Otherwise, a message indicating that the car does not have the value is printed.
- A