classes help Please!

Example 10- 10 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.
header

#include <string>

using namespace std;

class personType
{
public:
void print() const;
//Function to output the first name and last name
//in the form firstName lastName.

void setName(string first, string last, string middle);
//Function to set firstName and lastName according
//to the parameters.
//Postcondition: firstName = first; lastName = last

string getFirstName() const;
//Function to return the first name.


string getLastName() const;
//Function to return the last name.
string getMiddleName () const;


personType(string first = "", string last = "", string middle = "");
//Constructor
//Sets firstName and lastName according to the parameters.


private:
string firstName; //variable to store the first name
string lastName;//variable to store the last name
string MiddleName;
};
//personTypeImp.cpp

#include <iostream>
#include <string>
#include "personType.h"

using namespace std;

void personType::print() const
{
cout << firstName << " " << lastName;

}

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

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

string personType::getLastName() const
{
return lastName;
}
string personType::getMiddleName() const
{
return MiddleName;
}
//constructor
personType::personType(string first, string last, string middle)

{
firstName = first;
lastName = last;
}


#include <iostream>
#include <string>
#include "personType.h"

using namespace std;

int main()
{
personType student("Lisa", "Regan");

student.print();

cout << endl;

return 0;
}
My question how I do store and set the middle name and how to do d and e?
Last edited on
Topic archived. No new replies allowed.