Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Project Modify the Date Class: Standards Your program must start with comments giving your name and the name of the assignment. Your program must

C++ Project Modify the Date Class:

Standards

Your program must start with comments giving your name and the name of the assignment.

Your program must use good variable names.

All input must have a good prompt so that the user knows what to enter.

All output must clearly describe what is output.

Using the date class, make the following modifications:

Make the thanksgiving function you wrote for project 1 into a method of the Date class. It receive the current year and returns the date for Thanksgiving.

In the Date class there are only a few overloaded operators for comparison. Add all of the following: <=, >=, and !=

Add a method to return the season as an integer: 0=winter, 1=spring, 2=summer and 3=fall for the northern hemisphere.

Your main program should illustrate the use of each method.

You may use March 20th for the first day of Spring. Use June 20th for the first day of summer, September 22 for the first day of fall, and December 21 as the first day of winter. You will find the overloaded operators handy for this. A nice solution for this is to use an array to store the first date for each season, then loop to see where a date falls.

Main.cpp

#include "Date.h"

#include

using namespace std;

// Start of main

void bubbleSort(Date date[], int n)//is an array of dates and is the size of the array

{

int i, j;

for (i = 0; i < n - 1; i++)

// Last i elements are already in place

for (j = 0; j < n - i - 1; j++)

if (date[j] > date[j + 1])

{

Date temp = date[j];

date[j] = date[j + 1];

date[j + 1] = temp;

}

}

int main() {

// Declare arrays and variables

const int SIZE = 7; // Size of array elements

const int COUNT = 6; // Number of holidays

Date weekDays[SIZE]; // Weekday array

Date holidays[COUNT]; // Holiday array

string holidaysDescription[COUNT];

int year = 0;

Date easterSunday(04, 01, 2018); // Easter Sunday

holidays[0] = easterSunday;

holidaysDescription[0] = "Easter Sunday";

Date mothersDay(05, 13, 2018); // Mother's Day

holidays[1] = mothersDay;

holidaysDescription[1] = "Mother's Day";

Date memorialDay(05, 28, 2018); // Memorial Day

holidays[2] = memorialDay;

holidaysDescription[2] = "Memorial Day";

Date fathersDay(06, 17, 2018); // Fathers Day

holidays[3] = fathersDay;

holidaysDescription[3] = "Father's Day";

Date independenceDay(07, 04, 2018); // Independence Day

holidays[4] = independenceDay;

holidaysDescription[4] = "Independence Day";

// Prompt the user for current year

cout << "Please enter the current year: ";

cin >> year;// Read in year

cout << " ";

// Search for the date of Thanksgiving and add it to

// the holiday array

Date giveThanks = giveThanks.thanksGiving(year);

holidays[5] = giveThanks;

holidaysDescription[5] = "Thanksgiving";

bubbleSort(holidays, COUNT);//Sort the list of the array

cout << "The holidays are sorted by date: ";

for (int index = 0; index < COUNT; index++)

{

// Display the holiday

int day = holidays[index].weekday();

cout << holidaysDescription[index] << " is on " << holidays[index] << " which falls on a ";

// Display the day

switch (day) {

case 0: cout << "Sunday" << endl; break;

case 1: cout << "Monday" << endl; break;

case 2: cout << "Tuesday" << endl; break;

case 3: cout << "Wednesday" << endl; break;

case 4: cout << "Thursday" << endl; break;

case 5: cout << "Friday" << endl; break;

case 6: cout << "Saturday" << endl; break;

}

}

system("pause");

return 0;

}

Thanksgiving equation:

Date Date::thanksGiving(int year)

{

Date turkeyDay(11, 01, year);

while (turkeyDay.weekday() != 4)

{

turkeyDay = turkeyDay + 1;

}

turkeyDay = turkeyDay + 21;

return turkeyDay;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Describe the responsibilities of a change management board.

Answered: 1 week ago

Question

(1 point) Calculate 3 sin x cos x dx.

Answered: 1 week ago

Question

Consistently develop management talent.

Answered: 1 week ago

Question

Create a refreshed and common vision and values across Europe.

Answered: 1 week ago

Question

Provide the best employee relations environment.

Answered: 1 week ago