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

Consider the Date class below: Class Date { Private: string day; stringmonth; st

ID: 3610120 • Letter: C

Question

Consider the Date class below: Class Date { Private:         string day;         stringmonth;          stringyear;          boolAMERICAN_DATE_FORMAT; public: } complete the class by writing the following two (only)operations: 1.write a constructor function. It should use its inputarguments to intialize the member variables of the class. Thelength of the member string variable should be exactlycharacters. 2. writing an accessor function called getDate. It shouldreturn the date in the format MM/DD/YY if AMERICAN_DATE_FORMAT istrue, otherwise it should return the date in the formatDD/MM/YY. Thanks. Consider the Date class below: Class Date { Private:         string day;         stringmonth;          stringyear;          boolAMERICAN_DATE_FORMAT; public: } complete the class by writing the following two (only)operations: 1.write a constructor function. It should use its inputarguments to intialize the member variables of the class. Thelength of the member string variable should be exactlycharacters. 2. writing an accessor function called getDate. It shouldreturn the date in the format MM/DD/YY if AMERICAN_DATE_FORMAT istrue, otherwise it should return the date in the formatDD/MM/YY. Thanks.

Explanation / Answer

#includeusing namespace std;class Date{private:string day;string month;string year;bool AMERICAN_DATE_FORMAT;public:Date(string d,string m,string y, bool adf){change(d); change(m); change(y); day = d;month = m;year = y;AMERICAN_DATE_FORMAT = adf;}/* Format the string */void change(string & d){int len;string m="";if(d.length() > 2){len = d.length();m = d.at(len-2);m += d.at(len-1); d=m;}if(d.length()==1){d +="0";}}string getDate(){string s="";if(AMERICAN_DATE_FORMAT){s += month;s +="/";s += day;s +="/";s += year;}else{s += day;s +="/";s += month;s +="/";s += year;}return s;}};int main(){Date d("01","04","2009",false);cout
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