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

Add Two constructors: A- No argument that puts the Name in a safe empty state (I

ID: 3820259 • Letter: A

Question

Add Two constructors: A- No argument that puts the Name in a safe empty state (It is your call to decide what is a safe empty state for a Mark) B- A 2 argument constructor that sets a Name. C- Add a method calls isEmpty() that returns a Boolean. It returns true if the Mark is in a safe empty state. D- A display function that displays the full name.

class Name
{ char buffer[51];
char m_first[21];
char m_last[31];
public:

void firstname(const char* value); // sets the name
void lastname(const char* value); // sets the last name
const char* fullname(); // returns a string containing full name };

Explanation / Answer

#include <iostream>
#include <string.h>

using namespace std;

class Name{
   char buffer[51];
   char m_first[21];
   char m_last[31];
public:
   Name();
   Name(const char* f,const char* l);
   bool isEmpty();
   void display();
   void firstname(const char* value); // sets the name
   void lastname(const char* value); // sets the last name
   const char* fullname(); // returns a string containing full name
};

Name::Name(){
   buffer[0] = '';
   m_first[0] = '';
   m_last[0] = '';
}

Name::Name(const char* f,const char* l){
   buffer[0] = '';
   strcpy(m_first,f);
   strcpy(m_last,l);
}
bool Name::isEmpty(){
   if(m_first[0]=='' && m_last[0]=='')
       return true;
   return false;
}

void Name::display(){
   cout << "Full Name :"<<fullname()<<endl;
}

void Name::firstname(const char* value){
   strcpy(m_first,value);
}

void Name::lastname(const char* value){
   strcpy(m_last,value);
}

const char* Name::fullname(){
   int i=0;
   while(m_first[i] != ''){
       buffer[i] = m_first[i];
       i++;
   }
   buffer[i] = ' ';
   i++;
   while(m_last[i] != ''){
       buffer[i] = m_last[i];
       i++;
   }
   buffer[i] = '';
   return buffer;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote