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

C++: Part a. Create an overloaded constructor for a derived class named Customer

ID: 3579651 • Letter: C

Question

C++:

Part a. Create an overloaded constructor for a derived class named CustomerData
- Create the function without rewriting code from the overloaded base class constructor.
- Base Class (PersonData):
- A member variable for lastName, firstName and address (strings)
- Overloaded constructor
- Derived Class (CustomerData):
- A member variable for customer number (int)
- A member variable for mailing list (bool)

Part b. Using the information above, create an overloaded operator function to determine if a customer is less than another customer. A customer should be less than another customer if the customer number is less than the other customer number.

Explanation / Answer

#include<iostream>
#include<string>

class PersonData
{
public:

PersonData(string l, string n, string a)
{
          lastName=l;
          firstName=n;
          address=a;
   }
     
   string toString()
   {
          string s= lastName+" "+firstName+" "+address;
          return s;
   }

private:
string lastName, firstName,address;
string y;
};

class CustomerData: public PersonData
{
   public:
  
   CustomerData(string l, string n, string a, int id) : PersonData(l,n,a)
    {
           
          customer_no=id;
   }
  
  
   // overload < operator
   bool operator<(CustomerData& c) const
   {
       if(customer_no < c.customer_no) return true;
       else return false;
   }
   int getCustomerNo()
   {
       return customer_no;
   }
  
   private:
       int customer_no;
};

int main()
{
   CustomerData c("Khan","Asif","batamaloo", 1);
   CustomerData c1("Sheikh","Junaid","Habbakada;", 2);
   CustomerData c2("Khan","Asif","batamaloo", 1);
  
   if(c<c1)
   {
       cout << c.toString() <<" is less than "<<c1.toString();
   }
   else cout << c.toString() <<" is not less than "<<c1.toString();
  
  
}

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