Click here to Skip to main content
16,019,983 members

Comments by Member 13592359 (Top 1 by date)

Member 13592359 25-Dec-17 4:52am View    
// so far i have done this and everything is ok now i want to Include extraction and insertion operators for breed and eyecolor. Can you please tell me how to do it.
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
class Dog
{
string breed;
string eyeColor;
public:
void extInsrt(int i)
{
cout << "Enter the breed of "<<i+1 <<" no dog: ";
cin >> breed;
cout << "Enter eyecolor of " << i+1 << " no dog: ";
cin >> eyeColor;
}
void showData(int i, Dog obj[4])
{
cout <<i+1<< ". The breed of " << i+1 << " no dog is: " << obj[i].func_breed()<<endl;
cout << " The eyecolor of " << i+1 << " no dog is: " << obj[i].func_eyeColor()<<endl;

}
string func_breed()
{
return breed;

}
string func_eyeColor()
{
return eyeColor;
}
Dog operator* (Dog ob)
{
Dog obj;

if (this->breed == ob.breed)
{
obj.breed = breed;
return obj;
}
else
{
obj.breed = "Mixed";
return obj;
}
}

};



int main()
{
Dog obj[4];
for (int i = 0; i < 4; i++)
{
obj[i].extInsrt(i);
}
for (int i = 0; i < 4; i++)
{
obj[i].showData(i, obj);
}
for (int i = 0; i < 8; i++)
{

int opt1;
int opt2;
int random_Number = rand() % 2;
cout << "Enter the number of two dogs [Example: for 1 no dog, input 1]";
cin >> opt1;
cin >> opt2;
Dog ob;
ob = obj[opt1 - 1] * obj[opt2 - 1];
cout <<"Breed: "<< ob.func_breed() << endl;
if (random_Number == 0)
{
cout <<"Eyecolor: "<< obj[opt1 - 1].func_eyeColor() << endl;
}
else {
cout << "Eyecolor: " << obj[opt2 - 1].func_eyeColor() << endl;
}

}


return 0;

}