Question
Hi, I need to know how to achieve the following in C++ : 1).Implement the class Car and class Collection. 2). Include required libraries as
Hi,
I need to know how to achieve the following in C++ :
1).Implement the class Car and class Collection. 2). Include required libraries as necessary; 3). Add namespaces as necessary; 4). Overload the comparison operator < which is used by the priority_queue to determine the top of the queue. 5). void Collection::display_best() should use the void Car::display to display the Car specific information.
Test run the program and make sure that you get the output as: Sample output: C:\csc2401>g++ -Wall PartB-1.cpp C:\csc2401>a Sports Car From 1900 to 2014 Model: AH211 Price: 23456.8
Using the following code :
class Car { public: Car(); Car(string m, double p); string get_model(); double get_price(); void display()const; private: string model; double price; };
class Collection { public: Collection(); Collection(string n, string d); void add_item(Car c); // Add Car c to priority_queue task. void display_best(); // Display information of the Best car. // Use price to determine best. // Higher price means better. private: priority_queue
int main(){ // Instantiate 3 car objects Car c1("MQ310", 12345.99); Car c2("AH211", 23456.78); Car c3("ZH42", 3456.49); // Instantiate a Collection object Collection c("Sports Car", "From 1900 to 2014"); // Add 3 car objects to the car collection c.add_item(c1); c.add_item(c2); c.add_item(c3); // Display the information of the best car. c.display_best(); return 0; }
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