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

Example 12-9 defined a class personType to store the name of a person. The membe

ID: 3677306 • Letter: E

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.

(Malik 719)

FIGURE 12-11: UML class diagram of the class personType

We now give the definitions of the member functions of the class personType.

void personType::print() const

{

    cout << firstName << "" < < lastName;

}

void personType::setName(string first, string last)

{

    firstName = first;

    lastName = last;

}

string personType::getFirstName() const

{

    return firstName;

}

string personType::getLastName() const

{

    return lastName;

}

    //constructor

personType::personType(string first, string last)

{

    firstName = first;

    lastName = last;

}

(Malik 690-691)

Malik, D.S.. C++ Programming: From Problem Analysis to Program Design. Cengage Learning, 03/2014. VitalBook file.

personType -firstName: string -lastName: string +print (): voic +setName (string, string): void +get First Name() const: string +getLastName () const: string +personType (string="", string="")

Explanation / Answer

// Hi I have written all functionality of persontype class.

Please write your test class and test all functionality

#include<iostream>
#include<string>

using namespace std;

class personType{
   string firstName;
   string lastName;
   string middleName;
  
   public:
       void print() const;
       personType(string = "", string = "");
       personType(string = "", string = "", string = "");
       void setName(string, string);
       void setName(string, string,string);
       void setFirstName(string);
       void setLastName(string);
       void setMiddleName(string);
       string getFirstName() const;
       string getLastName() const;
       string getMiddleName() const;
       bool checkFirstName(string);
       bool checkLastName(string);
  
   };
  
void personType::print() const
{
    cout << firstName << " " << lastName;
}

void personType::setName(string first, string last)
{
    firstName = first;
   lastName = last;
}

void personType::setName(string first, string middle, string last)
{
   firstName = first;
    lastName = last;
    middleName = middle;
}

string personType::getFirstName() const
{
    return firstName;
}

string personType::getLastName() const
{
    return lastName;
}
string personType::getMiddleName() const
{
    return middleName;
}
void personType::setFirstName(string first)
{
    firstName = first;
}
void personType::setLastName(string last)
{
    lastName = last;
}
void personType::setMiddleName(string middle)
{
    middleName = middle;
}
bool personType::checkFirstName(string first)
{
    if(firstName.compare(first) == 0)
       return true;
   return false;
}
bool personType::checkLastName(string last)
{
    if(lastName.compare(last) == 0)
       return true;
   return false;
}
    //constructor
personType::personType(string first, string middle, string last)
{
    firstName = first;
   middleName = middle;
    lastName = last;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote