Example 1 : The class "colony" models an insect colony. The program decides which insect colony is larger ... #include #include using namespace std; class colony{ private : int initial; float r1; float r2; public : colony() {initial=0; r1=0; r2=0;} colony(int init, float a, float b) {initial = init; r1=a; r2=b;} void set(int i, float a, float b) {initial = i; r1=a; r2=b;} void get_data(); int get_size(int n); }; void colony :: get_data() { cout << "What is the initial population ?\n"; cin >> initial; cout << "Input the rates of growth \n"; cin >> r1 >> r2; } int colony :: get_size(int n) { float size = initial; for(int a=0; a> n; if (ants.get_size(n) > termites.get_size(n)) cout << "More ants than termites \n"; else cout << "More termites than ants \n"; return 0; } Example 2 : Complex numbers ... Only complex addition has been implemented. #include #include using namespace std; class complex{ private : float x,y; public: complex() {x=0;y=0;} complex(float a) {x=a;y=0;} complex(float a, float b) {x=a;y=b;} float real_part() { return x;} float imaginary_part() {return y;} void display(); void set(float a) {x=a;y=0;} void set(float a, float b) {x=a;y=b;} void get(); }; void complex :: display(){ cout <<"(" << x << ") + i(" << y << ")\n"; } void complex :: get() { float x,y; cout << "Input real part \n"; cin >> x; cout << "Input imaginary part \n"; cin >> y; set(x,y); } complex sum(complex z1, complex z2) { complex s; float x,y; x = z1.real_part() + z2.real_part(); y = z1.imaginary_part() + z2.imaginary_part(); s.set(x,y); return s; } int main() { complex z1, z2, z3; cout << "Input the first complex number \n"; z1.get(); cout << "Input the second complex number \n"; z2.get(); z3 = sum(z1, z2); cout << "The sum is \n"; z3.display(); return 0; }