Answer to Question #188942 in C++ for Dunga

Question #188942
  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-08T04:23:42-0400
#include <iostream>


using namespace std;


class Dog
{
private:
    const double licenseFee = 13.45;
    string name;
    string breed;
    int age;


public:
    void setName(string name)
    {
        this->name = name;
    }
    void displayName()
    {
        cout << name;
    }


    void setBreed(string breed)
    {
        this->breed = breed;
    }
    void displayBreed()
    {
        cout << breed;
    }


    void setAge(int age)
    {
        this->age = age;
    }
    void displayAge()
    {
        cout << age;
    }


};


int main()
{
    string name;
    cout << "Enter name: ";
    getline(cin, name);


    string breed;
    cout << "Enter breed: ";
    getline(cin, breed);


    int age;
    cout << "Enter age: ";
    cin >> age;


    Dog dog;
    dog.setName(name);
    dog.setBreed(breed);
    dog.setAge(age);


    cout << endl << "Name: ";
    dog.displayName();
    cout << endl << "Breed: ";
    dog.displayBreed();
    cout << endl << "Age: ";
    dog.displayAge();


    return 0;
}

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
APPROVED BY CLIENTS