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

Instructions: Please read and follow the following instructions. Read and unders

ID: 3669711 • Letter: I

Question

Instructions:

Please read and follow the following instructions.

Read and understand the description for all the methods listed in the header file. By listed in the header file, I mean the prototype methods

Implement all the methods listed in the header file, inside the FullName.cpp file.

The signature of each method is given to you, fill the body of the function based on how you understand the description of each method.

In the Source.cpp, follow the instructions listed in the file as comments

Methods description:

The Constructors & Destructor:

1) FullName();

This is the default constructor, the private string members (variables) first and last should be assigned to “unknown” and the private char member mI should be assigned to ‘_’

2) FullName(const FullName &);

This constructor has a FullName reference object as an argument, the passed reference object members (first, mI and last) should be assigned to the created object (the object which is causing calling this constructor). The const keyword indicates that you (the programmer) are not allowed to change any of the member values for the passed object.

3) FullName(const string fr, char initial, const string ls);

This constructor has 3 arguments argument, assign them to the members of the created object (the object which is causing calling this constructor). The const keyword indicates that you (the programmer) are not allowed to change the passed arguments.

Leave the body of the Destructor method (~FullName();) empty

The Getters:

const string getFirstName() const;

char getMiddleInitial() const;

const string getLastName() const;

The 1st and 3rd methods returns values of the first and last string members. The 2nd method return the value of mI char member. Each method implementation should be one line code starts with the return keyword.

The setters:

void setFirstName(const string);

void setMiddleInitial(char);

void setLastName(const string);

These methods will set the first, mi and last member values to the passed argument value. Rach method should contain one assignment line code.

void input(void);

Whenever this method is called, three prompt messages should appear asking the user to enter values for the members first, mI and last.

void print() const;

This method should print the full name of the object

void copyTo(const FullName &);

The implementation of this method is exactly the same as the implementation of the 2nd constructor

bool isEqual(const FullName &) const;

This method should return true if the passed object members (first, mI and last) are equal to the object members. The code has been given, you do not need to write anything here.

void changeLastNameToAllCaps(void);

The last name will be changed to all capital letters, the last name can contain special characters such as "Smith-Jones" which will become "SMITH-JONES"

All you have to do is:

Create a for loop to access to all the characters of the last name

For each character, if its an aplanatic char and its lower case char, Convert it to upper case character. Otherwise, do nothing.

You will need to use these methods

Isalpha(),islower() and toupper()

Question to think about: you may noticed that the keyword const has been used in three different conditions:

The return data type is const

The argument/arguments is/are const

The signature ends with const

Describe each case.

_____________________FullName.h______________________

#ifndef FULL_NAME
#define FULL_NAME
#include <iostream>
#include <string>
using namespace::std;

class FullName
{
public:
FullName();
FullName(const FullName &);
FullName(const string fr, char initial, const string ls);

~FullName();

const string getFirstName()       const;
char         getMiddleInitial()   const;
const string getLastName()        const;

void setFirstName(const string);
void setMiddleInitial(char);
void setLastName(const string);

void input(void);
void print() const;   

void copyTo(const FullName &);

bool isEqual(const FullName &) const;

void changeLastNameToAllCaps(void);

private:
string first;
char   mI;
string last;
};
#endif

Explanation / Answer

main.cpp

#include "FullName.h"
#include <iostream>
using namespace::std;

int main()
{
   {
        FullName singer("Patsy",'P',"Cline");
        FullName anotherSinger(singer);
        anotherSinger.input();
      
   }   // want singer to go out of scope so destructor will be called
   char t;
   cin.get(t);
   cin.get(t);
   return 0;
  
}


FullName.h

#ifndef FULL_NAME
#define FULL_NAME
#include <iostream>
#include <cstring>
using namespace::std;

class FullName
{
public:
   FullName();
   FullName(const FullName &);
   FullName(const char * fr, char initial, const char * ls);

   ~FullName();

   const char * getFirstName()       const;
   char         getMiddleInitial()   const;
   const char * getLastName()        const;

   void setFirstName(const char *);
   void setMiddleInitial(char);
   void setLastName(const char *);

   void input(void);
   void print(ostream & ) const; // of the form:    Doe, John A.

   bool isSmaller(const FullName & ) const;   // is invoking instance smaller than parameter

   void copyTo( const FullName &) ;    // copy parameter to invoking instance
  
    bool isEqual(const FullName&) const;

private:
   char * first;
   char   mI;
   char * last;
};
#endif

FullName.cpp

#include "FullName.h"

FullName::FullName()
{
   first = NULL;
   setFirstName("John");
}

FullName::FullName(const FullName & other)
{
   first = NULL;
   setFirstName(other.getFirstName());
}

FullName::FullName(const char * fr, char initial, const char * ls)
{
   first = NULL;
   setFirstName(fr);
}

FullName::~FullName()
{
    if ( first != NULL )
   {
        cout << "FIRST NAME: " << first << " deleted from address "
           << static_cast<void *>(first) << endl;
       delete [] first;
   }
}

const char * FullName::getFirstName()       const
{
   return first;
}

char FullName::getMiddleInitial()    const
{
       return 'X';     // only here to get a compile - MUST be removed
}

const char * FullName::getLastName()         const
{
       return NULL;    // only here to get a compile - MUST be removed
}

void FullName::setFirstName(const char *fr)
{
   if ( first != NULL )
       {
        cout << "FIRST NAME: " << first << " deleted from address "
           << static_cast<void *>(first) << endl;
        delete [] first;    // return heap memory
   }     
   first = new char[strlen(fr) + 1];
   strcpy(first, fr);
   cout << "FIRST NAME: " << first << " added at address "
           << static_cast<void *>(first) << endl;

}

void FullName::setMiddleInitial(char m)
{
    this->mI = m;
}

void FullName::setLastName(const char * ln)
{
    this->last = (char*)ln;
}

void FullName::input(void)
{
   char tempFirst[100];
   cin.getline(tempFirst, 100);
   setFirstName(tempFirst);
}
void FullName::print(ostream & ) const // of the form:    Doe, John A.
{
}

bool FullName::isSmaller(const FullName & right) const   // is invoking instance smaller than parameter
{
   if ( strcmp(getFirstName(),right.getFirstName()) < 0 )
        return true;
    else if (right.getMiddleInitial() < this->mI)
        return true;
    else if ( strcmp(getFirstName(),right.getFirstName()) < 0 )
        return true;
   else
        return false;
}

void FullName::copyTo( const FullName & right)    // copy parameter to invoking instance
{
   setFirstName(right.getFirstName());
}

bool FullName::isEqual(const FullName& right) const
{
    if ( strcmp(getFirstName(),right.getFirstName()) == 0 )
        return true;
    else if (right.getMiddleInitial() == this->mI)
        return true;
    else if ( strcmp(getFirstName(),right.getFirstName()) == 0 )
        return true;
   else
        return false;
}

output

FIRST NAME: Patsy added at address 0x1e39010                                                                                                                
FIRST NAME: Patsy added at address 0x1e39030