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

Subject: Write a complete C++ program that creates a Daggo class and uses object

ID: 3724832 • Letter: S

Question

Subject: Write a complete C++ program that creates a Daggo class and uses objects of this class. As the class name implies, this represents a dog. The Daggo class consists of following components. Properties (assuming default access modifier) o name: string, name of the dog o color: string, color of the dog o o e Constructors weight: double height: double o No-argument constructor: the constructor has no parameter o Standard constructor: the constructor with the same number of parameters as properties . Methods o bark0: no return, ie. void return type, describe how the dog bark, what does it sound like. o fetch item): no return, describe how the dog retrieves this item. o displayO: no return, prints the name and current value of every property. The mainO function should be placed below the Daggo class, inside the same source file as the Daggo class. In the main0 function, create two Daggo objects, one from the no-argument constructor, another from the standard constructor. For the latter object from the standard constructor, one value should be read from the user with proper prompts. At the end, call every method from each object.

Explanation / Answer

#include <iostream>

using namespace std;

class Daggo

{

//members with default access modifier

string name;

string color;

double weight;

double height;

public:

//No argument constructor

Daggo() {}

//standard constructor

Daggo(string n, string c, double w, double h)

{

name = n;

color = c;

weight = w;

height = h;

}

//bark method

void bark(){

cout<<"bow... boww... bowww..."<<endl;

}

//fetching method

void fetch(Daggo *d){

cout<<"Name: "<<d->name<<endl<<"Color: "<<d->color<<endl<< "Weight: "<<d->weight<<endl<<"Height: "<<d->height<<endl;

}

//display of properties

void display(){

cout<<"Name: "<<name<<endl<<"Color: "<<color<<endl<< "Weight: "<<weight<<endl<<"Height: "<<height<<endl;

}

};

int main(){

//instantiate object with no argument constructor

Daggo *dog1 = new Daggo();

string name, color;

double weight, height;

cout<<"Enter name: ";

cin>>name;

cout<<"Enter color: ";

cin>>color;

cout<<"Enter weight: ";

cin>>weight;

cout<<"Enter height: ";

cin>>height;

//instantiate object with number of paramenter for standard constructor

Daggo *dog2 = new Daggo(name, color, weight, height);

cout<<"Bark: ";

dog2->bark();

//display details

cout<<" Details: "<<endl;

dog2->display();

//fetching one from another object

cout<<" Fetching dog2 object from dog1 object ";

dog1->fetch(dog2);

}