Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class definition for an object that represents a dog. A dog has a name,

ID: 3564267 • Letter: W

Question

Write a class definition for an object that represents a dog. A dog has a name, breed, gender, and weight. A dog can do the following: bark() - display text "ruff ruff" sleep() - display text "zzzzz" display() - displays dog's information Write a main program that creates a dog. Ask the user for a name and update the dog's name. Ask the user if they want to (b) have the dog bark (s) have the dog sleep (d) display the dogs information Allow the user to select any of those options as many times as they want.

Explanation / Answer

#include<iostream>

using namespace std;

class Dog{
private :
   char name[20];
       char breed[20];
       char gender;
       double weight;

   public :
   void bark(){
       cout << "ruff ruff " << endl;
       }

       void sleep(){
       cout << "zzzzzzzz" << endl;
       }

       void display(){
       cout << "Name = " << name << endl;
           cout << "Breed = " << breed << endl;
           cout << "Gender = " << gender << endl;
           cout << "Weight = " << weight << endl;
       }
       void getData(){
       cout << "Enter the name of the Dog : ";
cin >> name;
cout << "Enter the breed of the Dog : ";
cin >> breed;
cout << "Enter the gender of the Dog : (M/ F) : ";
cin >> gender;
cout << "Enter the weight of the Dog : ";
cin >> weight;
       }
};

int main(){
Dog d1;
   d1.getData();
   char choice;
   do{
cout << " ";
   cout << "Enter 'b' if you want the dog to bark " << endl;
       cout << "Enter 's' if you want the dog to sleep " << endl;
       cout << "Enter 'd' if you want to see dog's information " << endl;
       cout << "Enter 'q' if you want to quit" << endl;

       cin >> choice;

       switch(choice){
       case 'b' :
           d1.bark();
               break;
           case 'd' :
           d1.display();
               break;
           case 's' :
           d1.sleep();
               break;
           case 'q' :
           return 0;
       }
   }while(choice != 'q');
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote