0% found this document useful (0 votes)
0 views

cpp

This document provides a comprehensive overview of C++ programming and Object-Oriented Programming (OOP) concepts, including basic program structure, data types, conditional statements, loops, functions, classes, and inheritance. It outlines the four pillars of OOP: encapsulation, abstraction, inheritance, and polymorphism, along with examples for each concept. Additionally, it covers file handling basics in C++.

Uploaded by

zohaib962442
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

cpp

This document provides a comprehensive overview of C++ programming and Object-Oriented Programming (OOP) concepts, including basic program structure, data types, conditional statements, loops, functions, classes, and inheritance. It outlines the four pillars of OOP: encapsulation, abstraction, inheritance, and polymorphism, along with examples for each concept. Additionally, it covers file handling basics in C++.

Uploaded by

zohaib962442
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

‭C++ & OOP Revision Notes‬

📘
‭ For Quick PDF Conversion‬
‭✍️Prepared by: ChatGPT Bhai‬

‭1. Basic Structure of C++ Program‬


‭ pp‬
c
‭CopyEdit‬
#include <iostream>‬

using namespace std;‬

int main() {‬

cout << "Hello, World!";‬

return 0;‬

}‬

📝
‭ Output:‬
‭Hello, World!‬

‭2. Variables & Data Types‬


‭ pp‬
c
‭CopyEdit‬
int age = 20;‬

float marks = 88.5;‬

char grade = 'A';‬

‭ Tip:‬
‭int → whole numbers‬
‭float → decimal‬
‭char → single character‬
‭3. Conditional Statements (if-else)‬
‭ pp‬
c
‭CopyEdit‬
int age = 18;‬

if (age >= 18) {‬

cout << "You can vote.";‬

} else {‬

cout << "You are underage.";‬

}‬

📝
‭ Output:‬
‭You can vote.‬

‭4. Loops (for loop)‬


‭ pp‬
c
‭CopyEdit‬
for (int i = 1; i <= 5; i++) {‬

cout << i << " ";‬

}‬

📝
‭ Output:‬
‭1 2 3 4 5‬

‭5. Functions‬
‭ pp‬
c
‭CopyEdit‬
int add(int a, int b) {‬

return a + b;‬

}‬

int main() {‬

cout << add(5, 3);‬

}‬

📝
‭ Output:‬
‭8‬

‭6. Object-Oriented Programming (OOP) Concepts‬


‭🎯 4 Pillars of OOP:‬

‭1.‬ ‭Encapsulation‬

‭2.‬ ‭Abstraction‬

‭3.‬ ‭Inheritance‬

‭4.‬ ‭Polymorphism‬

‭7. Classes and Objects‬


‭ pp‬
c
‭CopyEdit‬
class Student {‬

public:‬

string name;‬

void sayHello() {‬

cout << "Hello, I am " << name;‬

}‬

};‬

int main() {‬

Student s1;‬

s1.name = "Ali";‬

s1.sayHello();‬

}‬

📝
‭ Output:‬
‭Hello, I am Ali‬
‭8. Constructors‬
‭ pp‬
c
‭CopyEdit‬
class Student {‬

public:‬

Student() {‬

cout << "Constructor called!";‬

}‬

};‬

int main() {‬

Student s1;‬

}‬

📝
‭ Output:‬
‭Constructor called!‬

‭9. Inheritance‬
‭ pp‬
c
‭CopyEdit‬
class Animal {‬

public:‬

void sound() {‬

cout << "Animal sound";‬

}‬

};‬

class Dog : public Animal {};‬


int main() {‬

Dog d;‬

d.sound();‬

}‬

📝
‭ Output:‬
‭Animal sound‬

‭10. Polymorphism (Function Overloading)‬


‭ pp‬
c
‭CopyEdit‬
class Print {‬

public:‬

void show(int a) {‬

cout << "Integer: " << a;‬

}‬

void show(string b) {‬

cout << "String: " << b;‬

}‬

};‬

int main() {‬

Print obj;‬

obj.show("Hello");‬

}‬

📝
‭ Output:‬
‭String: Hello‬

‭11. Encapsulation‬
‭➡ Hiding data using private access modifier‬

‭ pp‬
c
‭CopyEdit‬
class Bank {‬

private:‬

int balance = 1000;‬

public:‬

int getBalance() {‬

return balance;‬

}‬

};‬

‭12. File Handling (Basics)‬


‭ pp‬
c
‭CopyEdit‬
#include <fstream>‬

using namespace std;‬

int main() {‬

ofstream myFile("data.txt");‬

myFile << "Hello File!";‬

myFile.close();‬

}‬

‭📁 Creates a file and writes text into it.‬

You might also like