# Pets ## Breed Class Create a `Breed` class with the following: ### Member Variables Create the following private member variables, all of type `std::string`:  1. `species_` 2. `breed_name_` 3. `color_` ### Constructors 1. Create a default constructor for `Breed` that sets its `species_` to `"Dog"`, `breed_name_` to `"Chihuahua"`, and `color_` to `"Fawn"`. 2. Create a non-default constructor that receives a `std::string` for `species_`, `breed_name_`, and `color_`; in that order. The values from the constructor should appropriately assign the member variables. ### Accessors and Mutators Create accessors and mutators for all member variables, following the naming conventions covered in class. e.g. for species_, name the accessor `Species`, and the mutator `SetSpecies`. ## Pet Class Create a `Pet` class with the following: ### Member Variables Create the following private member variables: 1. `std::string name_` 2. `Breed breed_`  3. `double weight_` ### Constructors 1. Create a default constructor for `Pet` that sets its name to `"Cookie"` and weight to `15.6`. The `Breed` object will automatically be created using its default constructor. 2. Create a non-default constructor that receives a `std::string` for `name_`, `Breed` for `breed_`, and a `double` for `weight_` in that order. The values from the constructor should appropriately assign the member variables. 3. Create another non-default constructor that receives a `std::string` for Pet's name stored in `name_`, `std::string` for the `Breed` species, `std::string` for the `Breed` name, and `std::string` for the `Breed` color, and `double` for `weight_`. The values accepted for the `Breed` species, `Breed` name, and `Breed` color should all be passed into the `Breed` constructor to create an object to assign to the `breed_` member variable (hint: you can initialize an object member variable within a member initializer list by invoking its constructor, see [this slide](https://docs.google.com/presentation/d/1zIAC4kj9FZ2GVZN2aMCJYm8qK_GFIKwfg55bW6b_s2M/edit#slide=id.g1636e2659d3_0_117)). The other values from the constructor should appropriately assign the member variables. ### Accessors and Mutators Create accessors and mutators for `name_`, `breed_`, and `weight_`. Please name the accessor for `breed_` as `GetBreed`, to avoid conflicting with the constructor for the `Breed` class. ### SetBreed overload Create a function overload for `SetBreed` that accepts a `species`, `breed_name`, and `color`, all of type `std::string`, that will internally create a `Breed` object using the values provided and then assign it to the `breed_` member variable. ### Print Create a member function called `Print` that returns `void` and does not take in any parameters. Using the member variables, this function should print out the name and weight of the `Pet`. It should also utilize accessors of the `Breed` class to get the species, breed name, and color.  ## Other instructions Complete the `main` function as described. Place the `Pet` class in `pet.h`, and the `Breed` class in `breed.h`. Member functions that take more than ten lines or use complex constructs should have their function prototype in the respective `.h` header file and implementation in the respective `.cc` implementation file. ## Sample Output: ``` Please enter the pet's name (q to quit): Bitzy Please enter the pet's type: Dog Please enter the pet's breed: Chihuahua Please enter the pet's color: Tan Please enter the pet's weight (lbs): 11.5 Please enter the pet's name (q to quit): Cookie Please enter the pet's type: Dog Please enter the pet's breed: Long Chihuahua Please enter the pet's color: Brown & White Please enter the pet's weight (lbs): 6.2 Please enter the pet's name (q to quit): q Printing Pets: Pet 1 Name: Bitzy Species: Dog Breed: Chihuahua Color: Tan Weight: 11.5 lbs Pet 2 Name: Cookie Species: Dog Breed: Long Chihuahua Color: Brown & White Weight: 6.2 lbs   I have solved the breed.h but got wrong on others  breed.h: #include #ifndef BREED_H #define BREED_Hclass Breed { public: Breed(): species_ ("Dog"), breed_name_ ("Chihuahua"), color_ ("Fawn") {} Breed(std::string species, std::string breed_name, std::string color) {     species_ = species;     breed_name_ = breed_name;     color_ = color;   } std::string Species() const {     return species_;   } std::string BreedName() const {     return breed_name_;   } std::string Color() const {     return color_;   } void SetSpecies(std::string species) {     species_ = species;     }  void SetBreedName(std::string breed_name) {     breed_name_ = breed_name;    } void SetColor(std::string color) {     color_ = color;    } private: // Declaring variables std::string species_; std::string breed_name_; std::string color_; }; #endif pet.h: #include #ifndef PET_H #define PET_H #include "breed.h" using namespace std; class Pet { public: private: string name_; Breed breed_; double weight_; }; #endif

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

# Pets
## Breed Class
Create a `Breed` class with the following:

### Member Variables
Create the following private member variables, all of type `std::string`: 
1. `species_`
2. `breed_name_`
3. `color_`

### Constructors
1. Create a default constructor for `Breed` that sets its `species_` to `"Dog"`, `breed_name_` to `"Chihuahua"`, and `color_` to `"Fawn"`.
2. Create a non-default constructor that receives a `std::string` for `species_`, `breed_name_`, and `color_`; in that order. The values from the constructor should appropriately assign the member variables.

### Accessors and Mutators
Create accessors and mutators for all member variables, following the naming conventions covered in class. e.g. for species_, name the accessor `Species`, and the mutator `SetSpecies`.

## Pet Class
Create a `Pet` class with the following:

### Member Variables
Create the following private member variables:
1. `std::string name_`
2. `Breed breed_` 
3. `double weight_`

### Constructors
1. Create a default constructor for `Pet` that sets its name to `"Cookie"` and weight to `15.6`. The `Breed` object will automatically be created using its default constructor.
2. Create a non-default constructor that receives a `std::string` for `name_`, `Breed` for `breed_`, and a `double` for `weight_` in that order. The values from the constructor should appropriately assign the member variables.
3. Create another non-default constructor that receives a `std::string` for Pet's name stored in `name_`, `std::string` for the `Breed` species, `std::string` for the `Breed` name, and `std::string` for the `Breed` color, and `double` for `weight_`. The values accepted for the `Breed` species, `Breed` name, and `Breed` color should all be passed into the `Breed` constructor to create an object to assign to the `breed_` member variable (hint: you can initialize an object member variable within a member initializer list by invoking its constructor, see [this slide](https://docs.google.com/presentation/d/1zIAC4kj9FZ2GVZN2aMCJYm8qK_GFIKwfg55bW6b_s2M/edit#slide=id.g1636e2659d3_0_117)). The other values from the constructor should appropriately assign the member variables.

### Accessors and Mutators
Create accessors and mutators for `name_`, `breed_`, and `weight_`. Please name the accessor for `breed_` as `GetBreed`, to avoid conflicting with the constructor for the `Breed` class.

### SetBreed overload
Create a function overload for `SetBreed` that accepts a `species`, `breed_name`, and `color`, all of type `std::string`, that will internally create a `Breed` object using the values provided and then assign it to the `breed_` member variable.

### Print
Create a member function called `Print` that returns `void` and does not take in any parameters. Using the member variables, this function should print out the name and weight of the `Pet`. It should also utilize accessors of the `Breed` class to get the species, breed name, and color. 

## Other instructions
Complete the `main` function as described. Place the `Pet` class in `pet.h`, and the `Breed` class in `breed.h`. Member functions that take more than ten lines or use complex constructs should have their function prototype in the respective `.h` header file and implementation in the respective `.cc` implementation file.

## Sample Output:
```
Please enter the pet's name (q to quit): Bitzy
Please enter the pet's type: Dog
Please enter the pet's breed: Chihuahua
Please enter the pet's color: Tan
Please enter the pet's weight (lbs): 11.5
Please enter the pet's name (q to quit): Cookie
Please enter the pet's type: Dog
Please enter the pet's breed: Long Chihuahua
Please enter the pet's color: Brown & White
Please enter the pet's weight (lbs): 6.2
Please enter the pet's name (q to quit): q
Printing Pets:
Pet 1
Name: Bitzy
Species: Dog
Breed: Chihuahua
Color: Tan
Weight: 11.5 lbs
Pet 2
Name: Cookie
Species: Dog
Breed: Long Chihuahua
Color: Brown & White
Weight: 6.2 lbs

 

I have solved the breed.h but got wrong on others 

breed.h:

#include <string>
#ifndef BREED_H
#define BREED_Hclass Breed
{
public:

Breed(): species_ ("Dog"), breed_name_ ("Chihuahua"), color_ ("Fawn") {}
Breed(std::string species, std::string breed_name, std::string color) {
    species_ = species;
    breed_name_ = breed_name;
    color_ = color;
  }
std::string Species() const {
    return species_;
  }
std::string BreedName() const {
    return breed_name_;
  }
std::string Color() const {
    return color_;
  }

void SetSpecies(std::string species) {
    species_ = species;  
  } 
void SetBreedName(std::string breed_name) {
    breed_name_ = breed_name; 
  }
void SetColor(std::string color) {
    color_ = color; 
  }
private:
// Declaring variables
std::string species_;
std::string breed_name_;
std::string color_;
};
#endif

pet.h:

#include <string>
#ifndef PET_H
#define PET_H
#include "breed.h"
using namespace std;
class Pet
{
public:


private:
string name_;
Breed breed_;
double weight_;

};
#endif



C main.cc x C pet.h x
1 #include "pet.h"
2 #include "breed.h"
C+ pet.cc x +
3 #include <iomanip>
4 #include <iostream>
5 using namespace std;
6
// ======
====== YOUR CODE HERE =====
7
// This implementation file (pet.cc) is where you should implement
8 // the member functions declared in the header (pet.h), only
9
// if you didn't implement them inline within pet.h.
10
//
11
// Remember to specify the name of the class with :: in this format:
12 // <return type> MyClassName::MyFunction() {
13 //
14 //
}
15
// to tell the compiler that each function belongs to the Pet class.
// ========
16
17 Pet: : Pet()
18 ▼ {
19
this->name="Doug";
20 this->weight=15.6;
21
22 }
23 Pet::Pet(string name, string species, string bred, string color, double weight)
24 ▼ {
25 this->name=name;
26
breed.SetName(breed);
27 breed.SetSpecies (species);
28 breed.SetColor(color);
29
30 this->weight=weight;
31 }
32
33 ▼ {
34 return breed;
Breed Pet::getBred()
35}
36 string Pet::getName()
37▼ {
38 return name;
39 }
40 double Pet::getWeight()
41 ▼ {
42 return weight;
43 }
44 void Pet::setBreed (Breed b)
45 ▼ {
46 this->breed=b;
47 }
48 void Pet::setName(string name)
49▼ {
50 this->name=name;
51 }
52 void Pet::setWeight (double weight)
53 ▼ {
54 this->weight=weight;
⠀
Transcribed Image Text:C main.cc x C pet.h x 1 #include "pet.h" 2 #include "breed.h" C+ pet.cc x + 3 #include <iomanip> 4 #include <iostream> 5 using namespace std; 6 // ====== ====== YOUR CODE HERE ===== 7 // This implementation file (pet.cc) is where you should implement 8 // the member functions declared in the header (pet.h), only 9 // if you didn't implement them inline within pet.h. 10 // 11 // Remember to specify the name of the class with :: in this format: 12 // <return type> MyClassName::MyFunction() { 13 // 14 // } 15 // to tell the compiler that each function belongs to the Pet class. // ======== 16 17 Pet: : Pet() 18 ▼ { 19 this->name="Doug"; 20 this->weight=15.6; 21 22 } 23 Pet::Pet(string name, string species, string bred, string color, double weight) 24 ▼ { 25 this->name=name; 26 breed.SetName(breed); 27 breed.SetSpecies (species); 28 breed.SetColor(color); 29 30 this->weight=weight; 31 } 32 33 ▼ { 34 return breed; Breed Pet::getBred() 35} 36 string Pet::getName() 37▼ { 38 return name; 39 } 40 double Pet::getWeight() 41 ▼ { 42 return weight; 43 } 44 void Pet::setBreed (Breed b) 45 ▼ { 46 this->breed=b; 47 } 48 void Pet::setName(string name) 49▼ { 50 this->name=name; 51 } 52 void Pet::setWeight (double weight) 53 ▼ { 54 this->weight=weight; ⠀
⠀
⠀
C pet.hx
1 #include <iostream>
2 #include "pet.h"
3 #include <vector>
4 using namespace std;
5
6
7
8
C+ main.ccx
int main() {
// Create an array of 100 pet objects called 'pet_arr`
9 Pet* pet_arr=new Pet [100];
10
int num_pet = 0;
11 std::string name;
std::string breed;
12
13
std::string species;
14 std::string color;
15 double weight;
16 ▼ do {
17
std::cout << "Please enter the pet's name (q to quit): ";
18 std::getline(std::cin, name);
19
if (name != "q") {
20
std::cout << "Please enter the pet's species: ";
21 std::getline(std::cin, species);
22 std::cout << "Please enter the pet's breed: ";
23 std::getline(std::cin, breed);
24 std::cout << "Please enter the pet's color: ";
25 std::getline(std::cin, color);
26 std::cout << "Please enter the pet's weight (lbs): ";
27 std::cin>> weight;
28 std::cin.ignore();
29 // Create a pet object using the input from the user
30 Pet p(name, species, breed, color, weight);
31 // Store the newly-created pet object into the array. Use `num_pet to
32 pet_arr[num_pet]=p;
33 num_pet++;
34 // control the index where the pet object is placed and update it
35 // accordingly
36 }
37 } while (name != "q");
38 std::cout << "Printing Pets:\n";
39 for (int i = 0; i < num_
i++) {
40 std::cout << "Pet " << i + 1 << "\n";
1 2 3 4 45
41 // Print information about the `i`th pet object
42 pet_arr[i].print();
C- pet.cc x +
43
}
44 return 0;
}
Transcribed Image Text:⠀ ⠀ C pet.hx 1 #include <iostream> 2 #include "pet.h" 3 #include <vector> 4 using namespace std; 5 6 7 8 C+ main.ccx int main() { // Create an array of 100 pet objects called 'pet_arr` 9 Pet* pet_arr=new Pet [100]; 10 int num_pet = 0; 11 std::string name; std::string breed; 12 13 std::string species; 14 std::string color; 15 double weight; 16 ▼ do { 17 std::cout << "Please enter the pet's name (q to quit): "; 18 std::getline(std::cin, name); 19 if (name != "q") { 20 std::cout << "Please enter the pet's species: "; 21 std::getline(std::cin, species); 22 std::cout << "Please enter the pet's breed: "; 23 std::getline(std::cin, breed); 24 std::cout << "Please enter the pet's color: "; 25 std::getline(std::cin, color); 26 std::cout << "Please enter the pet's weight (lbs): "; 27 std::cin>> weight; 28 std::cin.ignore(); 29 // Create a pet object using the input from the user 30 Pet p(name, species, breed, color, weight); 31 // Store the newly-created pet object into the array. Use `num_pet to 32 pet_arr[num_pet]=p; 33 num_pet++; 34 // control the index where the pet object is placed and update it 35 // accordingly 36 } 37 } while (name != "q"); 38 std::cout << "Printing Pets:\n"; 39 for (int i = 0; i < num_ i++) { 40 std::cout << "Pet " << i + 1 << "\n"; 1 2 3 4 45 41 // Print information about the `i`th pet object 42 pet_arr[i].print(); C- pet.cc x + 43 } 44 return 0; }
Expert Solution
steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY