Using classes : The building block

You will store the caracteristics of the objects that are relevant to your program

<aside> 💡 Everything inside a class is private by default

</aside>

Acces modifiers :

Everything inside a class is private by default

Behaviour : using class method

User-defined data types :

#include<iostream>
using namespace std;
    class Employee{
    public:
    string name;
    string company;
    int age;
    void introduceyourself(){
        cout<<"Name: "<<name<<endl;
        cout<<"Company: "<<company<<endl;
        cout<<"Age: "<<age<<endl;

    }

};
int main(){
    Employee emp;
    emp.name = "john";
    emp.company = "company";
    emp.age = 20;
emp.introduceyourself();
    return 0;

}

Constructors :

a constructor will not have a return type

constructor has the same name as the class

constructor must be public (not always but most of the time )

Encapsulation :

abstraction :

We will create a class called : abstract employee that has a function called ask for promotion

we will later define the function ask for promotion in the employee section of the codde

Class abstract_employee (){
void askforpromotion ();
}
class employee:abstract_employee{

	void askforpromotion (){

		if (age <20) { 
			std::cout<<name<<"you've been promoted";
 
		}
}

Inheritance

Base class = parent

Child class : will obtain all he members of the parent class

class developer: Employee{
    //developer is a sub-class of the superclass Employee
    //ddeveloper has all of the properties that emplloyee class has
    public:
    string FavProgrammingLanguage;
    // you have to create a default constructor 
    //Employee already has a constructor, we jsut need to derive the properties for the developere
    developer(string Name, string Company, int age, string favProgrammingLanguage){}
    //The constructor already knows how to constcut name company and age.
    //we can use:
    developer(string Name, string Company, int age, string favProgrammingLanguage): Employee(name, company, age, favProgrammingLanguage)
    {
        FavProgrammingLanguage = favProgrammingLanguage;
    }

<aside> 💡 To access the Property 'Name' from Employee class you need to use the getters : getName Or use the desired property as a Protected property in the base class

</aside>

<aside> 💡 Same thing for functions : The child class cannot use the functions of the base class. USe the following trick to rmodify it :

</aside>

class developer:public Employee{
public :
	string FAvprogramming language etc........