Question: I cannot get my code below to compile.. The idea is to Turn the class Collection into a template class so that it can be
I cannot get my code below to compile..
The idea is to Turn the class Collection into a template class so that it can be used for Car as well as Book, Person and other classes. You have to convert the overloaded operator < to a template function. Test run the program and make sure that you still get the output as: Sample output: C:\csc2401>g++ -Wall PartB-2.cpp C:\csc2401>a Sports Car From 1900 to 2014 Model: AH211 Price: 23456.8
My Code :
#include
using namespace std;
class Car { public: Car(); Car(string model, double price); string get_model(); double get_price(); void display()const; private: string model; double price; };
template
Car::Car(string m, double p) { model = m; price = p; }
string Car::get_model() { return model; }
double Car::get_price() { return price; }
void Car::display() const { cout << "Model: " << model << " Price: " << price << " "; }
template
{ }
template
template
template
template
//template class Collection;
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"); // Collection c(""); // 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
Get step-by-step solutions from verified subject matter experts
