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

Programming Logic and Design, comprehensive, 8 edition. Chapter 11, PE 5a Create

ID: 3669649 • Letter: P

Question

Programming Logic and Design, comprehensive, 8 edition.

Chapter 11, PE 5a

Create a class named Trip that includes four string variables; destination (for example, "air"), departure date (for example, "12/15/2015"), and trip's purpose (for example, "business") Include tow overloaded constructors. The default constructor sets each field to "XXX". The nondefault constructor accepts four parameters- one for each field. include two overloaded display() methods. The parameterless version displays all the Trip details. The second version accepts a string that represents a destination macthers the parameter.

I need help with this question. thank you

Explanation / Answer

Running Program with desired functions:

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

class Trip //class trip
{
   private:
       string destination;
       string departure_Date;
       string trip_purpose;
       string transport;
   public:
       Trip() // default constructor
       {
           destination = "XXX";
           departure_Date = "XXX";
           trip_purpose = "XXX";
           transport = "XXX";                      
       }
      
       Trip(string dst, string dst_date, string trp_purp, string trans) //paramaterised constructor
       {
           destination = dst;
           departure_Date = dst_date;
           trip_purpose = trp_purp;
           transport = trans;
       }
      
       void display() // display method with no parameters
       {
           cout<<"Destination: "<<destination<<endl;
           cout<<"Departure Date: "<<departure_Date<<endl;
           cout<<"Trip Purpose: "<<trip_purpose<<endl;
           cout<<"Transport: "<<transport<<endl;
       }
      
       void display(string dest) // overloaded display() function with parameter
       {
           if(destination.compare(dest) == 0)
           {
               cout<<"Destination: "<<destination<<endl;
               cout<<"Departure Date: "<<departure_Date<<endl;
               cout<<"Trip Purpose: "<<trip_purpose<<endl;
               cout<<"Transport: "<<transport<<endl;              
           }
       }
};

int main()
{
   Trip trip;
   trip.display();
  
   Trip trip1("abc", "19/2/2016", "study", "car");
   trip1.display();
   trip1.display("abc");
}