I have written a pretty small program where you type in whether you are a boy or a girl and it prints out a statement. My main question is that from my code is there any easier way of writing for the women beside copying and pasting from the base class. Here is my code
#include <iostream>
#include <string>
class Man{
protected:
std::string name;
public:
void getInfo(std::string hName){
name = hName;
}
void showInfo(){
std::cout << "Your name is: " << name << std::endl;
std::cout << "And you are a MAN" << std::endl;
}
};
class Women{ //is there an easier way to write this
protected:
std::string fem_name;
public:
void getfemInfo(std::string fhName){
fem_name = fhName;
}
void showfemaleInfo(){
std::cout << "Your name is: " << fem_name << std::endl;
std::cout << "And you are a Women" << std::endl;
}
};
class Human:public Man, public Women{
public:
Human(){}
};
int main(){
//local variables
std::string choice;
std::string tName;
//declaring objects
Human person;
//user interface
std::cout << "Please enter you name: ";
std::cin >> tName;
std::cout << "Are you a [boy/girl]: ";
std::cin >> choice;
//if handler
if (choice == "boy"){
person.getInfo(tName);
person.showInfo();
}else if(choice == "girl"){
person.getfemInfo(tName);
person.showfemaleInfo();
}
system("pause");
return 0;
}
When I try to derive class Woman
from class Man
, it makes person.getInfo(tName)
and person.showInfo()
ambiguous. Why is that? And how can I make this code smaller (for the women).