This course will teach you how to use the principles of OOP to develop efficient and scalable C++ programs. You will learn how to design classes and objects, use inheritance and polymorphism to create flexible systems, and how to overload operators to improve code readability. In addition, the course will cover the use of pointers and the Standard Template Library (STL) to help you work with data collections and improve program performance.
Course Topics:
Classes and Objects
- Classes: How to create and define classes in C++, using the constructor and destructor to initialize and clean up objects.
- Objects: Creating instances of classes and working with them.
Example:
Class Car {
public:
string model;
int year;
// Class constructor
Car(string m, int y) {
model = m;
year = y;
}
void displayInfo() {
cout << “Model: ‘ << model << ’, Year: ” << year << year << endl;
}
};
int main() {
Car myCar(“Toyota”, 2020);
myCar.displayInfo();
return 0;
}
Inheritance and polymorphism
- Inheritance: Creating new classes based on existing classes (derived classes).
- Polymorphism: Using virtual functions to implement dynamic binding, allowing child classes to override methods of parent classes.
Example:
Class Animal {
Public:
virtual void sound() { cout << “Some sound” << endl; }
};
class Dog : public Animal {
Public:
void sound() override { cout << “Bark” << endl; }
};
int main() {
Animal* animal = new Dog();
animal->sound(); // Output “Bark” (dynamic binding)
delete animal;
return 0;
}
Operator overloading
Use operator overloading to create more intuitive classes. For example, overloading the + operator to add two objects.
Example:
class Point {
Public:
int x, y;
Point(int a, int b) : x(a), y(b) {}
// Overload operator +
Point operator+(const Point& other) {
return Point(x + other.x, y + other.y);
}
};
int main() {
Point p1(1, 2), p2(3, 4);
Point p3 = p1 + p2; // Overloaded operator + is used
cout << “Sum of points: (” << p3.x << ”, ‘ << p3.y << ’)” << endl;
return 0;
}
Working with pointers
- How to use pointers to work with dynamic memory.
- Advantages and risks of working with pointers: working with arrays, passing objects by reference and pointers, dynamic memory allocation.
Example:
int main() {
int* ptr = new int(10); // Memory allocation
cout << “Value: ” << *ptr << endl; // Pointer dereferencing
delete ptr; // Memory freeing
return 0;
}
Standard Template Library (STL)
- Exploring standard containers and algorithms in C++ for working with data collections.
- Introduction to containers such as vectors (vector), sets (set), lists (list), maps (map).
Example:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> numbers = {1, 2, 3, 4, 5};
for (int num : numbers) {
cout << num << “ ”;
}
cout << endl;
return 0;
}
What you will get after completing the course:
- Ability to work with classes and objects, design data structures using OOP.
- A deep understanding of inheritance and polymorphism, which allow you to create flexible and extensible programs.
- Skills in operator overloading to improve code readability and functionality.
- Experience with pointers and dynamic memory allocation.
- Knowledge of using STL to work efficiently with data in real projects.
Course fee: 250 $.