The purpose of this C assignment is to show students a simpl
The purpose of this C++ assignment is to show students a simple class that they can practice with.
//DISPLAY 10.3 Class with a Member Function
//Program to demonstrate a very simple example of a class.
//A better version of the class DayOfYear will be given in Display 10.4.
#include
using namespace std;
class DayOfYear
{
public:
void output( );
int month;
int day;
};
int main( )
{
DayOfYear today, birthday;
cout << \"Enter today\'s date:\ \";
cout << \"Enter month as a number: \";
cin >> today.month;
cout << \"Enter the day of the month: \";
cin >> today.day;
cout << \"Enter your birthday:\ \";
cout << \"Enter month as a number: \";
cin >> birthday.month;
cout << \"Enter the day of the month: \";
cin >> birthday.day;
cout << \"Today\'s date is \";
today.output( );
cout << \"Your birthday is \";
birthday.output( );
if (today.month == birthday.month
&& today.day == birthday.day)
cout << \"Happy Birthday!\ \";
else
cout << \"Happy Unbirthday!\ \";
return 0;
}
//Uses iostream:
void DayOfYear::output( )
{
cout << \"month = \" << month
<< \", day = \" << day << endl;
}
Please make following changes and submit program file (.cpp) and output file.
1. Add variable named \'year\' to the class program.
2. Add class function named \'formatted_output\' which will be similar to \'output\'.
3. The function \'formatted_output\' should format date as (MM/DD/YYYY). See image below:
4. Call formatted_output right after function \'output\' is called.
Enter today\'s date Enter month a a number: 08 Enter the day of the month: 10 Enter the year as a number: 2016 Enter your birthday: Enter month a a number 8 Enter the day of the month: 10 Enter year as a number 1978 Today date is month 8, day 10 date is 8/10/2016 Your birthday i month 8, day 10 date is 8/10/1978 Happy Birthday! Press any key to continueSolution
#include <iostream>
using namespace std;
class DayOfYear
{
public:
void output( );
int month;
int day;
int year;
};
int main( )
{
DayOfYear today, birthday;
cout << \"Enter today\'s date:\ \";
cout << \"Enter month as a number: \";
cin >> today.month;
cout << \"Enter the day of the month: \";
cin >> today.day;
cout << \"Enter year as a number: \";
cin >> today.year;
cout << \"Enter your birthday:\ \";
cout << \"Enter month as a number: \";
cin >> birthday.month;
cout << \"Enter the day of the month: \";
cin >> birthday.day;
cout << \"Enter year as a number: \";
cin >> birthday.year;
cout << \"Today\'s date is \";
today.output( );
cout << \"Your birthday is \";
birthday.output( );
if (today.month == birthday.month
&& today.day == birthday.day && today.year == birthday.year)
cout << \"Happy Birthday!\ \";
else
cout << \"Happy Unbirthday!\ \";
return 0;
}
//Uses iostream:
void DayOfYear::output( )
{
cout << \"year = \" << year << \", month = \" << month
<< \", day = \" << day;
cout << \"\ date is \" << month << \"-\" << day << \"-\" << year << \"\ \";
}


