Microsoft Visual C#
Microsoft Visual C#
7th Edition
ISBN: 9781337102100
Author: Joyce, Farrell.
Publisher: Cengage Learning,
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

C++ help.

In the class definition, initialize the data members, string type and integer age, with the default values "Unstated" and 0, respectively.

Ex: If the input is mouse 13, then the output is:

Type: Unstated, Age: 0 Type: mouse, Age: 13

Note: The class's print function is called first after the default constructor, then again after the inputs are passed to the setters.

'''

#include <iostream>
#include <string>
using namespace std;

class Animal {
   public:
      void SetType(string animalType);
        void SetAge(int animalAge);
      void Print();

   private:

      /* Your code goes here */

};

void Animal::SetType(string animalType) {
    type = animalType;
}

void Animal::SetAge(int animalAge) {
    age = animalAge;
}

void Animal::Print() {
   cout << "Type: " << type << ", Age: " << age << endl;
}

int main() {
   string newType;
    int newAge;
   Animal myAnimal;

   myAnimal.Print();

   cin >> newType;
    cin >> newAge;

   myAnimal.SetType(newType);
    myAnimal.SetAge(newAge);

   myAnimal.Print();

   return 0;
}
'''

SAVE
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
bartleby
Unlock instant AI solutions
Tap the button
to generate a solution
Click the button to generate
a solution
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning