Object Oriented Programming (OOP) in C++

#include<iostream>

using namespace std;

class AbstractEmployee
{
	virtual void AskForPromotion() = 0;
};
 
class Employee:AbstractEmployee
{
private:

	string Company;
	int Age;
	
protected:
	string Name;
	
public:	
	void setName(string name)
	{
		Name = name;
	}
	string getName()
	{
		return Name;
	}
	
	void setCompany(string company)
	{
		Company = company;
	}
	string getCompany()
	{
		return Company;
	}
	
	void setAge(int age)
	{
		if(age >= 18)  
		Age = age;
	}
	int getAge()
	{
		return Age;
	}
	void IntroduceYourself()
	{
		cout << "Name - " << Name << endl;
		cout << "Company - " << Company << endl;
		cout << "Age - " << Age << endl; 
	}	
	Employee(string name, string company, int age)
	{
		Name = name;
		Company = company;
		Age = age;
	}
	
	void AskForPromotion()
	{
		if(Age > 30)
			cout << Name << " got promoted!" << endl;
		else
			cout << Name << ", sorry NO promotion for you!" << endl;
	}
	
	virtual void Work()
	{
		cout << Name << " is checking email, task backlog, performing task..." << endl;
	}
};

class Developer:public Employee
{
public:
	string FavProgrammingLanguage;
	Developer(string name, string company, int age, string favProgrammingLanguage)
		:Employee(name, company, age)
	{
		FavProgrammingLanguage = favProgrammingLanguage;
	}
	void FixBug()
	{
		cout << Name << " fixed bug using " << FavProgrammingLanguage << endl;
	}
	
	void Work()
	{
		cout << Name << " is writing " << FavProgrammingLanguage << " code" << endl;
	}
};

class Teacher:public Employee
{
public:	
	string Subject;
	void PrepareLesson()
	{
		cout << Name << " is preparing " << Subject << " lesson" << endl;
	}
		
	Teacher(string name, string company, int age, string subject)
		:Employee(name, company, age)
	{
		Subject = subject;
	}
	
	void Work()
	{
		cout << Name << " is teaching " << Subject  << endl;
	}	
};

int main()
{
	Developer d = Developer("Saldina", "YT-CodeBeauty", 25, "C++");
	Teacher t = Teacher("Jack", "Cool School", 35, "History");
	
	Employee* e1 = &d;
	Employee* e2 = &t;
	
	e1->Work();
	e2->Work();
	
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值