Final answer:
To design the class called Date, you can start by defining three private member variables: month, day, and year. Then you can create constructor functions to initialize these variables and member functions to print the date in different formats. Demonstrating the class can be done by writing a complete program that includes the main function which creates an instance of the Date class and calls the member functions to print the date in various formats.
Step-by-step explanation:
To design the class called Date, you can start by defining three private member variables: month, day, and year. Then you can create constructor functions to initialize these variables and member functions to print the date in different formats. Here is an example implementation:
#include <iostream>
#include <string>
using namespace std;
class Date {
private:
int month;
int day;
int year;
public:
Date(int m, int d, int y) {
month = m;
day = d;
year = y;
}
void printDate1() {
cout << month << "/" << day << "/" << year << endl;
}
void printDate2() {
string monthName;
switch(month) {
case 1:
monthName = "January";
break;
case 2:
monthName = "February";
break;
//more cases for other months
}
cout << monthName << " " << day << ", " << year << endl;
}
void printDate3() {
string monthName;
switch(month) {
case 1:
monthName = "January";
break;
case 2:
monthName = "February";
break;
//more cases for other months
}
cout << day << " " << monthName << " " << year << endl;
}
};
int main() {
Date date(12, 25, 2018);
date.printDate1();
date.printDate2();
date.printDate3();
return 0;
}