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 <iostream>
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 << "\n";
// 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: \n";
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;
}
//Date.h
#ifndef Date_H
#define Date_H
#include <iostream>
#include <sstream>
#include <ctime>
#include <string>
using namespace std;
class Date {
private:
int month, day, year;
int days[13];
public:
//constructors
Date(); //constructor for todays date
Date(int m, int d, int y); //constructor to assign date
Date(string str); //constructor for todays date as
"mm/dd/year
Date(int gregorian); //constructor to convert a Gregorian date to
Date
//methods
int getMonth() const; //returns the private variable month
int getDay() const; //returns the private variable day
int getYear() const; //returns the private variable year
string toString() const; //returns the string mm/dd/yyyy
bool leapYear() const; //determines if the year is a leap
year
int dayofYear() const; //returns the day of the year: ie 2/1/????
is the 32 day of year
int julian() const;
int weekday() const; //returns 0 for Sunday, 1 for Monday, etc.
//overloaded operators
bool operator==(const Date& otherDate); //2 dates are equal if
month, day and year are equal
bool operator<(const Date& otherDate); //a date is <
another date if it is earlier
bool operator>(const Date& otherDate); //a date is >
another date if it is later
bool operator>=(const Date& otherDate); //a date is >
another date if it is later
bool operator<=(const Date& otherDate); //a date is >
another date if it is later
bool operator!=(const Date& otherDate); //a date is >
another date if it is later
Date operator=(const Date& otherDate); //let's you copy one
date to another.
Date operator+(int); //Assign new values to the date after adding
the number of days
friend ostream& operator << (ostream &output, const
Date &d);
friend istream& operator >> (istream &input, Date
&d);
Date thanksGiving();
int season();
};
bool validDate(int m, int d, int y); //test other date
bool leapYear(int y); //let's you test any year, not just the year
for the instance
int julian(int m, int d, int y); //convert any date to Julian
void gregorian(int jd, int &mth, int &d, int &y);
static int days2[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
#endif
//******************************************************************
//Date.cpp
#include "Date.h"
#include <ctime>
Date::Date() {
//constructor to assign todays date to date
char data[9]; //holder for the date
_strdate(data); //gets the current date mm/dd/yy
string date(data); //copy to a string for parsing
if(date[0]=='0')
month = stoi(date.substr(1,1));
else
month = stoi(date.substr(0,2));
//gets characters 0 and 1 of date and converts to int
if(date[3]=='0')
day = stoi(date.substr(4,1));
else
day = stoi(date.substr(3,2));
//day=stoi(date.substr(3,2)); //gets characters 3 and 4 of date and
converts to int
year=stoi(date.substr(6,2))+2000; //gets characters 6 and 7 of date and converts to int
if(leapYear()) days2[2]=29; else days2[2]=28;
for(int m=0;m<13;m++) days[m]=days2[m];
}//constructor for today
bool validDate(int m, int d, int y) {
bool valid=true; //assume it is valid until found to be invalid
if(y<1000) valid=false;
if(m<1 || m>12) valid=false;
if(leapYear(y)) days2[2]=29; else days2[2]=28;
if(d<1 || d>days2[m]) valid=false;
return valid;
}//validDate
Date::Date(int m, int d, int y) {
//constructor to assign values to month day and year
if(validDate(m,d,y)) {
month=m;
day=d;
year=y;
}
else {
month=day=1;
year=1970; //Unix time starting point
} //not valid: set to default valid date
for(int m=0;m<13;m++) days[m]=days2[m];
} //constructor with assigned values
Date::Date(int julian) {
//Fliegel-Van Flandern algorithm to convert Julian date to Gregorian number month, day, and year
gregorian(julian,month,day,year);
if(leapYear()) days2[2]=29; else days2[2]=28;
for(int m=0;m<13;m++) days[m]=days2[m];
}//Date Julian
Date::Date (string str) { //constructor for todays date as "mm/dd/year
//Parse str by adding one char at a s time to the token until a "/" is encounter.
//When "/" is encountered start the next token
//int p=0;
int count=0;
int num[3];
string token[3];
int len=str.length();
for(int p=0; p<len;p++) {
if(str.substr(p,1)=="/") count++;
else token[count]+=str.substr(p,1);
}//parse str to create array of tokens
bool error=false;
for(int p=0;p<3;p++) {
try {
num[p]=stoi(token[p]);
}//try to convert to int
catch(invalid_argument&) {
num[p]=-1;
error=true;
} //catch
}//each of the 3 tokens
if(!error && validDate(num[0],num[1],num[2])) {
month=num[0];
day=num[1];
year=num[2];
} //no error
else {
month=day=1;
year=1970; //Unix time starting point
} //not valid: set to default valid date
for(int m=0;m<13;m++) days[m]=days2[m];
}//constructor with string such as "10/31/2016"
Date Date::operator=(const Date& otherDate) {
//assigns another instance of the date class to this.
month=otherDate.month;
day=otherDate.day;
year=otherDate.year;
return *this; //allows date1=date=date3;
}//overloaded operator =
Date Date::operator+(int numDays) {
//Adds the number of days to the Julian date.
Date other(month,day,year); //make copy of the date
int jd=other.julian(); //find the Julian date
jd+=numDays; //add the number of days to the Julian date
gregorian(jd,other.month,other.day,other.year); //Convert the Julian date back to Gregorian
if(other.leapYear()) days2[2]=29; else days2[2]=28;
for(int m=0;m<13;m++) other.days[m]=days2[m];
return other;
} //operator +
int Date::dayofYear() const {
//returns the day of the year, ie 2/1/???? is the 32 day of the year
int total=day;
for(int m=1;m<month;m++) total+=days[m];
return total;
}//dayofYear
void gregorian(int julian, int &mth, int &d, int &y) {
//Fliegel-Van Flandern algorithm to convert Julian date to Gregorian month, day, and year
int p,q,r,s,t,u,v;
p = julian + 68569;
q = 4*p/146097;
r = p - (146097*q + 3)/4;
s = 4000*(r+1)/1461001;
t = r - 1461*s/4 + 31;
u = 80*t/2447;
v = u/11;
y = 100*(q-49)+s+v;
mth = u + 2 - 12*v;
d = t - 2447*u/80;
} //Gregorian
int Date::julian() const {
int jd= day-32075+1461*(year+4800+(month-14)/12)/4+
367*(month-2-(month-14)/12*12) /12-3*((year+4900+(month-14)/12)/100)/4;
return jd;
}
bool Date::leapYear() const {
bool leap=false;
if(year%4==0) leap=true;
if(year%100==0 && year%400!=0) leap=false;
return leap;
}//leapYear
bool leapYear(int yr) {
bool leap=false;
if(yr%4==0) leap=true;
if(yr%100==0 && yr%400!=0) leap=false;
return leap;
}//leapYear
int Date::weekday() const {
//returns 0 for Sunday, 1 for Monday, etc.
static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
int y =year;
y-= month < 3;
return ( y + y/4 - y/100 + y/400 + t[month-1] + day) % 7;
}//weekday
int Date::getMonth() const {
//private variables cannot be accessed directly but require "getter" functions
return month;
}//getMonth
int Date::getDay() const {
return day;
}//
int Date::getYear() const {
return year;
}//getYear
string Date::toString() const {
stringstream oss; //a stream to append the values
oss<<month<<"/"<<day<<"/"<<year;
return oss.str();
}
bool Date::operator==(const Date& otherDate) {
return (month==otherDate.month && day==otherDate.day && year==otherDate.year);
}//operator ==
bool Date::operator<(const Date& otherDate) {
//A date is less than another date if is earlier
bool result=false; //assume false until proven true
if(year<otherDate.year) result=true;
else if(year==otherDate.year && month<otherDate.month) result=true;
else if(year==otherDate.year && month==otherDate.month && day<otherDate.day) result=true;
return result;
}//operator
bool Date::operator>(const Date& otherDate) {
//Convert both dates to Julian and compare the Julian dates
int jd1=julian();
int jd2=otherDate.julian();
return jd1>jd2;
}//operator
bool Date::operator<=(const Date& otherDate) {
//Convert both dates to Julian and compare the Julian dates
int jd1=julian();
int jd2=otherDate.julian();
return jd1<=jd2;
}//operator
bool Date::operator>=(const Date& otherDate) {
//Convert both dates to Julian and compare the Julian dates
int jd1=julian();
int jd2=otherDate.julian();
return jd1>=jd2;
}//operator
bool Date::operator!=(const Date& otherDate) {
//Convert both dates to Julian and compare the Julian dates
int jd1=julian();
int jd2=otherDate.julian();
return jd1!=jd2;
}//operator
ostream& operator << (ostream &output, const Date &d) {
output << d.toString();
return output;
} // operator <<
istream& operator >> (istream &input, Date &d) {
string s;
input >> s;
Date other(s); //create a new Date
d=other; //assign the new Date to d
return input;
} // operator >>
Date Date::thanksGiving()
{
Date turkeyDay(11, 01, year);
while (turkeyDay.weekday() != 4)
{
turkeyDay = turkeyDay + 1;
}
turkeyDay = turkeyDay + 21;
return turkeyDay;
}
int Date::season()//returns integer representing seasons
{
Date spring = {3,20,getYear()};//declare date for spring
Date summer = {6,20,getYear()};//declare date for summer
Date fall = {9,22,getYear()};//declare date for fall
Date winter = {12,21,getYear()};//declare date for winter
if(*this < spring)//if before spring then winter
return 0;
else if(*this < summer)//if before summer then spring
return 1;
else if(*this < fall)//if before fall then summer
return 2;
else if(*this < winter)//if before winter then fall
return 3;
else//else winter
return 0;
}
//************************************************************
//main.cpp
#include "Date.h"
#include <iostream>
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 << "\n";
// Search for the date of Thanksgiving and add it to
// the holiday array
Date currentYear = {1,1,2018};
Date giveThanks = currentYear.thanksGiving();
holidays[5] = giveThanks;
holidaysDescription[5] = "Thanksgiving";
bubbleSort(holidays, COUNT);//Sort the list of the array
cout << "The holidays are sorted by date: \n";
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;
}
}
for (int index = 0; index < COUNT; index++)
{
cout << holidays[index] << " is season " <<
holidays[index].season()<<endl;
}
system("pause");
return 0;
}
//*********************************************************
Output:

I have implemented the required functions. Please go through the updated header and cpp files.
Please give this solution a thumbs up if you find it helpful.
If you have any queries or issues with the above solution, kindly let me know in the comments instead of downvoting the solution. I would be happy to help you.
Thank you.
C++ Project Modify the Date Class: Standards Your program must start with comments giving your name...
-can you change the program that I attached to make 3 file
songmain.cpp , song.cpp , and song.h
-I attached my program and the example out put.
-Must use Cstring not string
-Use strcpy
- use strcpy when you use Cstring: instead of this->name=name
.... use strcpy ( this->name, name)
- the readdata, printalltasks, printtasksindaterange,
complitetasks, addtasks must be in the Taskmain.cpp
- I also attached some requirements below as a picture
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>...
fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str; while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title); getline(inFile, books[size].Author); getline(inFile, books[size].publisher); getline(inFile,...
for the following code I need the source code and output screenshot (includes date/time) in a PDF format. I keep getting an error for the #include "dayType.hpp" dayType.cpp #include"dayType.hpp" string dayType::weekday[7] = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat" }; //set the day void dayType::setDay(string day){ cout << "Set day to: " ; cin >> dayType::day; for(int i=0; i<7; i++) { if(dayType::weekday[i]==dayType::day) { dayType::markDay = i; } } } //print the day void dayType::printDay() { cout << "Day = "...
Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public: static string weekDays[7]; void print() const; string nextDay() const; string prevDay() const; void addDay(int nDays); void setDay(string d); string getDay() const; dayType(); dayType(string d); private: string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...
Convert the TreeArray C++ source code(posted below) into a BinaryTree, using this TreeNode definition: class TreeNode<T> T data TreeNode<T> left TreeNode<T> right Since this TreeNode is a generic Template, use any data file we've used this quarter to store the data in the BinaryTree. To do this will likely require writing a compare function or operator. Hint: Think LEFT if the index is calculate (2n+1) and RIGHT if index is (2n+2). Source code: #include<iostream> using namespace std;...
moviestruct.cpp
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef struct{
int id;
char title[250];
int year;
char rating[6];
int totalCopies;
int rentedCopies;
}movie;
int loadData(ifstream &infile, movie movies[]);
void printAll(movie movies[], int count);
void printRated(movie movies[], int count);
void printTitled(movie movies[], int count);
void addMovie(movie movies[],int &count);
void returnMovie(movie movies[],int count);
void rentMovie(movie movies[],int count);
void saveToFile(movie movies[], int count, char *filename);
void printMovie(movie &m);
int find(movie movies[], int...
Modify this C++ below to show the selection sorting algorithm method. Then write a test program and show that it works. HINT: Replace the bubbleSort function with the selectionSort. Your test program should perform the following steps: Create an array of random numbers. Display the array in its original order. Pass the array to your sorting function. Display the array again to show that it has been sorted. Provide a screen shot showing that the above steps are working. CODE:...
howthe output of the following 4 program segments (a) const int SIZE=8; int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8}; int index; index=0; res = values[index]; for (int j=1; j<SIZE; j++) { if (values[j] > res) { res = values[j]; index = j; cout << index << res << endl; } } cout <<...
The following program contains the definition of a class called List, a class called Date and a main program. Create a template out of the List class so that it can contain not just integers which is how it is now, but any data type, including user defined data types, such as objects of Date class. The main program is given so that you will know what to test your template with. It first creates a List of integers and...
Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender { MyDate myDate; Day day; enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter date below :"); System.out.println("Enter day :"); int day = sc.nextInt(); System.out.println("Enter Month :"); int month = sc.nextInt(); System.out.println("Enter year :"); int year = sc.nextInt(); MyDate md = new MyDate(day, month, year); if(!md.isDateValid()){ System.out.println("\n Invalid date . Try...