Please implement the following problem in basic C++ code and include detailed co
ID: 3589022 • Letter: P
Question
Please implement the following problem in basic C++ code and include detailed comments so that I am able to understand the processes for the solution. Thanks in advance.
// Day.h
// Question1.cpp
Please review Day.h" and "Question1.cpp". The header provides the complete declaration for the Day class. Without modifying the declaration, complete the methods of the class and use Question.cpp to verify your implementation. The output should match the example below. Example 1: Default Constructor: SUN Thursday Constructor THU Added 5 days to Thursday: TUE Tomorrow is: WED Yesterday was: MON Press any key to continue .. .Explanation / Answer
CODE
#include<string>
using namespace std;
class Day {
public:
Day(){ /* Default constructor */
_day = "SUN";
}
Day(string day){ /* Parameterized constructor */
_day = day;
}
/*
* Sets the current day to newDay
* value must be in the range:
* "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"
*/
void setDay(string day){
_day = day;
}
/*
* Gets the current day, values will be in the range:
* "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"
*/
string getDay(){
return _day;
}
/*
* Increments the current day by numDays
*/
void addDays(int numDays){
int index = getIdx(_day);
index = (index + numDays) % 7;
_day = getStr(index);
}
/* Returns the next day */
string nextDay(){
int index = getIdx(_day);
if(index == 7)
index = 0;
else
index++;
return getStr(index);
}
/* Returns the previous day */
string prevDay(){
int index = getIdx(_day);
if(index == 0)
index = 7;
else
index--;
return getStr(index);
}
private:
string _day;
int getIdx(string day){
// Returning index based on string
if(day == "SUN")
return 1;
else if(day == "MON")
return 2;
else if(day == "TUE")
return 3;
else if(day == "WED")
return 4;
else if(day == "THU")
return 5;
else if(day == "FRI")
return 6;
else if(day == "SAT")
return 7;
}
string getStr(int idx){
// Returning day based on index
if(idx == 0)
return "SUN";
else if(idx == 1)
return "MON";
else if(idx == 2)
return "TUE";
else if(idx == 3)
return "WED";
else if(idx == 4)
return "THU";
else if(idx == 5)
return "FRI";
else
return "SAT";
}
};
// Question1.cpp
#include<iostream>
#include"Day.h"
using namespace std;
int main(void) {
Day dflt, thu("THU");
cout << "Default Constructor: " << dflt.getDay()<< endl;
cout << "Thursday Constructor: " << thu.getDay()<< endl;
thu.addDays(5);
cout << "Added 5 days to Thursday: " << thu.getDay()<< endl;
cout << "Tomorrow is: " << thu.nextDay() << endl;
cout << "Yesterday was: " << thu.prevDay() << endl;
}
IF ANY QUERIES REGARDING CODE PLEASE GET BACK TO ME
THANK YOU