Skip to content

Commit fc9dcee

Browse files
Add files via upload
1 parent 62c0675 commit fc9dcee

6 files changed

+472
-0
lines changed

Abstraction.cpp

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
// abstract class
5+
class AbstractEmployee {
6+
virtual void askForPromotion()=0;
7+
};
8+
9+
class Employee: AbstractEmployee{
10+
private:
11+
string Name;
12+
string Company;
13+
int Age;
14+
15+
public:
16+
// Constructor
17+
Employee(string name, string company, int age) {
18+
Name = name;
19+
Company = company;
20+
Age = age;
21+
}
22+
23+
// Setter for Name
24+
void setName(string name) {
25+
Name = name;
26+
}
27+
28+
// Getter for Name
29+
string getName() {
30+
return Name;
31+
}
32+
33+
// Setter for Company
34+
void setCompany(string company) {
35+
Company = company;
36+
}
37+
38+
// Getter for Company
39+
string getCompany() {
40+
return Company;
41+
}
42+
43+
// Setter for Age
44+
void setAge(int age) {
45+
if(age<=18)
46+
Age = age;
47+
}
48+
49+
// Getter for Age
50+
int getAge() {
51+
return Age;
52+
}
53+
54+
// Method to introduce yourself
55+
void introduceYourself() {
56+
cout << "Name: " << Name << endl;
57+
cout << "Company: " << Company << endl;
58+
cout << "Age: " << Age << endl;
59+
}
60+
61+
void askForPromotion(){
62+
if(Age>30)
63+
cout << Name << " got promoted!" << endl;
64+
else
65+
cout << "Sorry, No promotion for you!"<< endl;
66+
}
67+
};
68+
69+
int main() {
70+
// Create Employee objects using the constructor
71+
Employee employee1 = Employee("Faraz Mirza", "Google", 40);
72+
Employee employee2 = Employee("Joseph Joestar", "Speedwagon Foundation", 25);
73+
74+
employee1.askForPromotion();
75+
employee2.askForPromotion();
76+
77+
78+
return 0;
79+
}

Encapsulation.cpp

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
class Employee {
5+
private:
6+
string Name;
7+
string Company;
8+
int Age;
9+
10+
public:
11+
// Constructor
12+
Employee(string name, string company, int age) {
13+
Name = name;
14+
Company = company;
15+
Age = age;
16+
}
17+
18+
// Setter for Name
19+
void setName(string name) {
20+
Name = name;
21+
}
22+
23+
// Getter for Name
24+
string getName() {
25+
return Name;
26+
}
27+
28+
// Setter for Company
29+
void setCompany(string company) {
30+
Company = company;
31+
}
32+
33+
// Getter for Company
34+
string getCompany() {
35+
return Company;
36+
}
37+
38+
// Setter for Age
39+
void setAge(int age) {
40+
if(age<=18)
41+
Age = age;
42+
}
43+
44+
// Getter for Age
45+
int getAge() {
46+
return Age;
47+
}
48+
49+
// Method to introduce yourself
50+
void introduceYourself() {
51+
cout << "Name: " << Name << endl;
52+
cout << "Company: " << Company << endl;
53+
cout << "Age: " << Age << endl;
54+
}
55+
};
56+
57+
int main() {
58+
// Create Employee objects using the constructor
59+
Employee employee1 = Employee("Faraz Mirza", "Google", 21);
60+
employee1.introduceYourself();
61+
62+
Employee employee2 = Employee("Joseph Joestar", "Speedwagon Foundation", 25);
63+
employee2.introduceYourself();
64+
65+
// Set and get age
66+
employee1.setAge(15);
67+
cout << employee1.getName() << " is " << employee1.getAge() << " years old" << endl;
68+
69+
return 0;
70+
}

Inheritance.cpp

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
// abstract class
5+
class AbstractEmployee {
6+
virtual void askForPromotion()=0;
7+
};
8+
9+
class Employee: AbstractEmployee{
10+
private:
11+
string Company;
12+
int Age;
13+
14+
protected:
15+
string Name;
16+
17+
public:
18+
// Constructor
19+
Employee(string name, string company, int age) {
20+
Name = name;
21+
Company = company;
22+
Age = age;
23+
}
24+
25+
// Setter for Name
26+
void setName(string name) {
27+
Name = name;
28+
}
29+
30+
// Getter for Name
31+
string getName() {
32+
return Name;
33+
}
34+
35+
// Setter for Company
36+
void setCompany(string company) {
37+
Company = company;
38+
}
39+
40+
// Getter for Company
41+
string getCompany() {
42+
return Company;
43+
}
44+
45+
// Setter for Age
46+
void setAge(int age) {
47+
if(age<=18)
48+
Age = age;
49+
}
50+
51+
// Getter for Age
52+
int getAge() {
53+
return Age;
54+
}
55+
56+
// Method to introduce yourself
57+
void introduceYourself() {
58+
cout << "Name: " << Name << endl;
59+
cout << "Company: " << Company << endl;
60+
cout << "Age: " << Age << endl;
61+
}
62+
63+
void askForPromotion(){
64+
if(Age>30)
65+
cout << Name << " got promoted!" << endl;
66+
else
67+
cout << "Sorry, No promotion for you!"<< endl;
68+
}
69+
};
70+
71+
class Developer: public Employee{
72+
public:
73+
string FavProgrammingLanguage;
74+
Developer(string name, string company, int age, string favProgrammingLanguage)
75+
: Employee(name, company, age)
76+
{
77+
FavProgrammingLanguage = favProgrammingLanguage;
78+
}
79+
80+
void fixBug(){
81+
cout << Name << " fixed bug using " << FavProgrammingLanguage << endl;
82+
}
83+
84+
};
85+
86+
class teacher: public Employee{
87+
public:
88+
string Subject;
89+
void prepareLesson()
90+
{
91+
cout << Name << " is preparing " << Subject << " lesson" << endl;
92+
}
93+
94+
teacher(string name, string company, int age, string Subject)
95+
: Employee(name, company, age)
96+
{
97+
this->Subject = Subject;
98+
}
99+
};
100+
101+
// Main function
102+
int main() {
103+
Developer d = Developer("Faraz Mirza", "YouTube", 40, "C++");
104+
teacher t = teacher("Jack","Army Public School",35,"Maths");
105+
t.prepareLesson();
106+
t.askForPromotion();
107+
return 0;
108+
}

Operator_Overloading.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include<iostream>
2+
#include<string>
3+
#include<list>
4+
using namespace std;
5+
6+
struct YouTubeChannel{
7+
string Name;
8+
int SubscribersCount;
9+
10+
YouTubeChannel(string name, int subscribers) {
11+
Name = name;
12+
SubscribersCount = subscribers;
13+
}
14+
15+
bool operator == (const YouTubeChannel& ytChannel) const{
16+
return this->Name == ytChannel.Name;
17+
18+
}
19+
20+
};
21+
22+
ostream& operator<<(ostream& COUT, YouTubeChannel& ytChannel){
23+
COUT<<"Name: "<<ytChannel.Name<<endl;
24+
COUT<<"Subscribers: "<<ytChannel.SubscribersCount<<endl;
25+
return COUT;
26+
}
27+
28+
struct MyCollection{
29+
list<YouTubeChannel> myChannels;
30+
31+
void operator += (YouTubeChannel& channel){
32+
this->myChannels.push_back(channel);
33+
}
34+
35+
void operator -= (YouTubeChannel& channel){
36+
this->myChannels.remove(channel);
37+
}
38+
39+
};
40+
41+
ostream& operator<<(ostream& COUT, MyCollection& myCollection){
42+
for(YouTubeChannel ytChannel: myCollection.myChannels){
43+
COUT<<ytChannel<<endl;
44+
}
45+
return COUT;
46+
}
47+
48+
int main(){
49+
50+
YouTubeChannel yt1= YouTubeChannel("Miraculer 2.0", 13000);
51+
YouTubeChannel yt2= YouTubeChannel("Starburst", 10000);
52+
MyCollection myCollection;
53+
myCollection += yt1;
54+
myCollection += yt2;
55+
myCollection -= yt1;
56+
cout << myCollection;
57+
58+
59+
cin.get();
60+
}

0 commit comments

Comments
 (0)