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

Write the implementation of the class member functions and a driver program as f

ID: 441820 • Letter: W

Question

Write the implementation of the class member functions and a driver program as follows The class member function implementations should be stored in the .cpp implementation file. There should be documentation for all function implementations. The driver program (main function) should be in its own .cpp file. In the spirit of compiling as you go, it is a good idea to alternate writing a member function and testing it in your driver program. Then you would compile what you have so far, and, once you have no syntax errors, you can run your program. Again you will find it much easier to diagnose your errors when testing small pieces at a time. The driver program should create two person objects as follows: Create a Person object using the default constructor. Read a name and age. Use the mutator set functions to set the name and age. Create a Person object using the constructor with parameters. Make up a name and age for this one in the code. Display the data fields for both Person objects using the accessor get functions.

Explanation / Answer

//Person.h


#ifndef PERSON_H

#define PERSON_H

#include<string>
using namespace std;


class Person{
string firstName;
string lastName;
int age;
public:
Person();
Person(string,string,int);
void setPersonInfo(string fname ,string lname, int Age );
void setName(string,string);
void setAge(int);
string getFirstName() const;
string getLastName() const;
int getAge();
};


#endif

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Person.cpp


#include"Person.h"
#include<string>
using namespace std;


Person::Person(){
age=0;
}
Person::Person(string fname ,string lname, int Age ){
firstName=fname;
lastName=lname;
age=Age;
}

void Person::setName(string fname,string lname){
firstName=fname;
lastName=lname;
}

void Person::setAge(int Age){
age=Age;
}
string Person::getFirstName() const{
return firstName;
}
string Person::getLastName() const{
return lastName;
}

int Person::getAge(){return age;}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//main.cpp


#include<iostream>
#include<string>

#include"Person.h>
#nclude<cstdlib>
using namespace std;


int main(){
string fname,lname;
int age;

Person A;
cout<<"Person A created with default constructor ";
cout<<"Enter name and age: ";
cin>>fname>>lname>>age;

A.setName(fname,lname);
A.setAge(age);
cout<<"Person A mutated with entered information ";
Person B("John","Doe",45);
cout<<"Person B created with overloaded constructor ";
cout<<"Person A: Name: "<<A.getFirstName()<<" "<<A.getLastName()<<" Age: "<<A.getAge()<<endl<<endl;
cout<<"Person B: Name: "<<B.getFirstName()<<" "<<B.getLastName()<<" Age: "<<B.getAge()<<endl;

system("pause");
return 0;
}