Starting with provided code • Add gender to your class – enum class Gender {man, woman, nonbinary}; – Gender gen as one of your data attributes in your class • Overload the operator>> to read in all 3 attributes of the person – read it in as an int (not in the class) – then set the gen data attribute with that int • Add a get_gender method to your class to return a string • Print the string that corresponds to the
Solve this programming question in c++
Use the code provided below to make further changes #include<bits/stdc++.h> using namespace std; class Person { private: string name; int age; public: Person() { this->name=""; this->age=0; } Person(string name,int age) { this->name=name; this->age=age; } public: void set_name(string name) { this->name=name; } void set_age(int age) { this->age=age; } string get_name() { return this->name; } int get_age() { return this->age; } }; //custon compare function to sort by name bool compareName (Person p1, Person p2) { return (p1.get_name() < p2.get_name()); } int main() { string name; int age; Person p1,p2("Ajay Kumar",21); cout<<"Enter the name: "; getline (cin, name); cout<<"Enter the age: "; cin>>age; p1.set_name(name); p1.set_age(age); Person p3("Suman Devi",24),p4("Amit Singh",42); //
Starting with provided code
• Add gender to your class
– enum class Gender {man, woman, nonbinary};
– Gender gen as one of your data attributes in your class
• Overload the operator>> to read in all 3 attributes of the person
– read it in as an int (not in the class)
– then set the gen data attribute with that int
• Add a get_gender method to your class to return a string
• Print the string that corresponds to the gender when you print out
the information for one person in the main
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images