Skip to content

Latest commit

Β 

History

73 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’» C++ Programs

A collection of C++ programs covering basic concepts, problem-solving, algorithms, and object-oriented programming.

πŸ“š Topics Included

  • Variables & Data Types
  • Operators
  • Conditional Statements
  • Loops
  • Functions
  • Arrays
  • Strings
  • Pointers
  • Structures
  • Classes & Objects
  • Inheritance
  • Polymorphism
  • File Handling
  • Standard Template Library (STL)
  • Sorting & Searching
  • Pattern Programs
  • Basic Algorithms

πŸ“‚ Repository Structure

πŸ“ Cpp-Programs
β”œβ”€β”€ Calculator.cpp
β”œβ”€β”€ Conditional_statemen.cpp
β”œβ”€β”€ If_statemen.cpp
β”œβ”€β”€ README.md
β”œβ”€β”€ Switch.cpp
β”œβ”€β”€ Third.cpp
β”œβ”€β”€ Triangle.cpp
β”œβ”€β”€ arithmetic_operations.cpp
β”œβ”€β”€ ternary_operator.cpp
β”œβ”€β”€ Temperature.cpp
β”œβ”€β”€ While_loop.cpp
β”œβ”€β”€ DO-While - Loop.cpp
β”œβ”€β”€ For_Loop.cpp
β”œβ”€β”€ Break_continue.cpp
β”œβ”€β”€ Squre_game.cpp
β”œβ”€β”€ Random Number.cpp
β”œβ”€β”€ Conditional_statemen.cpp
β”œβ”€β”€ Random_event.cpp
β”œβ”€β”€ Number_Guess.cpp
β”œβ”€β”€ Functions.cpp
β”œβ”€β”€ Function-2.cpp
β”œβ”€β”€ Function--3.cpp
β”œβ”€β”€ Grade_system.cpp
β”œβ”€β”€ Function 4.cpp
β”œβ”€β”€ Full Name.cpp
β”œβ”€β”€ void day()
β”œβ”€β”€ Global_variable.cpp
β”œβ”€β”€ Bank_System.cpp
β”œβ”€β”€ Bank-version-2.cpp
β”œβ”€β”€ Rock-paper-Game.cpp
β”œβ”€β”€ Arrays.cpp
β”œβ”€β”€ Arrays-2.cpp
β”œβ”€β”€ Arrays-3.cpp
β”œβ”€β”€ Dice.cpp
β”œβ”€β”€ Array-loop.cpp
β”œβ”€β”€ Array-loop-sum.cpp
β”œβ”€β”€ Search-Array.cpp
β”œβ”€β”€ Menu.cpp
β”œβ”€β”€ Search_string_array.cpp
β”œβ”€β”€ C-Bubble_sort.cpp
β”œβ”€β”€ Fill_Function.cpp
β”œβ”€β”€
β”œβ”€β”€
└── ...

πŸ› οΈ Requirements

  • C++17 or later
  • Any C++ compiler (GCC, MinGW, MSVC, Clang)

▢️ Compile & Run

Compile:

g++ filename.cpp -o output

Run:

Windows

output.exe

Linux / macOS

./output

🎯 Purpose

This repository is maintained for learning, practice, and improving C++ programming skills. New programs and concepts will be added regularly.

==================================== C++ CHEAT SHEET


WHAT IS C++?

β€’ General-purpose programming language. β€’ Created by Bjarne Stroustrup (1985), β€’ Extension of the C language. β€’ Supports Object-Oriented Programming (OOP). β€’ Compiled language. β€’ Fast and memory efficient.


PROGRAM STRUCTURE

#include

int main() { std::cout << "Hello World!"; return 0; }

Explanation:

#include -> Includes a library. -> Input & Output library. int -> Return type. main() -> Program entry point. {} -> Code block. return 0; -> Program ended successfully.


COMMENTS

Single-line

// Comment

Multi-line

/* Comment Comment */


DATA TYPES

Integer

int age = 18;

Floating Point

float price = 10.5f; double pi = 3.1415926535;

Character

char grade = 'A';

Boolean

bool isOnline = true;

String

std::string name = "ZERO";

Void

void function();


SIZE OF DATA TYPES

char -> 1 Byte bool -> 1 Byte short -> 2 Bytes int -> 4 Bytes long -> 4 or 8 Bytes long long -> 8 Bytes float -> 4 Bytes double -> 8 Bytes

Check size:

sizeof(int)


VARIABLES

Declaration

int age;

Initialization

int age = 18;

Multiple Variables

int a = 1, b = 2, c = 3;


CONSTANTS

const double PI = 3.14159;

Cannot be modified.


LITERALS

10 Integer 3.14 Double 3.14f Float 'A' Character "Hello" String true Boolean


KEYWORDS

int float double char bool void return const if else switch case default for while do break continue class struct public private protected virtual new delete namespace using typedef auto


NAMESPACE

std::cout

Using whole namespace

using namespace std;

Using specific object

using std::cout;

Type alias

using text = std::string;


SCOPE RESOLUTION ::

std::cout

MyClass::function()

Namespace::variable


INPUT

int age;

std::cin >> age;


OUTPUT

std::cout << "Hello";

New Line

'\n'

or

std::endl


OPERATORS

Arithmetic

/ %

Assignment

= += -= *= /= %=

Comparison

== !=

<

= <=

Logical

&& || !

Increment

++

Decrement

--


TYPE CASTING

Recommended

static_cast(x)

Old

(double)x


TYPE CONVERSION

Implicit

int β†’ double

Explicit

static_cast(5.8)


IF STATEMENT

if(condition) { }


IF ELSE

if(condition) {

} else {

}


ELSE IF

if() {

} else if() {

} else {

}


SWITCH

switch(choice) { case 1: break;

case 2: break;

default: }


LOOPS

For

for(int i=0;i<5;i++) { }

While

while(condition) { }

Do While

do {

} while(condition);


BREAK

Stops a loop.


CONTINUE

Skips current iteration.


FUNCTIONS

Declaration

void greet();

Definition

void greet() { }

Calling

greet();


FUNCTION PARAMETERS

void add(int a, int b)

Arguments

add(5,3);


RETURN

int add(int a,int b) { return a+b; }


FUNCTION OVERLOADING

int add(int a,int b)

double add(double a,double b)

Same name. Different parameters.


DEFAULT PARAMETERS

void greet(string name="User")


VARIABLE SCOPE

Local

Inside function.

Global

Outside all functions.


ARRAYS

int nums[5];

Initialization

int nums[]={1,2,3};

Access

nums[0]


MULTI-DIMENSIONAL ARRAY

int matrix[3][3];


STRINGS

std::string name;

Length

name.length()

Size

name.size()

Empty

name.empty()

Append

name += "Hello";

Clear

name.clear();


CHARACTER FUNCTIONS

toupper()

tolower()

isdigit()

isalpha()


REFERENCES

int x=5;

int& ref=x;


POINTERS

int x=5;

int* ptr=&x;

Address

&x

Value

*ptr


DYNAMIC MEMORY

Allocate

new

Delete

delete


ENUM

enum Color { RED, GREEN, BLUE };


STRUCT

struct Student { string name; int age; };


CLASS

class Car { public:

private:

};


OBJECT

Car bmw;


CONSTRUCTOR

Car() {

}

Runs automatically when object is created.


DESTRUCTOR

~Car() {

}

Runs automatically when object is destroyed.


ACCESS MODIFIERS

public

private

protected


INHERITANCE

class Dog : public Animal


POLYMORPHISM

Function Overloading

Function Overriding

Virtual Functions


ENCAPSULATION

Hiding internal data.


ABSTRACTION

Showing only important information.


FILE HANDLING

ofstream

ifstream

fstream


EXCEPTIONS

try

catch

throw


STL (Standard Template Library)

vector

map

set

queue

stack

pair

algorithm


USEFUL HEADER FILES


COMMON MATH FUNCTIONS

sqrt()

pow()

abs()

round()

floor()

ceil()


COMMON STRING FUNCTIONS

length()

size()

substr()

find()

replace()

erase()

insert()

compare()


BEST PRACTICES

β€’ Prefer std::string over char arrays. β€’ Prefer '\n' over std::endl unless flushing is needed. β€’ Use const whenever possible. β€’ Prefer static_cast over C-style casts. β€’ Give variables meaningful names. β€’ Keep functions small. β€’ Don't use global variables unless necessary. β€’ Comment why, not what. β€’ Initialize variables. β€’ Format your code consistently.

⭐ Support

If you find this repository helpful, consider giving it a star.

About

πŸ“˜ Learn C++ through practical programs, examples, and projects. Covers everything from basic syntax to advanced programming concepts.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages