Skip to content

harshul997/NetworkSimulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

NetworkSimulator

🧠 Learning Summary: OOP + Shape Simulator Project

This repository contains a learning-based implementation of an object-oriented shape simulator using C++. The project was designed to develop a strong understanding of class design, inheritance, polymorphism, modular code structure, compilation automation, and 2D visualization using SFML.


📘 Week 1: Learning OOP and Building Shapes

🔹 Section 1.1: Understanding Classes in C++

Resources: [learncpp.com Chapters 14 & 15]

Key Learnings:

  • Classes allow bundling data + behavior.
  • Understood access specifiers (public, private, protected).
  • Constructors, destructors, and initialization lists.
  • Created member methods like getLength(), getBreadth(), getArea().

Takeaway: A well-structured class can simplify program logic and extend easily through inheritance.


🔹 Section 1.2: Multi-file Projects in C++

Resources: [learncpp.com Chapters 2.11, 2.12, 7.8, 7.10]

Key Learnings:

  • Separated interface (.h) and implementation (.cpp).
  • Header guards to prevent redefinitions.
  • Used #include to link files together.

Takeaway: Separation of concerns improves readability and debugging in large projects.


🔹 Section 1.3: Makefiles and Build Automation

Resources: [Makefile Tutorials]

Key Learnings:

  • Automated compilation using Makefile.
  • Only modified files are recompiled.
  • Commands like make, make clean simplify workflow.

Takeaway: Automating builds is essential in real-world projects to save time and prevent errors.


🛠️ Tasks & Implementation

✅ Task 1.1: Rectangle Class

  • Created class with length, breadth.
  • Added methods: getLength(), getBreadth(), getArea(), isSquare().

✅ Task 1.2: Square Class

  • Inherited from Rectangle.
  • Ensured both sides are equal.
  • Overridden relevant methods.

✅ Task 1.3: Shape Hierarchy + Circle

  • Introduced abstract base class Shape.
  • Derived: Rectangle, Square, Circle.
  • Used polymorphism to call derived methods using Shape*.

✅ Task 1.4: Added Ellipse Class

  • Created Ellipse with xRadius, yRadius.
  • Made Circle inherit from Ellipse with equal radii.

✅ Task 1.5: getShape() Mapping

Each shape class implements int getShape():

Shape ID
Rectangle 0
Square 1
Circle 2
Ellipse 3

📘 Week 3: UML Design & Visualization with SFML

🧩 Task 1.1: Understanding UML

Resources: UML introductory videos, tools like draw.io, StarUML, PlantUML.

Key Learnings:

  • UML (Unified Modeling Language) helps in visualizing and planning class relationships before coding.
  • Diagrams created:
    • Class diagrams showing inheritance between Shape, Rectangle, Square, Ellipse, Circle.
    • Attributes and public method signatures.
  • Benefits:
    • Easier debugging.
    • Cleaner and modular design.
    • Reduces interdependencies and simplifies extensions.

🧩 Task 1.2: Creating UML Diagram for Shape Classes

  • Represented following relationships:
    • Shape is an abstract base class.
    • Rectangle, Square, Ellipse, and Circle inherit from Shape.
    • Circle inherits from Ellipse.
    • Optional: A Coordinate class included to handle positions.
  • Each class includes:
    • Attributes: dimensions (length, breadth, radius), position.
    • Methods: getShape(), getArea(), translate(), etc.

🧩 Task 1.3: Canvas Class Implementation

  • Class: Canvas

    • Stores shapes using: std::vector<Shape*> shapes;
    • Method: void addShape(Shape* shape); to add a shape to canvas.
    • Method: void displayCanvas(); renders all shapes in a graphical window.
  • Display Logic with SFML:

    • Each shape implements a draw(sf::RenderWindow&) method.
    • Canvas::displayCanvas() loops over all shapes and calls their draw() method.
    • Promotes separation of concerns: rendering handled by each shape individually.

Tools Used:

  • SFML Library for 2D graphics.
  • Installed using:
    sudo apt install libsfml-dev
    

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages