Question

In: Computer Science

Maryland Animal Sanctuary and Rescue is a small Pet adoption place right here in our area...

  1. Maryland Animal Sanctuary and Rescue is a small Pet adoption place right here in our area and has different animals up for adoption. Design an application for their pets, creating a class diagram and writing the pseudocode for both the class definition and the application. Be sure to follow the Style Criteria for naming conventions, class diagrams, pseudocode, keywords, and operators.
    1. Create the UML class diagram for the Pet class that contains the type of the pet, the breed of the pet, and the weight. Examples of valid values for the type of the pet are "dog" and "rabbit". Examples of valid values for the breed are "husky" and "checkered giant". Examples of valid values for the weight are 32 and 3 1/2. Be sure to choose the most appropriate data type for the attributes. Include the methods of the Pet class listed below as well as the application class. Add the correct relationship and multiplicity.
    2. Create a class definition
      • Create a Pet class that contains the attributes in the class diagram. Additionally, include the following:
        • A default constructor that initializes each attribute to some reasonable default value for the pets.
        • Another constructor method that has a parameter for each data member. This constructor initializes each attribute to the value provided when an object of this type is instantiated.
        • Accessor and mutator methods for each attribute.
        • A method that displays all the data about the pets.
    3. Create the main application
      • Write the pseudocode for the application program for the pet sanctuary with a main() module that instantiates two objects of the Pet class.
        • The first object should be named dog and use the default constructor.
        • The second object should be named cat and use the second constructor to initialize the type to "cat", the breed to "Siamese", and the weight to 3.  
      • Include the following instructions in the main() method, in the order specified below
        • A call to set the type of the dog to "Large Dog".
        • A call to set the breed of the dog to “German Shephard”.
        • A call to set the weight of the dog to 50.
        • A Statement that displays the breed of the cat, using the appropriate method call.
        • A call to change the weight of the dog to 45.
        • A statement that displays the weight of the dog, using the appropriate method call.
        • A call for the cat object to the method that displays all the information about the cat.
        • A call for the dog object to the method that displays all of the information about the dog.

Solutions

Expert Solution

Short Summary:

  • Provided the source code and sample output as per the requirements.

**************Please upvote the answer and appreciate our time.************

UML DIAGRAM:

Source Code:

Pet.h:

// Create a Pet class that contains the attributes in the class diagram.
#ifndef PET_H
#define PET_H
#include <iostream>
using namespace std;
class Pet{
public:
// default constructor
Pet();
// parameterized constructor
Pet(string,string,float);
// mutators
void setType(string);
void setBreed(string);
void setWeight(float);
// Accessors
string getType();
string getBreed();
float getWeight();
// displays all the data about the pets
void displayPetData();
private:
string petType;
string petBreed;
float weight;
};
#endif

Pet.cpp:

#include "Pet.h"
#include <iostream>

using namespace std;
// default constructor
Pet :: Pet(){
petType = "";
petBreed = "";
weight = 0;
}
// parameterized constructor
Pet :: Pet(string type,string breed,float wt){
petType = type;
petBreed = breed;
weight = wt;
}
// mutators
void Pet :: setType(string type){
petType = type;
}
void Pet :: setBreed(string breed){
petBreed = breed;
}
void Pet :: setWeight(float wt){
weight = wt;
}
// Accessors
string Pet :: getType(){
return petType;
}
string Pet :: getBreed(){
return petBreed;
}
float Pet :: getWeight(){
return weight;
}
// displays all the data about the pets
void Pet :: displayPetData(){
cout << "Type : " << getType() << "\nBreed : " << getBreed() << "\nWeight : " << getWeight() << endl;
}

main.cpp:

#include "Pet.h"
#include <iostream>

using namespace std;

int main()
{
// first object should be named dog and use the default constructor.
Pet dog = Pet();
// second object should be named cat and use the parameterized constructor
Pet cat = Pet("cat","Siamese",3);
// A call to set the type of the dog to "Large Dog".
dog.setType("Large Dog");
// A call to set the breed of the dog to "German Shephard".
dog.setBreed("German Shephard");
// A call to set the weight of the dog to 50.
dog.setWeight(50);
// A Statement that displays the breed of the cat, using the appropriate method call.
cout << "Cat Breed : " << cat.getBreed() << endl;
// A call to change the weight of the dog to 45.
dog.setWeight(45);
// A statement that displays the weight of the dog, using the appropriate method call.
cout << "Dog Weight : " << dog.getWeight() << endl;
// A call for the cat object to the method that displays all the information about the cat.
cout << "**** CAT DATA ****" << endl;
cat.displayPetData();
// A call for the dog object to the method that displays all of the information about the dog.
cout << "**** DOG DATA ****" << endl;
dog.displayPetData();

return 0;
}

Sample Run:

**************************************************************************************

Feel free to rate the answer and comment your questions, if you have any.

Please upvote the answer and appreciate our time.

Happy Studying!!!

**************************************************************************************


Related Solutions

When considering The Right to Food Timeline, place the following in correct order: Answers Adoption of...
When considering The Right to Food Timeline, place the following in correct order: Answers Adoption of the 2030 Agenda for Sustainable Development Appropriation of the Principles for Responsible Investment in Agriculture and Food Systems UN Convention on the Rights of Persons with Disabilities Initiation of the Millenium Development Goals CESCR General Comment 12: The Right to Adequate Food World Food Summit World War II Adoption of the Universal Declaration of Human Rights UN Convention on the Elimination of All Forms...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT