0% found this document useful (0 votes)
23 views2 pages

Oop Group Work-1

Uploaded by

fasteluv19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Oop Group Work-1

Uploaded by

fasteluv19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

github link

demo link

Overview for Pet Management Software System

This system models a pet management application using object-oriented principles in C++.
The design is based on the principles of Encapsulation, Inheritance, Polymorphism,
Abstraction, and Exception Handling, all of which are applied to create a simple yet
effective system for managing different types of pets (Dog, Cat, Fish).

1. Classes and Objects

We define the following classes to represent various entities in the system:

● Pet Class: A base class representing general pet characteristics like name, hunger,
and happiness. It includes methods like feed(), play(), and displayStats().
This class also enforces encapsulation by keeping certain attributes private and
providing public methods to interact with them.
● Dog, Cat, and Fish Classes: Derived from the Pet class, these classes implement
specific behavior for each type of pet. For example, a Dog's feed() method reduces
hunger by 15, while a Fish’s feed() method reduces hunger by 10. These classes
demonstrate inheritance and polymorphism by overriding the virtual feed() and
play() methods from the base Pet class.
● PetManager Class: This class manages a collection of pets. It allows the creation,
feeding, playing with, and viewing stats of pets. It uses a vector of shared pointers to
hold Pet objects, demonstrating smart pointers for memory management. The
createPet() method uses polymorphism to create instances of specific pet types
based on input.

2. Inheritance and Polymorphism

● Inheritance: The Dog, Cat, and Fish classes inherit from the base Pet class, which
allows them to share common behavior (like hunger and happiness) and also define
their own specific behaviors (like feeding and playing).
● Polymorphism: We use virtual functions in the Pet class (feed(), play()) to
enable method overriding in derived classes. The PetManager class can interact
with different types of pets in a uniform way, regardless of their specific type.

3. Abstraction
● The Pet class is abstracted to hide the internal details of each pet's behavior. The
methods feed() and play() are pure virtual functions, forcing derived classes to
implement them. This ensures that the PetManager class interacts with pets
through a well-defined interface.

4. Exception Handling

● Basic error handling is incorporated using standard C++ error reporting. If the user
tries to interact with a pet that doesn't exist or provides an invalid pet type, the
system will display an error message using std::cerr.

5. File I/O

● Though not fully implemented in the initial code, the system is designed to be
extended with file handling for saving and retrieving pet data (e.g., using fstream).
For future enhancements, pet details such as name, type, and stats could be saved
to and read from a file.

6. Menu/Command-line Interface

● The program provides a simple CLI for the user to interact with the system. The
options include:
○ Create a pet (by name and type)
○ Feed a pet
○ Play with a pet
○ View pet stats
○ Exit the application
● This allows the user to manage pets through a text-based interface, demonstrating
basic interaction with the backend system.

Conclusion

The system for managing pets in this application is designed with clear object-oriented
principles. It effectively demonstrates encapsulation, inheritance, polymorphism, and
abstraction, providing a solid foundation for managing pets in a console-based application.
The system is modular and can be easily extended with more functionality, like file I/O for
persistent data storage, or additional pet types.

You might also like