Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you are to implement the methods of the class VehicleOwners . The class stores information about vehicles and their owners. VehicleOwner class

In this assignment you are to implement the methods of the class VehicleOwners. The class stores information about vehicles and their owners.

VehicleOwner class

This is the class that holds a single owner and vehicle information.

class VehicleOwner { public: string first = "na"; string last = "na"; int year = 1900; string manufacturer = "na"; string model = "na"; VehicleOwner() {} VehicleOwner(const string& first, const string& last, const int year, const string& manufacturer, const string& model) : first{first}, last{last}, year{year}, manufacturer{manufacturer}, model{model} {} string getName() const { return last + "," + first; } }; 

VehicleOwners class

This class holds an array of VehicleOwner objects and represents the collection used in this assignment.

class VehicleOwners { public: static const int MAX_SIZE = 100; VehicleOwner vehicleOwners[MAX_SIZE]; int length = 0; void append(const VehicleOwner& vehicleOwner); void appendFromFile(const string& filename); string toString() const; }; /* VehicleOwners stream operator */ ostream& operator (const VehicleOwner& lhs, const VehicleOwner& rhs); bool operator >=(const VehicleOwner& lhs, const VehicleOwner& rhs); 

Instructions

In VehicleOwners.cpp define the following methods:

append() method

The append() method inserts a new VehicleOwner instance to the end of the array. You may safely assume that there won't be more than MAX_SIZE instances appended.

void VehicleOwners::append(const VehicleOwner& vehicleOwner); 

vehicleOwner - the instance to add to the end of the array.

appendFromFile() method

This method attempts to read from the specified file a number of VehicleOwner records. The method first tries to open the filenameand if this attempt fails, gives an error message ("Error opening file.") and returns. On success it reads each record, builds a VehicleOwner object and appends it to the end of the array. Hint: Use the function stoi() to convert a string representation of an integer to its integer equivalent, e.g. stoi("15") returns 15.

void appendFromFile(const string& filename); 

filename - the filename to read from.

descriptor

The descriptor method is responsible for returning a formatted string representation of the object.

string toString() const; 

returns - a formatted string of objects or [] when the array is empty.

The returned string should contain multiple objects:

[ {Owner:first last, Vehicle:year manufacturer model}, ... {Owner:first last, Vehicle:year manufacturer model} ] 

stream operator

This operator outputs to its stream the VehicleOwners object by calling its toString() method.

ostream& operator  

os - the output stream to write the instance.

o - the instance to output to the stream.

relational operators

These operators each returns true or false based on the result of the conditional evaluation. Each condition is tested against the owner's name as returned by the method getName() of the VehicleOwner class.

bool operator ==(const VehicleOwner& lhs, const VehicleOwner& rhs); bool operator !=(const VehicleOwner& lhs, const VehicleOwner& rhs); bool operator (const VehicleOwner& lhs, const VehicleOwner& rhs); bool operator >=(const VehicleOwner& lhs, const VehicleOwner& rhs); 

Example:

After the following code executes:

VehicleOwners vo{}; cout  

the output will be:

[] [ {owner:John Doe, vehicle:2000,Chrysler,300}, {owner:Mary,Doe, vehicle:2020,Honda,Accord}, {owner:Mary,Smith, vehicle:2019,Toyota,Corolla} {owner:Peter,Pan, vehicle:2019,Ford,Fiesta} ]

for this question I am getting these two failed functions can anyone help please help quickly I shall be very thankful

image text in transcribedimage text in transcribed

test: random it operator

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

Step: 3

blur-text-image

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

Consider some type of redress for the customer, such as a coupon.

Answered: 1 week ago

Question

Demonstrate through language that you are grateful to be informed.

Answered: 1 week ago

Question

Always mention the specifi c problem the customer faced.

Answered: 1 week ago