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

The following code: #include <string> using namespace std; class personType { pu

ID: 3619583 • Letter: T

Question

The following code:

#include <string>

using namespace std;

class personType
{
public:

void print() const;
void setName (string first, string last);
string getFirstName() const;
string getLastName() const;
personType(string first = "", string last = "");

Private:

string firstName;
string lastName;
};

void personType::print() const
{
cout<<firstName<<" "<<lastNname;
}

void persontype::setName(string first, string last)
{
firstName = first;
lastName = last;
}

string personType::getFirstName() const
{
return firstName;
}

string personType::getLastName() const
{
return lastName;
}

personType:personType(string first, string last)
{
firstName = first;
lastName = last;
} //end

defined a "class" personType to store the name of a perso. 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 can:

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 last name of this person. Write definitions of the member functions to implement the operations for this class. Also, write a program to test various operations on this "class".

I have written my own code and tryed to use the given code posted on this website ( "C++ programming 4th editon" by D.S. Malik. Chapter 12, Question 4). I keep getting LNK2019 Errors using VisualStudio 2008. Any help would be greatly appreciated.

Explanation / Answer

please rate - thanks the lines I fixed have a /////// next to them I then finished the code #include <string>
#include <iostream>        /////////////////////
using namespace std;

class personType
{
public:

void print() const;
void setName (string first, string mid,string last);
string getFirstName() const;
string getLastName() const;
string getMiddleName() const;
void setFirstName(string);
void setLastName(string) ;
void setMiddleName(string) ;
personType(string first = "", string mid="",string last = "");

private:                           /////////////////

string firstName;
string lastName;
string middleName;
};

void personType::print() const
{
cout<<firstName<<" "<<middleName<<" "<<lastName<<endl;           ///////////////////
}

void personType::setName(string first,string mid, string last)      ////////////
{
firstName = first;
lastName = last;
middleName =mid;
}
void personType::setLastName(string last)    
{
lastName = last;
}
void personType::setFirstName(string first)    
{
firstName = first;
}
void personType::setMiddleName(string mid)    
{
middleName =mid;
}
string personType::getFirstName() const
{
return firstName;
}
string personType::getMiddleName() const
{
return middleName;
}
string personType::getLastName() const
{
return lastName;
}

personType::personType(string first,string middle, string last) //////////////
{
firstName = first;
middleName=middle;
lastName = last;
} //end
int main()
{personType a;
personType b("Mary","Susan","Jones");
a.print();
b.print();
a.setFirstName("John");
a.print();
a.setMiddleName("Paul");
a.print();
a.setLastName("Jones");
a.print();
if(a.getFirstName().compare("Jack")!=0)
       cout<<a.getFirstName()<<" and Jack are different ";
else
       cout<<a.getFirstName()<<" and Jack are the same ";
if(a.getLastName().compare("Jack")!=0)
       cout<<a.getLastName()<<" and Jack are different ";
else
       cout<<a.getLastName()<<" and Jack are the same ";
if(b.getFirstName().compare("Mary")!=0)
       cout<<b.getFirstName()<<" and Mary are different ";
else
       cout<<b.getFirstName()<<" and Mary are the same ";
      
if(b.getLastName().compare("Jones")!=0)
       cout<<b.getLastName()<<" and Jones are different ";  
else
       cout<<b.getLastName()<<" and Jones are the same ";  
           
     
system("pause");
return 0;
}

#include <string>
#include <iostream>        /////////////////////
using namespace std;

class personType
{
public:

void print() const;
void setName (string first, string mid,string last);
string getFirstName() const;
string getLastName() const;
string getMiddleName() const;
void setFirstName(string);
void setLastName(string) ;
void setMiddleName(string) ;
personType(string first = "", string mid="",string last = "");

private:                           /////////////////

string firstName;
string lastName;
string middleName;
};

void personType::print() const
{
cout<<firstName<<" "<<middleName<<" "<<lastName<<endl;           ///////////////////
}

void personType::setName(string first,string mid, string last)      ////////////
{
firstName = first;
lastName = last;
middleName =mid;
}
void personType::setLastName(string last)    
{
lastName = last;
}
void personType::setFirstName(string first)    
{
firstName = first;
}
void personType::setMiddleName(string mid)    
{
middleName =mid;
}
string personType::getFirstName() const
{
return firstName;
}
string personType::getMiddleName() const
{
return middleName;
}
string personType::getLastName() const
{
return lastName;
}

personType::personType(string first,string middle, string last) //////////////
{
firstName = first;
middleName=middle;
lastName = last;
} //end
int main()
{personType a;
personType b("Mary","Susan","Jones");
a.print();
b.print();
a.setFirstName("John");
a.print();
a.setMiddleName("Paul");
a.print();
a.setLastName("Jones");
a.print();
if(a.getFirstName().compare("Jack")!=0)
       cout<<a.getFirstName()<<" and Jack are different ";
else
       cout<<a.getFirstName()<<" and Jack are the same ";
if(a.getLastName().compare("Jack")!=0)
       cout<<a.getLastName()<<" and Jack are different ";
else
       cout<<a.getLastName()<<" and Jack are the same ";
if(b.getFirstName().compare("Mary")!=0)
       cout<<b.getFirstName()<<" and Mary are different ";
else
       cout<<b.getFirstName()<<" and Mary are the same ";
      
if(b.getLastName().compare("Jones")!=0)
       cout<<b.getLastName()<<" and Jones are different ";  
else
       cout<<b.getLastName()<<" and Jones are the same ";  
           
     
system("pause");
return 0;
}

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