Write a complete the most simplistic C++ program that creates a Daggo class and
ID: 3723826 • Letter: W
Question
Write a complete the most simplistic 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)
name: string, name of the dog
color: string, color of the dog
weight: double
height: double
Constructors:
No-argument constructor: the constructor has no parameter
Standard constructor: the constructor with the same number of parameters as properties.
Methods
bark(): no return, i.e. void return type, describe how the dog bark, what does it sound like.
fetch(item): no return, describe how the dog retrieves this item.
display(): no return, prints the name and current value of every property.
The main() function should be placed below the Daggo class, inside the same source file as the Daggo class. In the main() 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
Note: I have need clearifiction how you wants to implement bark and fetch functions. Becuase i have
confusion what you needs to implement as there is nothing mentioned in the requirement. Also,
Do you want user input for both default as well as standard constructor.
Please add your comments on above mentioned points. Once requirement become clear, i'll quickly finish
the fuction and also provide you the sample output.
Thanks
//============================================================================
// Name : daggo.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <string.h>
using namespace std;
// This is daggo class used to store dog's information
class Daggo {
public:
// properties of the dog
string name;
string color;
double weight;
double height;
//constructor without parameters.
Daggo();
// constructor with dog's properties as parameter.
Daggo(string dogName, string dogColor, double dogWeigth, double dogHeight);
//method's for daggo class.
void bark();
void fetch(string item);
void display();
};
//constructor without parameters.
//initializing weight and height fields.
Daggo::Daggo() {
weight = 0.0;
height = 0.0;
}
// constructor with dog's properties as parameter.
Daggo::Daggo(string dogName, string dogColor, double dogWeigth,
double dogHeight) {
name = dogName;
color = dogColor;
weight = dogWeigth;
height = dogHeight;
}
// This method will prints how dog's bark
void Daggo::bark() {
// to-do
}
// this function will prints how dog fetch the given item
void Daggo::fetch(string item) {
// to -do
}
// this function will displays the dog's information
void Daggo::display() {
cout << name << " is " << color << ". It's weight is " << weight
<< " pounds and height is " << height << " inches" << endl;
}
int main() {
// creating object with no arguments
Daggo dog1;
dog1.name = "bull dog";
dog1.color = "black";
dog1.weight = 1000.0;
dog1.height = 20.3;
dog1.bark();
dog1.fetch("stick");
dog1.display();
string name;
string color;
double weight;
double height;
// Promoting user for input
cout << "Enter dog's name: ";
cin >> name;
cout << "Enter dog's color: ";
cin >> color;
cout << "Enter dog's weight: ";
cin >> weight;
cout << "Enter dog's height: ";
cin >> height;
// creating standard daggo object with parameters.
Daggo dog2(name,color, weight, height);
dog2.bark();
dog2.fetch("stick");
dog2.display();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.