Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Book is Data Structures Using C++ 2nd edition. Example 1-12 defined a class personType to store the name of a person.The member functions that we

Book is Data Structures Using C++ 2nd edition.

Example 1-12 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 also can do the following: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.

Here is the base code given.

C++

MainSource.cpp

#include "Info.h" #include "personType.h" #include using namespace std;

int main() { Info myInfo; myInfo.displayInfo(__DATE__);

personType aperson; aperson.setName("First", "Last"); aperson.print();

cin.ignore(); }

personType.H

#include

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); //Function to set firstName and lastName according to the //parameters. //Postcondition: firstName = first; lastName = last

string getFirstName() const; //Function to return the first name. //Postcondition: The value of firstName is returned.

string getLastName() const; //Function to return the last name. //Postcondition: The value of lastName is returned.

personType(); //Default constructor //Sets firstName and lastName to null strings. //Postcondition: firstName = ""; lastName = "";

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

private: string firstName; //variable to store the first name string lastName; //variable to store the last name };

personType.cpp #include #include #include "personType.h"

using namespace std;

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; }

//Default constructor personType::personType() { firstName = ""; lastName = ""; }

//Constructor with parameters personType::personType(string first, string last) { firstName = first; lastName = last; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions