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

#include <string> using namespace std; class personType { public: void print() c

ID: 3552413 • Letter: #

Question


#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);

      //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(string first = "", string last = "");

      //Constructor

      //Sets firstName and lastName according to the parameters.

      //The default values of the parameters are null strings.

      //Postcondition: firstName = first; lastName = last;

private:

    string firstName; //variable to store the first name

    string lastName; //variable to store the last name

};

a. Write a C++ statement that declares student to be a personType object, and initialize its first name to "Buddy" and last name to "Arora".
b. Write a C++ statement that outputs the data stored in the object student.
c. Write C++ statements that change the first name of student to "Susan" and the last name to "Gilbert".

Assume the definition of the class personType as follows.

#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);

      //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(string first = "", string last = "");

      //Constructor

      //Sets firstName and lastName according to the parameters.

      //The default values of the parameters are null strings.

      //Postcondition: firstName = first; lastName = last;

private:

    string firstName; //variable to store the first name

    string lastName; //variable to store the last name

};

Explanation / Answer

(a) personType student("Buddy", "Arora");


(b) student.print();


(c) student.setName("Susan", "Gilbert");