Question

1) Using the O-O Paradigm create a class in C++ for the object Dog 2) Implement...

1) Using the O-O Paradigm create a class in C++ for the object Dog

2) Implement ALL the behaviors  (member functions/methods- including any needed constructors, and helper methods ) of the class.

3) Write the necessary Client/Application/User program

The Client program should do the following:

a) create at least 4 objects.

b) show all the behaviors

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • Complete program provided below is well commented for better understanding.
  • Program follows all the instructions given in question.
  • Program snippet is provided below the typed code to understand indentation of code.
  • Output snippet for program is also attached below.

Program:

#include<iostream>
#include<string>
using namespace std;
/* Defining class Dog*/
class Dog
{
/* defining Dog class member variables */
private:
// NOTE: Other characters of dog can be added similarly if needed
string name;
int age;
char gender;
int size;
public:
// Dog class constructor
Dog(string n, int a, char g, int s)
{
name = n;
age = a;
gender = g;
size = s;
}

/* Defining Dog class methods to access members of class*/
string getName()
{
return name;
}
int getAge()
{
return age;
}
char getGender()
{
return gender;
}
int getSize()
{
return size;
}

// defining barking behavior of Dog
// NOTE: Here any other behavior or other member functions can be defined according to need
void bark()
{
cout<<"Bow-wow"<<endl;
}
};

// Defining main function/ driver function
int main()
{
// Creating 4 objects of Dog with their properties
Dog dog1("Puppy", 8, 'M', 6);
Dog dog2("Lucy", 7, 'F', 5);
Dog dog3("Tom", 8, 'M', 7);
Dog dog4("Daisy", 6, 'F', 6);

/* Printing description of Dog1 */
cout<<"Dog 1 description:"<<endl;
cout<<"Name: "<<dog1.getName()<<endl;
cout<<"Age: "<<dog1.getAge()<<endl;
cout<<"Gender: "<<dog1.getGender()<<endl;
cout<<"Size: "<<dog1.getSize()<<endl<<endl;

/* Printing description of Dog2 */
cout<<"Dog 2 description:"<<endl;
cout<<"Name: "<<dog2.getName()<<endl;
cout<<"Age: "<<dog2.getAge()<<endl;
cout<<"Gender: "<<dog2.getGender()<<endl;
cout<<"Size: "<<dog2.getSize()<<endl<<endl;

/* Printing description of Dog3 */
cout<<"Dog 3 description:"<<endl;
cout<<"Name: "<<dog3.getName()<<endl;
cout<<"Age: "<<dog3.getAge()<<endl;
cout<<"Gender: "<<dog3.getGender()<<endl;
cout<<"Size: "<<dog3.getSize()<<endl<<endl;

/* Printing description of Dog4 */
cout<<"Dog 4 description:"<<endl;
cout<<"Name: "<<dog4.getName()<<endl;
cout<<"Age: "<<dog4.getAge()<<endl;
cout<<"Gender: "<<dog4.getGender()<<endl;
cout<<"Size: "<<dog4.getSize()<<endl<<endl;

// Calling bark behavior of dog
cout<<"Dog 1 is barking: ";
dog1.bark();
cout<<"Dog 3 is barking: ";
dog3.bark();
}

Program Snippet:

#include<iostream>
#include<string>
using namespace std;
/* Defining class Dog*/
class Dog
{
/* defining Dog class member variables */
private:
    // NOTE: Other characters of dog can be added similarly if needed
    string name;
    int age;
    char gender;
    int size;
public:
    // Dog class constructor
    Dog(string n, int a, char g, int s)
    {
        name = n;
        age = a;
        gender = g;
        size = s;
    }

    /* Defining Dog class methods to access members of class*/
    string getName()
    {
        return name;
    }
    int getAge()
    {
        return age;
    }
    char getGender()
    {
        return gender;
    }
    int getSize()
    {
        return size;
    }

    // defining barking behavior of Dog
    // NOTE: Here any other behavior or other member functions can be defined according to need
    void bark()
    {
        cout<<"Bow-wow"<<endl;
    }
};

// Defining main function/ driver function
int main()
{
    // Creating 4 objects of Dog with their properties
    Dog dog1("Puppy", 8, 'M', 6);
    Dog dog2("Lucy", 7, 'F', 5);
    Dog dog3("Tom", 8, 'M', 7);
    Dog dog4("Daisy", 6, 'F', 6);

    /* Printing description of Dog1 */
    cout<<"Dog 1 description:"<<endl;
    cout<<"Name: "<<dog1.getName()<<endl;
    cout<<"Age: "<<dog1.getAge()<<endl;
    cout<<"Gender: "<<dog1.getGender()<<endl;
    cout<<"Size: "<<dog1.getSize()<<endl<<endl;

    /* Printing description of Dog2 */
    cout<<"Dog 2 description:"<<endl;
    cout<<"Name: "<<dog2.getName()<<endl;
    cout<<"Age: "<<dog2.getAge()<<endl;
    cout<<"Gender: "<<dog2.getGender()<<endl;
    cout<<"Size: "<<dog2.getSize()<<endl<<endl;

    /* Printing description of Dog3 */
    cout<<"Dog 3 description:"<<endl;
    cout<<"Name: "<<dog3.getName()<<endl;
    cout<<"Age: "<<dog3.getAge()<<endl;
    cout<<"Gender: "<<dog3.getGender()<<endl;
    cout<<"Size: "<<dog3.getSize()<<endl<<endl;

    /* Printing description of Dog4 */
    cout<<"Dog 4 description:"<<endl;
    cout<<"Name: "<<dog4.getName()<<endl;
    cout<<"Age: "<<dog4.getAge()<<endl;
    cout<<"Gender: "<<dog4.getGender()<<endl;
    cout<<"Size: "<<dog4.getSize()<<endl<<endl;

    // Calling bark behavior of dog
    cout<<"Dog 1 is barking: ";
    dog1.bark();
    cout<<"Dog 3 is barking: ";
    dog3.bark();
}

Output Snippet:

E:\CheggSolutions\C++ question 24 Dog\program.exe Dog 1 description: Name: Puppy Age: 8 Gender: M Size: 6 Dog 2 description

I hope you got the provided solution.

Thank You.

Add a comment
Know the answer?
Add Answer to:
1) Using the O-O Paradigm create a class in C++ for the object Dog 2) Implement...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1) Using the Object-Oriented Programming Paradigm,implement the necessary code in Python creating a ‘Car’ class with...

    1) Using the Object-Oriented Programming Paradigm,implement the necessary code in Python creating a ‘Car’ class with a constructor that stores all the Car information (ID, MAKE, MODEL, YEAR , COLOR, MILEAGE, PRICE_TO_DEALER, SALE_PRICE, PROFIT) as attributes. 2) Implement and add the following methods to the ‘Car' class in Question 1. a) necessary getter methods b) necessary setter methods c) method to display all the information to the screen d) a method to calculate the profit

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class...

    JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare (); } The prepare method will...

  • Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named...

    Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...

  • Create a Java application, that support the following: Create an Employee class, which holds following information:...

    Create a Java application, that support the following: Create an Employee class, which holds following information: Employee First Name Employee Last Name Employee Phone Number Employee Address Employee id Employee Title Employee salary Create an application that uses the Employee class Constructors –Getters and setters A minimum of 3 constructors including default constructor equals() method Helper methods toString() method Create an array of 5 Employee objects Use a Scanner to read in 5 employee information Change 2 employees information (3-items...

  • 2-1. Define and implement a class named cart. A cart object represents a horse drawn cart...

    2-1. Define and implement a class named cart. A cart object represents a horse drawn cart that can seat up to four meerkats, after that meerkats have to walk. The meerkats must be represented by meerkat objects. The cart class has the following constructors and behaviours: cort)i bool addleerkat(meerkat cat); vold enptyCort() void printMeerkats0 // create an erpty cart object // dd, ?"eerkat to the cart, returns false if full // renove all reerkats from the core print the nane,...

  • Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the c...

    C++ Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...

  • C++ programming implement a struct int Container similar to C++’s standard template library std::vector but without using Object Oriented Programming.

    Assignment Description: We will implement a struct int Container similar to C++’s standard template library std::vector but without using Object-Oriented Programming. The Container struct will only have member variables and user-defined helper functions that will assist with constructing and destructing instances of the Container type, and to add items to the Container, check the length of the Container, etc. See below for function prototypes and descriptions. User-Defined Helper-Functions and Container Member Variables The helper-functions that operate on the Container data type...

  • When answering this question, can you please specify what you name your files? Thank you! Write a...

    When answering this question, can you please specify what you name your files? Thank you! Write a Java application, and an additional class to represent some real-world entity. Keep in mind that a class is a model in code of something real or imagined, which has attributes (member variables) and behaviors (member methods). The class will: a. Create a total of 5 member variables for the class, selecting the appropriate data types for each field. For example, a class to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT