3 Month Complete Thyroid Reversal Plan

C++ Basics for Beginners

🌟 C++ Basics β€” A Beginner Friendly Guide

Welcome student! Let’s understand C++ step-by-step in a simple and engaging way.

πŸ”₯ Difference Between C and C++

  • C β†’ Procedural Programming (focus on functions).
  • C++ β†’ Object-Oriented Programming (focus on objects & classes).
  • C does not support classes; C++ supports classes, objects, inheritance, polymorphism.
  • C uses stdio.h; C++ uses iostream.
  • C++ supports function overloading, operator overloading, templates, exceptions.

πŸ“š Basic C++ Library: <iostream>

To take input or print output, C++ uses the library:

#include <iostream> using namespace std;
  • <iostream> β†’ Handles input/output streams.
  • cin β†’ Used for input from keyboard.
  • cout β†’ Used for displaying output to screen.

⌨️ Syntax of cin and cout

πŸ‘‰ Output (cout)

cout << "Hello Students!";

πŸ‘‰ Input (cin)

int age; cin >> age;

<< insertion operator (send data to output stream)
>> extraction operator (read data from input stream)

πŸ—οΈ Basic Structure of a C++ Program

#include <iostream> // Header file using namespace std; // To avoid writing std::cout int main() // Main function { cout << "Welcome to C++"; // Statement return 0; // Ends program }

πŸ” Explanation of Each Section

  • #include <iostream> β†’ Loads input/output functions.
  • using namespace std; β†’ Allows direct use of cout/cin.
  • int main() β†’ Program starts executing from here.
  • { } β†’ Body of the main function.
  • cout β†’ Prints text.
  • return 0; β†’ Indicates successful program termination.
Top 5 C++ Header Files

🌟 Top 5 Header Files in C++ & Their Inbuilt Functions

These are the most commonly used and most important header files for beginners and intermediate level students.

1️⃣ <iostream> β€” Input/Output Stream

This header file is used for taking input and printing output.

πŸ”₯ Important Inbuilt Functions:

  • cout β†’ For output
  • cin β†’ For input
  • getline() β†’ Reads full string including spaces
#include <iostream> using namespace std; int main() { string name; getline(cin, name); cout << "Welcome: " << name; }

2️⃣ <cmath> β€” Math Functions

Used for mathematical operations.

πŸ”₯ Important Inbuilt Functions:

  • sqrt(n) β†’ Square root
  • pow(a, b) β†’ a raised to power b
  • abs(x) β†’ Absolute value
  • ceil(x) β†’ Round upward
  • floor(x) β†’ Round downward
#include <cmath> int x = sqrt(49); // 7 int y = pow(2, 5); // 32 int z = abs(-8); // 8

3️⃣ <string> β€” String Handling

Used to work with strings easily.

πŸ”₯ Important Inbuilt Functions:

  • length() β†’ Returns size of string
  • substr(a, b) β†’ Extract substring
  • append() β†’ Append string at end
  • compare() β†’ Compare two strings
#include <string> string s = "Swapnil"; int len = s.length(); // 7 string part = s.substr(0,3); // Swa

4️⃣ <cctype> β€” Character Handling

Used to test and convert characters.

πŸ”₯ Important Inbuilt Functions:

  • toupper(ch) β†’ Convert to uppercase
  • tolower(ch) β†’ Convert to lowercase
  • isdigit(ch) β†’ Check if digit
  • isalpha(ch) β†’ Check alphabet
#include <cctype> char x = 'a'; char y = toupper(x); // A

5️⃣ <vector> β€” Dynamic Arrays

Vector is one of the most powerful containers in C++.

πŸ”₯ Important Inbuilt Functions:

  • push_back() β†’ Add element
  • pop_back() β†’ Remove last element
  • size() β†’ Returns number of elements
  • front() β†’ First element
  • back() β†’ Last element
#include <vector> vector<int> v; v.push_back(10); v.push_back(20); int n = v.size(); // 2
C++ Class - Complete Notes

🌟 C++ Class β€” Complete Beginner Friendly Notes

Classes are the heart of Object-Oriented Programming in C++. Let's understand them in the easiest way possible.

πŸ“Œ What is a Class?

A class is a user-defined blueprint or template from which objects are created.

It contains:

  • Data Members β†’ Variables that store data
  • Member Functions β†’ Functions that operate on data

πŸ‘‰ Think of a class as a β€œdesign” and an object as the β€œactual product”.

πŸ“Œ Syntax of a Class

class ClassName { public: // data members // member functions private: // data members // member functions };

βœ” Ending semicolon ; is compulsory after class definition.

πŸ” Access Specifiers in C++

Access specifiers control where class members can be accessed.

1️⃣ public

Members are accessible anywhere in the program.

2️⃣ private

Members can be accessed only inside the class (default mode).

3️⃣ protected

Accessible inside class + child class (inheritance), but not outside.

class Demo { public: int a; // accessible anywhere private: int b; // only inside class protected: int c; // inside class + inherited class };

πŸ“Œ Creating an Object

Object is an instance of the class.

ClassName objectName; // Syntax
Example:
Demo d1; // d1 is an object of class Demo

🌟 Complete Basic Example of a Class

#include <iostream> using namespace std; class Student { public: string name; int age; float marks; void input() { cout << "Enter Name: "; cin >> name; cout << "Enter Age: "; cin >> age; cout << "Enter Marks: "; cin >> marks; } void display() { cout << "\n--- Student Details ---\n"; cout << "Name: " << name << endl; cout << "Age: " << age << endl; cout << "Marks: " << marks << endl; } }; int main() { Student s1; // Object Creation s1.input(); // Calling function s1.display(); // Calling function return 0; }

🧐 Explanation of Above Example

  • class Student β†’ Creates a blueprint for students
  • name, age, marks β†’ Data members
  • input() β†’ Takes input from user
  • display() β†’ Shows student details
  • Student s1; β†’ Creates an object
  • s1.input() β†’ Accesses public function

πŸ’Ύ Memory Concept (Easy Explanation)

  • Class itself consumes **0 memory**.
  • Memory is allocated **only when an object is created**.
  • Each object gets a separate copy of data members.

Example:

Student s1; // memory allocated for name, age, marks Student s2; // separate memory allocated
C++ Access Specifiers & Inheritance Syntax

🌟 C++ Access Specifiers + Inheritance Syntax (Full Notes)

This note explains access levels and how they behave in inheritance in a simple, student-friendly way.

πŸ” What Are Access Specifiers?

Access specifiers decide whether class members (variables/functions) are:

  • βœ” Accessible inside the class
  • βœ” Accessible in derived class
  • βœ” Accessible outside the class (object)

There are 3 access specifiers:

  • public
  • private
  • protected

πŸ“Œ Access Specifier Matrix (VERY IMPORTANT)

Access Specifier Inside Same Class Inside Derived Class Outside Class (Object)
public βœ” Accessible βœ” Accessible βœ” Accessible
private βœ” Accessible ❌ Not Accessible ❌ Not Accessible
protected βœ” Accessible βœ” Accessible ❌ Not Accessible

πŸ“Œ Access after Inheritance (MOST IMPORTANT TABLE)

When a derived class inherits a base class, the access of members may change depending on inheritance mode.

Original Access Public Inheritance Protected Inheritance Private Inheritance
public public protected private
protected protected protected private
private not inherited not inherited not inherited

Note: Private members of base class are never inherited. Only public/protected members get inherited.

πŸ“Œ Syntax of Deriving a Child Class

πŸ‘‰ General Syntax

class ChildClass : access_specifier ParentClass { // body of derived class };

access_specifier can be:

  • public
  • private
  • protected

1️⃣ Public Inheritance (MOST COMMON)

Public members β†’ remain public Protected members β†’ remain protected

class Child : public Parent { };

2️⃣ Protected Inheritance

Public + Protected β†’ become protected in derived class.

class Child : protected Parent { };

3️⃣ Private Inheritance

Public + Protected β†’ become private in derived class.

class Child : private Parent { };

🌟 Full Example of Inheritance with Access Specifiers

#include <iostream> using namespace std; class Parent { public: int a = 10; protected: int b = 20; private: int c = 30; }; class Child : public Parent { public: void show() { cout << a; // βœ” allowed (public) cout << b; // βœ” allowed (protected) // cout << c; // ❌ not allowed (private) } }; int main() { Child obj; cout << obj.a; // βœ” allowed // cout << obj.b; // ❌ not allowed // cout << obj.c; // ❌ not allowed return 0; }
Scroll to Top