Coder Social home page Coder Social logo

una-eif201-progra1-master / dev.funda.oop-polymorphism Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 238 KB

Polymorphism: Polymorphism permits objects to be treated as instances of their parent class rather than their actual class.

CMake 27.24% Nix 1.73% C++ 71.04%

dev.funda.oop-polymorphism's Introduction

Polymorphism

Documentation

Resources

Project Directory Structure

MyProject/
│
├── .github/workflows         # [optional] GitHub Actions workflow files
├── docs/                     # [optional] Documentation files│
├── src/                      # [required] Source files directory
│   ├── main.cpp              # [required] Main program file
│   └── MyClass.cpp           # Implementation of MyClass
│
├── include/                  # [required] Header files directory
│   └── MyClass.h             # Header for MyClass
│
├── .gitignore                # [required] Git ignore file
├── .replit                   # [optional] Repl.it configuration file
├── replit.nix                # [optional] Repl.it configuration file
├── CMakeLists.txt            # [required] CMake configuration file
└── README.md                 # [required] README file
  1. .github/workflows: This is a directory typically used in GitHub repositories for storing workflow files. GitHub workflows are part of GitHub Actions, which automate certain processes in a software development workflow, like running tests, deploying code, or other CI/CD (Continuous Integration/Continuous Deployment) tasks.

  2. docs/html: This looks like a directory within the docs folder, likely used for storing HTML files related to documentation. The commit message "Final changes" tagged as "now" indicates recent updates or finalization of the documentation in HTML format.

  3. include: This is commonly a directory containing header files in C or C++ projects, but it can also include other types of files in different contexts.

    1. MyClass.h: This contains the declarations of your class or functions.
  4. src: Short for "source", this directory usually contains the source code of the project.

    1. main.cpp: This is the entry point of your program.
    2. MyClass.cpp: This contains the implementation of a class or functions.
  5. .gitignore: This is a special file used by Git, the version control system. It tells Git which files or directories to ignore in a project, usually things like build outputs, temporary files, or files containing sensitive information.

  6. .replit: This file is specific to Repl.it, an online IDE (Integrated Development Environment). It's used to configure the Repl.it environment, such as specifying the language, build, and run commands.

  7. CMakeLists.txt: This is a file used by CMake, a build system that manages the build process in an operating system and compiler-independent manner.

  8. README.md: This file, typically written in Markdown, provides an overview of the project, including instructions on how to install, configure, and use it.

  9. replit.nix: This is likely a configuration file for Nix, a powerful package manager, used in the context of Repl.it. It specifies dependencies and environment settings for the project.

Building the Project

  1. Creating a Build Directory: It's a good practice to do an out-of-source build. This keeps your build files separate from your source files.

    mkdir build
    cd build
  2. Running CMake: From within the build directory, run CMake to generate the build system.

    cmake ..
  3. Compiling the Project: After CMake has done its job, you can use the generated build system to compile the project.

    make

    This will compile your project and generate an executable in the build directory.

Notes

  • CMake Version: Make sure to specify the minimum required version of CMake that your project needs.
  • Project Structure: This is a simple example. Larger projects may have more complex structures, with subdirectories for different modules, tests, third-party libraries, etc.
  • C++ Standard: Set the C++ standard according to your project requirements.
  • Include Directories: Use include_directories to include your header files.
  • Executable: Use add_executable to specify the executable name and the source files required to build it.

This structure is scalable and can be expanded as your project grows, by adding more source files, headers, and potentially CMake configuration files in subdirectories.

The Example

// Example of Polymorphism
class Animal {
  public:
    virtual void makeSound() {
        cout << "Some sound" << endl;
    }
};

class Pig : public Animal {
  public:
    void makeSound() override {
        cout << "Oink oink" << endl;
    }
};

class Dog : public Animal {
  public:
    void makeSound() override {
        cout << "Bark bark" << endl;
    }
};

int main() {
    Animal myAnimal;
    Pig myPig;
    Dog myDog;

    myAnimal.makeSound();  // Output: Some sound
    myPig.makeSound();     // Output: Oink oink
    myDog.makeSound();     // Output: Bark bark
    return 0;
}

This demonstrates polymorphism where the makeSound() method behaves differently based on the object type (Animal, Pig, Dog).

dev.funda.oop-polymorphism's People

Contributors

mikeguzman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.