Answer to Question #189341 in C++ for Dunga

Question #189341
  1. Write a class definition for a Dog. Private data fields include name, breed, and age, and a constant static field for the license fee, which is $13.45. Create public member functions to set and display the data. Write a main() function that demonstrates the class operates correctly.
1
Expert's answer
2021-05-07T04:44:52-0400
#include <iostream>
using namespace std;

class Dog {
    private:
        string name;
        string breed;
        int age;
    public:
        static const double licenseFee;
    public:
        void setData(string name, string breed, int age);
        void display();
};

void Dog::setData(string name, string breed, int age) {
    this->name = name;
    this->breed = breed;
    this->age = age;
}

void Dog::display() {
    cout << "Dog's name: " << this->name << ", breed: " << this->breed <<
    ", age: " << this->age << ", license fee: $" << Dog::licenseFee << endl;
}

const double Dog::licenseFee = 13.45;

int main() {
    Dog Bobby;
    Dog Daisy;
    Dog Cooper;

    Bobby.setData("Bobby", "Yorkshire Terrier", 3);
    Daisy.setData("Daisy", "Poodle", 1);
    Cooper.setData("Cooper", "Labrador Retriever", 5);

    Bobby.display();
    Daisy.display();
    Cooper.display();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS