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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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); //vector initialization vector<Person> vec = {p1, p2, p3, p4}; sort(vec.begin() ,vec.end(), compareName); //printing sorted vector int i = 1; for(Person x : vec) { cout << "\n-"<<i<<"-Name: "<<x.get_name()<<" Age: "<< x.get_age()<<endl; i++; } return 0; }

 

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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY