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

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

ID: 441797 • Letter: #

Question

#include<iostream>

#include<string>

#include<cstdlib>

using namespace std;

class Button

{

private:

int pressCount;//starts at 0

public:

//CONSTRUCTOR

Button();

//MUTATOR

void Press();//increments the pressCount

//ACCESSOR

int TimesPressed();

};

class Date

{

private:

int year,month,day;

public:

Date();

Date(int yr,int mm,int dd);

void SetDate(int yr,int mm, int dd);

void DisplayNumerically();

void DisplayTextually();

};

Button::Button()

{

pressCount = 0;

}

void Button::Press()

{

pressCount++;

}

int Button::TimesPressed()

{

return pressCount;

}


Date::Date()

{

//default constuctor sets Date to 2/7/2013 :3

SetDate(2013,2,12);

}


Date::Date(int yr,int mm,int dd)

{

Date();

SetDate(yr,mm,dd);

}


void Date::SetDate(int yr,int mm,int dd)

{

if(yr < 0 || yr > 2019)

{

cout << "[ERROR] " << yr << " isn't a valid year. ";

}

else if(mm < 0 || mm > 12)

{

cout << "[ERROR] " << mm << " isn't a valid month. ";

}

else if(dd < 0 || dd > 31)

{

cout << "[ERROR] " << dd << " isn't a valid day. ";

}

else if((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30)

{

cout << "[ERROR] " << dd << " isn't a valid day. ";

}

else if(mm == 2 && dd > 28)

{

cout << "[ERROR] " << dd << " isn't a valid day. ";

}

else

{

year=yr;

month=mm;

day=dd;

}

}


void Date::DisplayNumerically()

{

if(month<10)

cout << "0";

cout << month << "/";

if(day<10)

cout << "0";

cout << day << "/" << year << endl;

return;

}


void Date::DisplayTextually()

{

string Month[12] = {"January", "February", "March","April", "May", "June", "July","August", "September", "October","November", "December"};

cout<<Month[month-1]<<" "<< day <<", "<< year;

}


int main()

{

Button myButton;

char press;

cout << "Button myButton created. ";

cout << "The current pressed count of myButton is " << myButton.TimesPressed() << endl;

cout << "Do you want to press myButton(y/n): ";

cin >> press;

while(press!='n' && press!='N')

{

myButton.Press();

cout << " [myButton was pressed.] ";

cout << "Now, the current pressed count of myButton is "<< myButton.TimesPressed()<< endl;

cout << "Do you want to press myButton again?(y/n): ";

cin >> press;

cout << endl;

}

cout << "Now, the current pressed count of myButton is "<< myButton.TimesPressed() << endl;

cout << endl;

Date today;

Date someDay;

int month,day,year;

cout<<"The default constructor date is ";

today.DisplayNumerically();

cout << " or ";

today.DisplayTextually();

cout << ". ";

cout << "Enter a date(mm dd yy): ";

cin >> month >> day >> year;

someDay.SetDate(year,month,day);

cout << endl;

cout << " DisplayNumerically ";

someDay.DisplayNumerically();

cout << endl;

cout << " DisplayTextually ";

someDay.DisplayTextually();

cout << ". ";

return 0;

}





Explanation / Answer

//hey, i recongnize my code :3

//here is the definition of the extended fxn of class Date

//make sure you put their repective prototype inside of class Date

void Date::DisplayTextEuropean(){

string Month[12] = {"January", "February", "March","April", "May", "June", "July","August", "September", "October","November", "December"};

cout<<day<<Month[month-1]<<" "<<", "<<year;

}


void Date::AdvanceOneDay(){


day++;//increment day first


//now normalize to real date


//take account for end of year

if(month==12 && day>31){

month=1;

day=1;

year+=1;

}


//take account new month

if(day>31){

month++;

day=1;

}


// take account that certain days max out at 30 days

if((day==31)&&((month==4)||(month==6)||(month==9)||(month==11))){

month++;

day=1;

}


//normalize to 12 months

if(month>12){

month-=12;

year++;

}


//take account of leap year

if((month==2 && day>28)&& !((year % 4 == 0 && year % 100 != 0) || ( year % 400 == 0))){

month=3;

day-=28;

}

return;


}

void Date::AdvanceDays(int n){

for(int i=0;i<n;i++){

AdvanceOneDay();

}

return;

}