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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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

 

Expert Solution
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education