Question
QUESTION: How to make a tostring() in c++. I have all of the other methods done. The descriptor method is responsible for returning a formatted
QUESTION: How to make a tostring() in c++. I have all of the other methods done.
The descriptor method is responsible for returning a formatted string representation of the object.
string toString() const;
The returned string should contain multiple objects:
[ {Owner:first last, Vehicle:year manufacturer model}, ... {Owner:first last, Vehicle:year manufacturer model} ]
The returned string is not
Example:
After the following code executes:
VehicleOwners vo{ VehicleOwner{"John", "Doe", 2019, "Toyota", "Prius"} }; vo.append(VehicleOwner{"May", "Smith", 1998, "Honda", "Pilot"}); vo.append(VehicleOwner{"Jane", "Doe", 2028, "Dodge", "Viper"}); cout << vo.toString();
the output will be:
[ {owner:John Doe, vehicle:2019 Toyota Prius}, {owner:May Smith, vehicle:1998 Honda Pilot}, {owner:Jane Doe, vehicle:2028 Dodge Viper} ]
GIVEN CODE:
#ifndef VEHICLE_OWNERS_H #define VEHICLE_OWNERS_H
#include
/* struct: VehicleOwner * Stores single vehicle owner information. */ struct VehicleOwner { string first; string last; int year; string manufacturer; string model; };
/* class: VehicleOwners * Stores multiple vehicle owner information. */ class VehicleOwners { public: /* class level constant for array size. */ static const int MAX_SIZE = 100;
VehicleOwner vehicleOwners[MAX_SIZE]; int length = 0;
/* Construtors */ VehicleOwners() { /* Type your code here. */ } VehicleOwners(const VehicleOwner& vehicleOwner) { /* Type your code here. */ }
/* getters */ VehicleOwner getVehicleOwner(const int index) const { /* Type your code here. */ }
/* setters */ void setVehicleOwner(const int index, const VehicleOwner& vehicleOwner) { /* Type your code here. */ }
/* methods */ void append(const VehicleOwner& vehicleOwner) { /* Type your code here. */ }
/* descriptor */ string toString() const { /* Type your code here. */ } }; #endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started