Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone please help with the following C++ program: Write a program that creates a virtual pet for the user to care for. The player

Can someone please help with the following C++ program:

Write a program that creates a virtual pet for the user to care for. The player will care for the pet by keeping it fed, healthy, happy, clean, and not bored, The virtual pet talks to the player to let them know their status. Include both a default constructor and a constructor that accepts the pet type as an argument (cat, dog, horse) and then appropriately sets different starting status values. Use an overloaded stream operator to output the status of the virtual pet (pet class). Time passes for all cases for each user choice so you will use an overloaded prefix or postfix increment operator for the passage of time (++). Make sure to use a random amount of time with related random changes to pet status. You will use a pet class with member functions for each of the required actions. Partial code examples for the class and the main program are provided. You should add at least two additional functions, such as cleanliness and health, to the virtual pet class. Once completed, you will submit all your code files and your execution screenshot.

EXAMPLE CLASS CODE FOR THE HEADER FILE:

class VirtualPet { public: VirtualPet(); void Talk(); void Eat(int food); void Play(int fun);

private: int m_Hunger; int m_Boredom; int GetMood() const; Virtualpet operator ++ (Virtualpet); ostream &operator << (ostream &strm, Virtualpet &obj);

};

EXAMPLE CODE FOR THE MAIN PROGRAM:

int main() { String pettype; cout << Do you want a dog, cat or horse? ; cin >> pettype; Virtualpet mypet(pettype); mypet.Talk();

int choice; do { cout << " Hello to the New Pet Parent "; cout << "0 - Quit "; cout << "1 - Listen to your pet "; cout << "2 - Feed your pet "; cout << "3 - Play with your pet "; cout << 4 Give your pet a bath ; cout << 5 Give your pet medicine ;

cout << "Which one would you like to do with your pet?"; cin >> choice;

switch (choice) { case 0: cout << "Good-bye. "; break; case 1: ++mypet mypet.Talk(); cout << mypet; break; case 2: mypet.Eat(); cout << ++mypet; break; case 3: mypet.Play(); cout << ++mypet; break; case 4: mypet.Bath(); cout << ++mypet; break; case 5: mypet.Meds(); cout << ++mypet; break; default: cout << " Sorry, but " << choice << " isn't a valid choice. "; } } while (choice != 0);

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions

Question

1. Make sure you can defend the grade in the first place.

Answered: 1 week ago

Question

Define the goals of persuasive speaking

Answered: 1 week ago