Question

In c++ redefine the class personType to take advantage of the new features of object-oriented design...

In c++ redefine the class personType to take advantage of the new features of object-oriented design that you have
learned, such as operator overloading, and then derive the class customerType.

personType:

#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();
//Default constructor
//Sets firstName and lastName to null strings.
//Postcondition: firstName = ""; lastName = "";

personType(string first, string last);
//Constructor with parameters.
//Sets firstName and lastName according to the parameters.
//Postcondition: firstName = first; lastName = last;

private:
string firstName; //variable to store the first name
string lastName; //variable to store the last name
};

0 0
Add a comment Improve this question Transcribed image text
Answer #1

personType.h:

#include <string>
#ifndef PERSONTYPE_H
#define PERSONTYPE_H
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();
//Default constructor
//Sets firstName and lastName to null strings.
//Postcondition: firstName = ""; lastName = "";

    personType(string first, string last);
//Constructor with parameters.
//Sets firstName and lastName according to the parameters.
//Postcondition: firstName = first; lastName = last;

    friend istream &operator>>(istream &input, personType &P)
    {
        char str[20];
        input>>P.firstName;
        input>>P.lastName;
        P.setName(P.firstName,P.lastName);
        return input;
    }
    friend ostream &operator<<( ostream &output, personType &P ) {
        cout<<"Operator << overloaded"<<endl;
        output << "The name of person is: " << P.getFirstName() << " " << P.getLastName()<<endl;
        return output;
    }


private:
    string firstName; //variable to store the first name
    string lastName; //variable to store the last name
};
personType::personType()
{
    firstName = "";
    lastName = "";
}
personType::personType(string first, string last)
{
    setName(first, last);
}
void personType::print()const
{
    cout<<"The name of person is: "<<getFirstName()<<" "<<getLastName()<<endl;
}
void personType::setName(string first, string last)
{
    firstName = first;
    lastName = last;
}
string personType::getFirstName() const
{
    return firstName;
}
string personType::getLastName() const
{
    return lastName;
}

class customerType: public personType {
public:
    void printCustomer()
    {
        cout<<"The name of customer is: "<<getFirstName()<<" "<<getLastName()<<endl;
    }
};
#endif

personType.cpp:

#include<iostream>
#include "personType.h"
using namespace std;
int main()
{
    personType p = personType("vishnu","prasad");/*implementatoin of class personType*/
    p.print();
    personType p1;
    cout<<"Enter first name and last name for performing overloading << operator: "<<endl;
    cin>>p1;   /*implementation of operator overloading*/
    cout<<p1;

    customerType c;
    c.setName("vishnu","koduri");/*implementation of derived class*/
    c.printCustomer();
    return 0;
}

Output:

Add a comment
Know the answer?
Add Answer to:
In c++ redefine the class personType to take advantage of the new features of object-oriented design...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please implement the following problem in basic C++ code and include detailed comments so that I...

    Please implement the following problem in basic C++ code and include detailed comments so that I am able to understand the processes for the solution. Thanks in advance. // personType.h #include <string> using namespace std; class personType { public: virtual void print() const; void setName(string first, string last); string getFirstName() const; string getLastName() const; personType(string first = "", string last = ""); protected: string firstName; string lastName; }; // personTypeImp.cpp #include <iostream> #include <string> #include "personType.h" using namespace std; void...

  • "Function does not take 0 arguments". I keep getting this error for my last line of...

    "Function does not take 0 arguments". I keep getting this error for my last line of code: cout << "First Name: " << employee1.getfirstName() << endl; I do not understand why. I am trying to put the name "Mike" into the firstName string. Why is my constructor not working? In main it should be set to string firstName, string lastName, int salary. Yet nothing is being put into the string. #include<iostream> #include<string> using namespace std; class Employee {    int...

  • 8.26 Encapsulate the Name class. Modify the existing code shown below to make its fields private,...

    8.26 Encapsulate the Name class. Modify the existing code shown below to make its fields private, and add appropriate accessor methods to the class named getFirstName, getMiddleInitial, and getLastName. code: class Name { private String firstName; private String middleNames; private String lastName;    //Constructor method public Name(String firstName, String middleNames, String lastName) { this.firstName = firstName; this.middleNames = middleNames; this.lastName = lastName;    } //Accessor for firstName public String getFirstName() { return firstName; } //Accessor for middleNames public String getMiddlesNames()...

  • A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double...

    A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double GPA(=(4.0*NumberOfAs+3.0*NumberOfBs+2.0*NumberOfCs+1.0*NumberOfDs)/( As+Bs+Cs+Ds+Fs)); Public data member, void setFirstName(string name); string getFirstName() const; void printFirstName() const; void getLastName(string name); string getLastName() const; void printLastName() const; void computeGPA(int NumberOfAs,int NumberOfBs,int NumberOfCs,int NumberOfDs,int NumberOfFs); double getGPA() const; double printGPA() const; A destructor and an explicit default constructor initializing GPA=0.0 and checking if GPA>=0.0 by try{}catch{}. Add member function, bool operator<(const Student); The comparison in this function based on...

  • This is a simple C++ class using inheritance, I have trouble getting the program to work....

    This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...

  • Is there any better way to solve the way I'm calling employer() and get...() below codes...

    Is there any better way to solve the way I'm calling employer() and get...() below codes in c++:: ============ class employer{ string FirstName, string LastName; int emplID; public: ///to set employer void setemployer(string f,string l,int y) { FirstName=f; LastName=l; emplID=y; } string getFirstName(){ return FirstName; } string getLastName(){ return LastName; } int getemplID(){ return emplID; } .... // This sections is in the main: int main() { string first; string last; int emplID; for(int i=0;i<size;i++) { cin>>first>>last>>emplID; ///read data employer[i].setemployer(first,last,emplID);...

  • Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person {...

    Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person { public: Person() { setData("unknown-first", "unknown-last"); } Person(string first, string last) { setData(first, last); } void setData(string first, string last) { firstName = first; lastName = last; } void printData() const { cout << "\nName: " << firstName << " " << lastName << endl; } private: string firstName; string lastName; }; class Musician : public Person { public: Musician() { // TODO: set this...

  • My main() file does not call to the class created in a .hpp file. It comes...

    My main() file does not call to the class created in a .hpp file. It comes out with the error "undefined reference to "___" const. I want to solve this by only changing the main() .cpp file, not the .hpp file. .cpp file .hpp file Thank you! include <iostream> include <string> tinclude "CourseMember.hpp using namespace std int main0 CourseMember CourseMember(90, "Jeff", "Goldblum"): // initializing the constructor cout<< "Member ID is <<CourseMember.getID) << endl; 1/ calling getID) accessor cout <<"First Name...

  • Public class Person t publie alass EmployeeRecord ( private String firstName private String last ...

    public class Person t publie alass EmployeeRecord ( private String firstName private String last Nanei private Person employee private int employeeID publie EnmployeeRecord (Person e, int ID) publie Person (String EName, String 1Name) thia.employee e employeeID ID setName (EName, 1Name) : publie void setName (String Name, String 1Name) publie void setInfo (Person e, int ID) this.firstName- fName this.lastName 1Name this.employee e employeeID ID: publio String getFiritName) return firstName public Person getEmployee) t return employeei public String getLastName public int getIDO...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT