-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
89 lines (75 loc) · 2.09 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/// Problem 13 on page 891 (Problem Solving)
/// Course: CS213 - Programming II - 2018
/// Title: Assignment 2 - Indivindual Task
/// Program: CS213-2018-A2
/// Author: Ahmed Sayed Mansour 20170022
/// Date: 10 August 2018
/// last edit : 23/10/2018
/// Version: 1.0
#include <bits/stdc++.h>
using namespace std;
//A child class Pet (Base class) that includes the name an d details of the animal
//Including functions to set and get some information and pure virtual function to print inf
class Pet
{
private:
string name;
bool neuterSpayed=false;
bool talks=false;
public:
void setname(string a){ name =a ;}
void setneeu(bool a){neuterSpayed=a;}
void settalks(bool a){talks = a;}
string getname(){return name;}
bool getneu(){return neuterSpayed;}
bool gettalks(){return talks;}
virtual void printDescription()=0;
};
//An inherited class Dog from Per that includes inf of Dog
class Dog :public Pet
{
public:
void printDescription(){
cout << "Dog named " << getname() << endl;
cout << "Neuter/Spayed: " <<getneu();
}
};
//An inherited class Cat from Per that includes inf of Cat
class Cat :public Pet
{
public:
void printDescription(){
cout << "Cat named " << getname() << endl;
cout << "Neuter/Spayed: " <<getneu();
}
};
//An inherited class Bird from Per that includes inf of Bird
class Bird :public Pet
{
public:
void printDescription(){
cout << "Bird named " << getname() << endl;
cout << "Talks: " << gettalks() << endl;
}
};
int main()
{
// A vector to store classes
vector <Pet*> vec;
vec.push_back(new Dog);
vec[0]->setname("Boby");
vec[0]->settalks(1);
vec.push_back(new Cat);
vec[1]->setname("Caty");
vec[1]->settalks(0);
vec.push_back(new Bird);
vec[2]->setname("Birdy");
vec[2]->settalks(1);
//A for loop to print all inf of animals
for (int i=0;i<3;++i){
cout<<endl;
vec[i]->printDescription();
cout<<endl;
}
return 0;
}