---
- C++, Bjarne Stroustrup tarafından 1980’lerde C dili üzerine geliştirilmiş bir programlama dilidir.
- C’nin hızını korurken, Nesne Yönelimli Programlama (OOP) özellikleri eklenmiştir.
- Sistem yazılımı, oyun motorları, yapay zeka, yüksek performanslı uygulamalarda sıkça kullanılır.
#include <iostream>
using namespace std;
int main() {
cout << "Merhaba C++ 🚀" << endl;
return 0;
}
📌 Açıklama:
#include <iostream>
→ giriş/çıkış kütüphanesini ekler.cout
→ ekrana yazdırır.endl
→ yeni satır ekler.
int sayi = 10; // Tam sayı
float pi = 3.14; // Ondalık sayı
double buyukPi = 3.14159; // Daha hassas ondalık
char harf = 'A'; // Tek karakter
string isim = "Ebrar"; // Metin
bool dogruMu = true; // Mantıksal değer
int a = 5, b = 2;
cout << a + b << endl; // Toplama
cout << a - b << endl; // Çıkarma
cout << a * b << endl; // Çarpma
cout << a / b << endl; // Bölme
cout << a % b << endl; // Mod
int yas = 18;
if (yas >= 18) {
cout << "Reşitsiniz ✅" << endl;
} else {
cout << "Reşit değilsiniz ❌" << endl;
}
int gun = 3;
switch (gun) {
case 1: cout << "Pazartesi" << endl; break;
case 2: cout << "Salı" << endl; break;
case 3: cout << "Çarşamba" << endl; break;
default: cout << "Bilinmiyor" << endl;
}
for (int i = 1; i <= 5; i++) {
cout << i << endl;
}
int sayac = 0;
while (sayac < 3) {
cout << "Sayaç: " << sayac << endl;
sayac++;
}
#include <iostream>
using namespace std;
int kare(int x) {
return x * x;
}
int main() {
cout << kare(5) << endl;
return 0;
}
#include <iostream>
using namespace std;
class Ogrenci {
public:
string isim;
int yas;
void bilgi() {
cout << "Ad: " << isim << ", Yas: " << yas << endl;
}
};
int main() {
Ogrenci ogr;
ogr.isim = "Ebrar";
ogr.yas = 20;
ogr.bilgi();
return 0;
}
int sayilar[5] = {1, 2, 3, 4, 5};
for (int i = 0; i < 5; i++) {
cout << sayilar[i] << endl;
}
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<string> meyveler = {"Elma", "Armut", "Muz"};
for (string meyve : meyveler) {
cout << meyve << endl;
}
return 0;
}
✔️ using namespace std;
→ kolaylık sağlar ama büyük projelerde dikkatli kullan.
✔️ Bellek yönetimini öğren (new
, delete
).
✔️ Modern C++ ile std::vector
, std::string
gibi STL (Standard Template Library) yapıları kullan.
❌ Çiğ işaretçiler (raw pointer
) → başlangıç için kafa karıştırabilir.
- Kullanıcıdan 2 sayı al → toplamasını, çıkarmasını, çarpmasını ve bölmesini ekrana yazdır.
- 1’den 100’e kadar olan sayıların toplamını bulan program yaz.
- Bir
Araba
sınıfı oluştur → markası ve modeli olsun, nesne üzerinden ekrana yazdır. - Bir vektör oluştur (
int
tipinde) → eleman ekle, sil, yazdır.
C++ dili, hem sistem programlamada hem de yüksek seviyeli uygulamalarda kullanılabilen güçlü bir dildir.
OOP (Sınıflar, Kalıtım, Polimorfizm) özellikleri sayesinde büyük projelerde tercih edilir.
Kısacası: C’nin gücü + OOP = C++ 🚀
- C++ is a programming language developed by Bjarne Stroustrup based on the C language in the 1980s.
- While maintaining the speed of C, it adds Object-Oriented Programming (OOP) features.
- It is frequently used in system software, game engines, artificial intelligence, and high-performance applications.
#include <iostream>
using namespace std;
int main() {
cout << "Hello C++ 🚀" << endl;
return 0;
}
📌 Description:
#include <iostream>
→ adds the input/output library.cout
→ prints to the screen.endl
→ adds a new line.
int number = 10; // Integer
float pi = 3.14; // Decimal number
double bigPi = 3.14159; // More precise decimal
char letter = 'A'; // Single character
string name = "Ebrar"; // Text
bool true = true; // Logical value
int a = 5, b = 2;
cout << a + b << endl; // Addition
cout << a - b << endl; // Subtraction
cout << a * b << endl; // Multiplication
cout << a / b << endl; // Division
cout << a % b << endl; // Mode
int age = 18;
if (age >= 18) {
cout << "You are a minor ✅" << endl;
} else {
cout << "You are a minor ❌" << endl;
}
int day = 3;
switch (day) {
case 1: cout << "Monday" << endl; break;
case 2: cout << "Tuesday" << endl; break;
case 3: cout << "Wednesday" << endl; break;
default: cout << "Unknown" << endl;
}
for (int i = 1; i <= 5; i++) {
cout << i << endl;
}
int counter = 0;
while (counter < 3) {
cout << "Counter: " << counter << endl;
counter++;
}
#include <iostream>
using namespace std;
int square(int x) {
return x * x;
}
int main() {
cout << square(5) << endl;
return 0;
}
#include <iostream>
using namespace std;
class Student {
public:
string name;
int age;
void info() {
cout << "Name: " << name << ", Age: " << age << endl;
}
};
int main() {
Student student;
student.name = "Ebrar";
student.age = 20;
student.info();
return 0;
}
int numbers[5] = {1, 2, 3, 4, 5};
for (int i = 0; i < 5; i++) {
cout << numbers[i] << endl;
}
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<string> fruits = {"Apple", "Pear", "Banana"};
for (string fruit : fruits) {
cout << fruit << endl;
}
return 0;
}
✔️ using namespace std;
→ is convenient, but use it carefully in large projects.
✔️ Learn memory management (new
, delete
).
✔️ Use STL (Standard Template Library) structures like std::vector
and std::string
with modern C++.
❌ Raw pointers → can be confusing at first.
- Receive 2 numbers from the user → print their addition, subtraction, multiplication, and division.
- Write a program that finds the sum of numbers from 1 to 100.
- Create a
Car
class → print the make and model from the object. - Create a vector (of type
int
) → add, delete, and print elements.
C++ is a powerful language that can be used in both system programming and high-level applications. Its OOP (Classes, Inheritance, Polymorphism) features make it a popular choice for large projects. In short: The Power of C + OOP = C++ 🚀