Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 terminated. Each record is indented by two spaces from the left margin.

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 #include using namespace std;

/* 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Income Summary account?

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago