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

Design a class DriversLicense which has the following 5 private data members - n

ID: 3787590 • Letter: D

Question

Design a class DriversLicense which has the following 5 private data members - name (string), date of birth (mm/dd/yyyy)(Date object), address (string), gender(char), expiry date (mm/dd/yyyy)(Date object). The class should have a default constructor that assigns the name to be unknown, date of birth to be 01/01/1900, address to be unknown, gender to be unknown, and expiry date to be 01/01/1900. It should have a 5 argument constructor to initialize all the member data. Also, it should have a constructor that only sets the name and date of birth with the remaining parameters same as the default. Include a method that displays all the information (each on a separate line), and another method that prints the number of years to expiry from the year input by the user. The Date class has 3 private data members of type int representing month, day, and year. It has a 1 string argument constructor to initialize all member data, and a default constructor that sets the date to 01/01/1990. Add a getter getYear() that returns the year. Also, it has a printDate() method that prints the date as a string in the (mm/dd/yyyy) format.

testing program is below

int main()
{
   DriversLicense my_license1, my_license3("Superman", "01/01/1000");
   my_license1.printLicenseInfo(); // Prints the 5 data members on separate lines
   cout << endl;
   my_license3.printLicenseInfo();
   cout << endl;
   DriversLicense my_license2("Charlie Brown", "01/01/1980", "9201 University City Blvd. Charlotte NC 28223", 'm', "01/01/2020");
   my_license2.printLicenseInfo();
   cout << endl;
   cout << "Years to expiry " << my_license2.yearsToExpiry(2017) << endl;
   return 0;
}

Explanation / Answer

// C++ code

#include <iostream>
#include <stdlib.h>
using namespace std;


class DriversLicense
{
private:
    string name, date_Of_Birth, personAddress, expiryDate, gender;

public:
    DriversLicense()
    {

      name="unknown";
      date_Of_Birth="01/01/1900";
      personAddress="unknown";
      gender="unknown";
      expiryDate="01/01/1900";

    }

    DriversLicense(string personName,string dob, string address, string gender1, string expiryDate1)
    {

      name=personName;
      date_Of_Birth=dob;
      personAddress=address;
      gender=gender1;
      expiryDate=expiryDate1;

    }

    DriversLicense(string personName,string dob)
    {

      name=personName;
      date_Of_Birth=dob;
      personAddress="unknown";
      gender="unknown";
      expiryDate="01/01/1900";

    }
    void printLicenseInfo()
    {
      cout<<" Name:"<<name<<endl;
      cout<<"Date Of Birth:"<<date_Of_Birth<<endl;
      cout<<"personAddress:"<<personAddress<<endl;
      cout<<"Gender:"<<gender<<endl;
      cout<<"Expiry Date:"<<expiryDate<<endl;

    }
    int yearsToExpiry(int yrs)
    {
      string tkn = expiryDate.substr(6, 9);
      int nyears=atoi(tkn.c_str());

      return nyears-yrs;

    }

};


int main()
{
    DriversLicense my_license1, my_license3("Superman", "01/01/1000");
    my_license1.printLicenseInfo();
    cout << endl;
    my_license3.printLicenseInfo();
    cout<<endl;
    DriversLicense my_license2("Charlie Brown", "01/01/1980", "9201 University City Blvd. Charlotte NC 28223", "Male", "01/01/2020");
    my_license2.printLicenseInfo();
    cout << "Years to expiry " << my_license2.yearsToExpiry(2016)<<endl;
    return 0;
}


/*
output:

Name:unknown
Date Of Birth:01/01/1900
personAddress:unknown
Gender:unknown
Expiry Date:01/01/1900


Name:Superman
Date Of Birth:01/01/1000
personAddress:unknown
Gender:unknown
Expiry Date:01/01/1900


Name:Charlie Brown
Date Of Birth:01/01/1980
personAddress:9201 University City Blvd. Charlotte NC 28223
Gender:Male
Expiry Date:01/01/2020
Years to expiry 4


*/

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