a. Setthe first name only. b. Setthe last name only. c. Store and set the middle
ID: 3615630 • Letter: A
Question
a. Setthe first name only.
b. Setthe last name only.
c. Store and set the middle name.
d. Checkwhether a given first name is the first name of thisperson.
e. Check whether a given last name is the same as the last name ofthis person. Write the definition of the member functions toimplement the operations for this class. Also, write a program totest various operations on this class.
//Sets firstName and lastName according to theparameters.
//The default values of the parameters are nullstrings
//Postcondition: firstName = first; lastName =last;
private:
string firstName; //variable to store the firstname.
string lastName; //variable to store the last name.
};
class personType
{
public:
void printName();
void setName (string , string );
void setFirstName(string );
void setLastName(string );
void setMiddleName(string );
string getFirstName () const;
string getMiddleName () const;
string getLastName () const;
bool IsSameFirstName(string );
bool IsSameLastName(string );
//personType();
//personType (string first = " ", string last= " ",stringmiddle="");
#include "Header7.h"
#include<string>
#include <iostream>
#include <cstdlib>
void personType::printName()
{
cout<<"First Name:" << firstName<<endl;
cout<<"Middle Name:"<< middleName<<endl;
cout<<"Last Name:" <<lastName<<endl;
}
void personType::setName (string first, stringlast)
{
firstName = first;
lastName = last;
}
void personType::setFirstName(string first)
{
firstName = first;
}
void personType::setLastName(string last)
{
lastName = last;
}
void personType::setMiddleName(string middle)
{
middleName = middle;
}
string personType::getFirstName () const
{
return firstName;
}
string personType::getLastName () const
{
returnlastName;
}
string personType::getMiddleName () const
{
returnmiddleName;
}
bool personType::IsSameFirstName(string first)
{
if(first == firstName) return true;
return false;
}
bool personType::IsSameLastName(string last)
{
if(last == lastName) return true;
return false;
cout<< "Enter first name: ";
cin>>FirstName;
person.IsSameFirstName(FirstName);
person.IsSameFirstName(LastName);
cout<< "Enter last name: ";
cin>>LastName;
person.IsSameFirstName(LastName);
system("PAUSE");
return 0;
}
Explanation / Answer
int main(int argc, char*argv[])
{ personType person;
string FirstName, LastName;
personType ptype ; //= new personType("","","");
ptype.setFirstName("Babe");
ptype.setLastName("Ruth");
ptype.setMiddleName("Jr");
//print first name ,middle name ,last name
ptype.printName();
while(1){
cout<<endl<<endl<<"Enter the names"<<endl;
//person.IsSameFirstName(FirstName);
cout<< "Enter first name: ";
cin>>FirstName;
cout<<"Same first name"<<ptype.IsSameFirstName(FirstName)<<endl;;
//person.IsSameFirstName(LastName);
cout<< "Enter last name: ";
cin>>LastName;
cout<<"Same last name"<<ptype.IsSameLastName(LastName)<<endl;
}
system("PAUSE");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.