Question

In this module you learned about Object-Oriented programming in C++ and how to combine this approach...

In this module you learned about Object-Oriented programming in C++ and how to combine this approach with the concepts covered in previous modules

For this assignment you will write a class called Dog that has the following member variables:

  • birthyear. An int that holds the dog’s birth year.
  • breed. A string that holds the breed of dog.
  • vaccines. A Boolean holding a yes/no value indicating whether the dog is currently on vaccinations.

In addition, the class should have the following member functions:

  • Constructor. The constructor should accept the dog’s birthyear, breed and vaccines as arguments and assign these values to the object’s birthyear, breed and vaccines member variables.
  • Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an object’s birthyear, breed and vaccinesmember variables.

Demonstrate the class in a program that creates a Dog object. The user should enter all input. Be sure to include comments throughout your code where appropriate.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student,

Thanks for posting an interesting question of OOPS concepts in C++.

So, for the given question. I have created a complete program and created Dog.cpp file having Dog class.

1. Please find below complete Dog class screenshot with proper comments to each line of the code.

2. Please find complete program in text format with proper comments to each line of the code:-

#include<iostream>

//for getting Stream size value used for flushing the console stream buffer
#include<ios>
  
//for getting numberic limits value used for flushing the console stream buffer
#include<limits>

using namespace std;

//Declaration of Class Dog
class Dog {

//Declaring three private variables birthYear, breed and vaccines
private :
int birthYear;
string breed;
bool vaccines;

public:

   //Constructor to initalize the instance variables of Dog class
   Dog(int birthYear_constrcut, string breed_construct, bool vaccines_construct){
birthYear = birthYear_constrcut;
breed = breed_construct;
       vaccines = vaccines_construct;
}

   //Accessor to get Birth year
   int getBirthYear(){
       return birthYear;
   }
  
   //Accessor to get breed
   string getBreed(){
       return breed;
   }
  
   //Accessor to get Vaccines
   bool getVaccines(){
       return vaccines;
   }
};

int main(){  
   //Declaring three variables birthYear, breed and vaccines to store input from the user
   int birthYear;
   string breed;
   bool vaccines;
  
   //Inputting all the parameters i.e. birthYear, breed and vaccines
   cout<<"Enter dog's birth year ";
   cin>>birthYear;
   //Below line will remove \n i.e. new line from the stream buffer so that it's value not copied to the breed variables
   //Mainly it is for flushing the buffer
   cin.ignore(numeric_limits<streamsize>::max(),'\n');
   cout<<"Enter dog's breed ";
   getline(cin,breed);
   cout<<"Enter dog's vaccines 1 for yes and 0 for no ";
   cin>>vaccines;
  
   //Creating Dog d object
   Dog d(birthYear, breed, vaccines);
  
   //Printing Dog d object details accessing using the accessors of the Dog class
   cout<<"Entered dog details are:\nBirth Year-"<<d.getBirthYear()<<", Breed-"<<d.getBreed()<<", Vaccines-";  
   if(d.getVaccines()){
       cout<<"Yes";
   }else{
       cout<<"No";
   }

}

3. Please find output screenshot of the above program after taking input from the user:-

4. The important part of the code is to creation of Dog class and to print the message and initializing Dog object using constructor. That part I marked in bold.

5. Please note that I put main method inside the same Dog.cpp file for demonstration of the Dog class.

6. Though I put comments to each line of the code. Still if you have any query please feel free to reach me through comments section. I will be more than happy to help you further.

7. If you like my answer, please upvote it by pressing thumb's up button.

Thanks!!

Happy Learning!!

Add a comment
Know the answer?
Add Answer to:
In this module you learned about Object-Oriented programming in C++ and how to combine this approach...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a...

    C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a class named Car that has the following member variables: year. An int that holds the car’s model year. make. A string object that holds the make of the car. speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. Constructor. The constructor should accept the car’s year and make as arguments and assign these values...

  • It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming...

    It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming Challenge 2 Employee Class.pdf Program Template: // Chapter 13, Programming Challenge 2: Employee Class #include <iostream> #include <string> using namespace std; // Employee Class Declaration class Employee { private: string name; // Employee's name int idNumber; // ID number string department; // Department name string position; // Employee's position public: // TODO: Constructors // TODO: Accessors // TODO: Mutators }; // Constructor #1 Employee::Employee(string...

  • Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing...

    Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing this assignment, students will practice Object Oriented design and programming by creating a Java program that will implement Object Oriented basic concepts. RetailItem Class: Part 1: Write a class named RetailItem that holds data about an item in a retail store. The class should have the following fields: • description. The description field references a String object that holds a brief description of the...

  • C++ Programing In this exercise, you will design a class memberType. The class has the following...

    C++ Programing In this exercise, you will design a class memberType. The class has the following data members: memberName. A string that holds the name of a person memberID. A string that holds the member identification number numBooks. An int that holds the number of books bought purchaseAmt. A double that holds the amount spent on books In addition, the class should have the following constructor and other member functions. Constructor. The constructor should accept the person’s name and member...

  • Write a Java object class Cat with the member variables (fields) color, breed, birthday, and weight....

    Write a Java object class Cat with the member variables (fields) color, breed, birthday, and weight. Create an empty constructor and overload that constructor and have it accept values for each member variable. There should be manipulator (setter) and accessor (getter) methods for each member variable. Ensure the Cat object has a toString() method. The accessor method for the birthday should return the date in the format MM/DD/YYYY. Add an accessor method getAgeInYears() that calculates how many years old the...

  • Using C++, Write a class named Employee that has the following member variables: name. A string...

    Using C++, Write a class named Employee that has the following member variables: name. A string that holds the employee's name. idNumber. An int variable that holds the employee's ID number. department. A string that holds the name of the department where the employee works. position. A string that holds the employee's job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee's name,...

  • python Design a class named Car that has the following fields: yearModel: The yearModel field is...

    python Design a class named Car that has the following fields: yearModel: The yearModel field is an Integer that holds the car’s year model. make: The make field references a String that holds the make of the car. speed: The speed field is an Integer that holds the car’s current speed. In addition, the class should have the following constructor and other methods: Constructor: The constructor should accept the car’s year model and make as arguments. These values should be...

  • Exercise #3: Create a class to represent a dog. Name the class “Dog”. It will contain...

    Exercise #3: Create a class to represent a dog. Name the class “Dog”. It will contain three (3) class attributes, its bark, size, and cuteness. The bark will be the sound of the dog’s bark, as in “woof!”. Its size will be how tall the dog is from the ground, and that number should always be between 6 and 44 inches. The cuteness is a string describing how cute the dog is, based on this scale: “ugliest dog ever!” “pretty...

  • In Java please Create a class to represent a dog. Name the class “Dog”. It will...

    In Java please Create a class to represent a dog. Name the class “Dog”. It will contain three (3) class attributes, its bark, size, and cuteness. The bark will be the sound of the dog’s bark, as in “woof!”. Its size will be how tall the dog is from the ground, and that number should always be between 6 and 44 inches. The cuteness is a string describing how cute the dog is, based on this scale: “ugliest dog ever!”...

  • Second time posting please answer this question!!! Thankyou!! Please do it in visual studio C #...

    Second time posting please answer this question!!! Thankyou!! Please do it in visual studio C # and post copy of form.cs and designer.cs. Will give vgood review!!! In this module you learned about Classes and Multiforms. You will be completing one program for this module Write a class named Car that has the following member variables: year -    An int that holds the car’s model year. make - A string object that holds the make of the car. speed -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT