//main.cpp #include #include #include #include #include #include using namespace std; #include "Dog.h" void popDogs(list&); /** Change NOTHING above this line **/ //TODO, overload << operator //here's a start ostream& operator<<(ostream& os, Dog& d) { //Insert code here so that when a Dog is output, it is done as: //dogName weighs weight pounds. //Like: //Spot weighs 28 pounds. //Don't forget the period at the end. Do NOT include an endl at the end of the line. os<< d.dogName<< " weighs " << d.weight << " pounds."; return os; } int main() { //TODO, instantiate list of Dog variable called kennel. list kennel; //TODO, call the popDogs function passing the kennel variable declared above popDogs(kennel); //This code will sort the list of Dog using the less-than operator kennel.sort(); kennel.reverse(); //Do not change this line cout << "Dogs:" << kennel.size() << endl; //TODO, declare an iterator named itDogs to kennel from above list::iterator itDogs; //for (pitDogs= akennelbegin(); pitDogs< akennelend(); pitDogs+) for (itDogs = kennel.begin(); itDogs != kennel.end(); ++itDogs) //TODO, properly iterate itDogs using a for loop { //The following code MUST be the only code in the loop cout << *itDogs << endl; } /*** Touch NOTHING below this line ***/ return 0; } /** Do NOT change this function **/ void popDogs(list& ld) { ld.push_back(*(new Dog ("Shep", 32))); ld.push_back(*(new Dog ("Spot", 28))); ld.push_back(*(new Dog ("Killer", 9))); ld.push_back(*(new Dog ("Tiny", 82))); ld.push_back(*(new Dog ("Taco", 32))); ld.push_back(*(new Dog ("Zena", 29))); ld.push_back(*(new Dog ("Dakota", 32))); ld.push_back(*(new Dog ("Ally", 15))); ld.push_back(*(new Dog ("Kelly", 10))); ld.push_back(*(new Dog ("Benny", 28))); ld.push_back(*(new Dog ("Rex", 32))); ld.push_back(*(new Dog ("Shon", 55))); } //Dog.cpp #include "Dog.h" //no other includes are needed //TODO, implement the 1 constructor and 2 operator overloads. Nothings else needs to be done here. Dog::Dog(string n, int w) // parameterized constructor { dogName = n; weight = w; } bool Dog::operator< (Dog& d) { if(weight < d.weight) return true; else return false; } bool Dog::operator==(Dog& d) { return (dogName==d.dogName && weight==d.weight); } //Dog.h /** NO CHANGES NEEDED HERE **/ #include using namespace std; class Dog { public: string dogName; int weight; Dog(string, int ); bool operator<(Dog&); bool operator==(Dog&); }; Output required: Dogs:12 Tiny weighs 82 pounds. Shon weighs 55 pounds. Dakota weighs 32 pounds. Rex weighs 32 pounds. Shep weighs 32 pounds. Taco weighs 32 pounds. Zena weighs 29 pounds. Benny weighs 28 pounds. Spot weighs 28 pounds. Ally weighs 15 pounds. Kelly weighs 10 pounds. Killer weighs 9 pounds.
//main.cpp
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<list>
using namespace std;
#include "Dog.h"
void popDogs(list<Dog>&);
/** Change NOTHING above this line **/
//TODO, overload << operator
//here's a start
ostream& operator<<(ostream& os, Dog& d)
{
//Insert code here so that when a Dog is output, it is done as:
//dogName weighs weight pounds.
//Like:
//Spot weighs 28 pounds.
//Don't forget the period at the end. Do NOT include an endl at the end of the line.
os<< d.dogName<< " weighs " << d.weight << " pounds.";
return os;
}
int main()
{
//TODO, instantiate list of Dog variable called kennel.
list<Dog> kennel;
//TODO, call the popDogs function passing the kennel variable declared above
popDogs(kennel);
//This code will sort the list of Dog using the less-than operator
kennel.sort();
kennel.reverse();
//Do not change this line
cout << "Dogs:" << kennel.size() << endl;
//TODO, declare an iterator named itDogs to kennel from above
list<Dog>::iterator itDogs;
//for (pitDogs= akennelbegin(); pitDogs< akennelend(); pitDogs+)
for (itDogs = kennel.begin(); itDogs != kennel.end(); ++itDogs)
//TODO, properly iterate itDogs using a for loop
{
//The following code MUST be the only code in the loop
cout << *itDogs << endl;
}
/*** Touch NOTHING below this line ***/
return 0;
}
/** Do NOT change this function **/
void popDogs(list<Dog>& ld)
{
ld.push_back(*(new Dog ("Shep", 32)));
ld.push_back(*(new Dog ("Spot", 28)));
ld.push_back(*(new Dog ("Killer", 9)));
ld.push_back(*(new Dog ("Tiny", 82)));
ld.push_back(*(new Dog ("Taco", 32)));
ld.push_back(*(new Dog ("Zena", 29)));
ld.push_back(*(new Dog ("Dakota", 32)));
ld.push_back(*(new Dog ("Ally", 15)));
ld.push_back(*(new Dog ("Kelly", 10)));
ld.push_back(*(new Dog ("Benny", 28)));
ld.push_back(*(new Dog ("Rex", 32)));
ld.push_back(*(new Dog ("Shon", 55)));
}
//Dog.cpp
#include "Dog.h" //no other includes are needed
//TODO, implement the 1 constructor and 2 operator overloads. Nothings else needs to be done here.
Dog::Dog(string n, int w) // parameterized constructor
{
dogName = n;
weight = w;
}
bool Dog::operator< (Dog& d)
{
if(weight < d.weight)
return true;
else
return false;
}
bool Dog::operator==(Dog& d)
{
return (dogName==d.dogName && weight==d.weight);
}
//Dog.h
/** NO CHANGES NEEDED HERE **/
#include<string>
using namespace std;
class Dog
{
public:
string dogName;
int weight;
Dog(string, int );
bool operator<(Dog&);
bool operator==(Dog&);
};
Output required:
Dogs:12
Tiny weighs 82 pounds.
Shon weighs 55 pounds.
Dakota weighs 32 pounds.
Rex weighs 32 pounds.
Shep weighs 32 pounds.
Taco weighs 32 pounds.
Zena weighs 29 pounds.
Benny weighs 28 pounds.
Spot weighs 28 pounds.
Ally weighs 15 pounds.
Kelly weighs 10 pounds.
Killer weighs 9 pounds.
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 5 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)