Skip to content

A collection of my C++ code snippets, covering basic concepts, problem-solving examples, and practice exercises. This repo is mainly for learning, revision, and experimenting with different approaches in C++.

Notifications You must be signed in to change notification settings

MuhammadHassan-094/Cpp

Repository files navigation

🚀 C++ Practice Programs

C++
Beginner Friendly
Hacktoberfest
Contributions Welcome

This repository contains well-structured C++ programs organized by topics.
It covers everything from basic concepts to advanced programming like OOP, Pointers, File Handling, and STL.

If you find this repo helpful, don’t forget to give it a ⭐


📑 Table of Contents


📂 Folder Overview

  • A. Basics & Fundamentals → Simple programs like Hello World, sum, factorial, prime check, etc.
  • B. Patterns → Star, number, and alphabet patterns (pyramid, diamond, butterfly, zig-zag, etc.).
  • C. Arrays & Strings → Array operations, palindrome check, searching, and sorting.
  • D. Functions & Recursion → Power, GCD, Fibonacci, reverse string, and sum of digits.
  • E. Object-Oriented Programming (OOP) → Classes, constructors, inheritance, polymorphism, encapsulation.
  • F. Pointers & Memory → Swap numbers, reverse array with pointers, dynamic memory allocation, this pointer.
  • G. File Handling → Read/write files, word count, copy & append content.
  • H. Standard Template Library (STL) → Stack, Queue, Vector, Map, Set with built-in functions.

📝 Topics Covered

🔹 Basics & Fundamentals

  • Hello World
  • Sum of two integers
  • Even/Odd check
  • Largest of three numbers
  • Factorial using loops
  • Multiplication table
  • Prime check
  • Prime numbers from 1–100
  • Leap year check
  • Reverse an integer

🔹 Patterns

  • Right-angled triangle
  • Inverted right-angled triangle
  • Square & Hollow square
  • Pyramid & Inverted pyramid
  • Diamond & Hollow diamond
  • Number patterns (Floyd’s, Pascal’s, etc.)
  • Alphabet patterns
  • Advanced patterns (Checkerboard, Hollow Pyramid, Butterfly, Sandglass, Zig-Zag)

🔹 Arrays & Strings

  • Largest & second largest in array
  • Reverse array in-place
  • Frequency count of elements
  • Check if array is sorted
  • Merge two sorted arrays
  • Remove duplicates
  • Linear & Binary Search
  • Palindrome string check

🔹 Functions & Recursion

  • Power function (x^y) using recursion
  • GCD of two numbers
  • Fibonacci number
  • Reverse string using recursion
  • Sum of digits using recursion

🔹 Object-Oriented Programming (OOP)

  • Student class (attributes + input/output)
  • Rectangle class (area, perimeter)
  • BankAccount (deposit & withdraw)
  • Copy constructor
  • Complex number operations
  • Function overloading
  • Operator overloading (+)
  • Inheritance (Shape → Circle/Square)
  • Runtime polymorphism (virtual functions)
  • Encapsulation (private vars, public methods)

🔹 Pointers & Memory

  • Swap numbers using pointers
  • String length using pointers
  • Dynamic memory allocation (new)
  • Reverse array using pointers
  • this pointer demonstration

🔹 File Handling

  • Write user input into file
  • Read and display contents
  • Count number of words
  • Copy file contents
  • Append data to existing file

🔹 Standard Template Library (STL)

  • Stack → LIFO operations
  • Queue → FIFO operations
  • Vector → Sorting with sort()
  • Map → Key-value storage & retrieval
  • Set → Unique numbers in ascending order

💡 Why this repo?

✔️ Beginner-friendly examples
✔️ Organized by topics
✔️ Covers theory + implementation
✔️ Useful for exams, interviews, and practice


⭐ Don’t forget to star this repository if it helped you!

About

A collection of my C++ code snippets, covering basic concepts, problem-solving examples, and practice exercises. This repo is mainly for learning, revision, and experimenting with different approaches in C++.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages