Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

help me to solve this question Example 12-9 defined a class personType to store

ID: 3779464 • Letter: H

Question

help me to solve this question

Example 12-9 defined a class personType to store the name of a person.
The member functions that we included merely print the name and set the
name of a person. Redefine the class personType so that, in addition to
what the existing class does, you can:
a. Set the first name only.
b. Set the last name only.
c. Store and set the middle name.
d. Check whether a given first name is the same as the first name of this person.
e. Check whether a given last name is the same as the last name of this person.
Write the definitions of the member functions to implement the operations
for this class. Also, write a program to test various operations on this class.

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;
class personType
{
   string fname,mname,lname;
public:
   void setFirstName(string n)
   {
       fname=n;
   }
   void setLastName(string n)
   {
       lname=n;
   }
   void setMiddleName(string n)
   {
       mname=n;
   }

   bool compareFirstName(personType& o1)
   {
      
       if((o1.fname).compare(fname))
       {
          
           return false;
       }
       return true;
   }

   bool compareLastName(personType& o1)
   {
       if((o1.lname).compare(lname))
           return false;
       return true;
   }
};

int main(int argc, char const *argv[])
{   string f,l,m,f2,l2,m2;
   personType o1,o2;
   cout<<"Enter Details for Person 1: ";
   cout<<"Enter First name ";
   cin>>f;
   o1.setFirstName(f);


   cout<<"Enter Last name ";
   cin>>l;
   o1.setLastName(l);


   cout<<"Enter Middle name ";
   cin>>m;
   o1.setMiddleName(m);

   cout<<"Enter Details for Person 2: ";
   cout<<"Enter First name ";
   cin>>f2;
   o2.setFirstName(f2);


   cout<<"Enter Last name ";
   cin>>l2;
   o2.setLastName(l2);


   cout<<"Enter Middle name ";
   cin>>m2;
   o2.setMiddleName(m2);

   if(o1.compareFirstName(o2))
   {
       cout<<"First name are same ";
   }
   else
   {
       cout<<"First name are not same ";
   }

   if(o1.compareLastName(o2))
   {
       cout<<"Last name are same ";
   }
   else
   {
       cout<<"Last name are not same ";
   }

  

  
   return 0;
}

================================================================

Chegg$ g++ eprsontyep.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Enter Details for Person 1:
Enter First name
Jon
Enter Last name
smith
Enter Middle name
Kenn
Enter Details for Person 2:
Enter First name
Jon
Enter Last name
clinton
Enter Middle name
godmann
First name are same
Last name are not same

=====================================================================