Answer to Question #124319 in C++ for Barsha Shakya

Question #124319
2. Write the class definition for a Date class that contains three integer data members: month, day, and year. Include a default constructor that assigns the date 1/1/2000 to any new object that does not receive arguments. Also include a function that displays the Date object. Write a main() function in which you instantiate two Date objects—one that you create using the default constructor values, and one that you create using three arguments—and display its values. Save the file as Date.cpp
1
Expert's answer
2020-06-29T08:42:10-0400
#include <iostream>




class Date

{

int month;

int day;

int year;




 public:




Date()

  :month(1), day(1), year(2000)

{

}




Date(int Month, int Day, int Year)

  :month(Month), day(Day), year(Year)

{

}




void Display() const

{

std::cout << month << "/" << day << "/" << year;

}

};




int main()

{

Date date1;

Date date2(6, 29, 2020);




std::cout << "Date1: "; date1.Display(); std::cout << "\n";

std::cout << "Date2: "; date2.Display(); std::cout << "\n";

  return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS