In: Computer Science
In C++
Create a class that simulates a school calendar for a course and has a warner that provides the school administration with the option of warning students when the last day is that a student is permitted to drop the course. (Allow administrators to warn or not, as they wish. Do not make this a required function.)
You will assume in this calendar that there are 12 months in a year, 4 weeks in a month, and 7 days in a week. You can represent any day by 3 numbers. For example 12/3/2 would represent the 2nd day in the 3rd week of the 12th month. In this class you should:
Store a calendar day in terms of month, week, and day. (You should represent the month from 1 to 12, week from 1 to 4, and day from 1 to 7.)
Initialize the calendar to a specified day. (For example, you can initialize the calendar to 1/1/1.)
Allow the calendar to increment to the next day. (Hint: You need to take into account things such as whether the calendar is at the 3rd week, 6th day. Then you may need to consider iterated if statements.) In addition, you need to prevent the possibility of going beyond the 12th month, 4th week, and 7th day.
Set the warner and have the warner print out "TODAY IS THE LAST DAY TO DROP THE COURSE" when the set date is reached. (Hint: You may wish to create a private function that provides the wished-for printout when the date is reached and the warner is on.)
Display the present date.
Use the class in a program that uses the functions requiring displaying of time and setting of the warner.
Include 2 constructors. One constructor should be the default constructor that will initialize the object to 1/1/1. The second constructor should take parameters for months, weeks, and days. Both constructors will provide the private members with the date. In addition, have both constructors set the warner as off. (You will need a Boolean attribute that determines whether the warner is on or off. The administrators have the option of using the warner. They do not have to provide a warning to students if they do not wish to. In fact, the constructor should set the default as the warner is off and will not provide a warning to students.) The function or method you use to set the warner will set the warner on. (Hint: Have the class also have attribute of month, week, and day and the ability to be on or off with a Boolean variable for the warner.)
Output: Students should develop the output for this assignment to be as clear and concise as possible. Provide as much detail as possible in regards to the dates and corresponding calendar timeline.
#include<iostream>
#include<string>
using namespace std;
//schoolCalender class
class schoolCalender
{
//private variables
int month;
int week;
int day;
bool warner;
public:
//Default constructor
schoolCalender(){
month=1;
week=1;
day=1;
warner=false;
}
//Parameterised constructor
schoolCalender(int month, int week,int day) {
month=month;
week=week;
day=day;
warner=false;
}
//To set date
void setDate(int month, int week,int day){
this->month=month;
this->week=week;
this->day=day;
}
//To increment date
void incrementDate(){
//calling method to increment the date
incrementMonth();
incrementWeek();
incrementDay();
}
void incrementMonth(){
if(month==12)
month=1;
else
month++;
}
void incrementWeek()
{
if(week==4)
week=1;
else
week++;
}
void incrementDay()
{
if(day==7)
day=1;
else
day++;
}
//checking two dates are equal or not
bool isLastDate(schoolCalender sc )
{
if(this->month==sc.month &&
this->week==sc.week && this->day==sc.day )
{
warner=true;
return true ;
}
else
false;
}
//returns waner value
bool returnWarner()
{
return warner;
}
//Display date
void display(){
cout<<"MM/WW/DD:"<<month<<"/"<<week<<"/"<<day;
}
};
int main(){
//school date
schoolCalender schoolDate;
schoolDate.setDate(12,4,3);
//school last date
schoolCalender lastDate;
lastDate.setDate(12,4,3);
//cheking whether the school date is last date
schoolDate.isLastDate(lastDate);
//if waner boolean value is true then this message will
print
if(schoolDate.returnWarner())
cout<<"TODAY IS THE LAST DAY TO DROP THE
COURSE"<<endl;
//Incrementing the date
cout<<"Date before incrementing school date
";
schoolDate.display();
cout<<"\nDate after incrementing school date ";
schoolDate.incrementDate();
schoolDate.display();
cout<<endl;
system("pause");
return 0;
}
OUTPUT:
TODAY IS THE LAST DAY TO DROP THE COURSE
Date before incrementing school date MM/WW/DD:12 / 4 / 3
Date after incrementing school date MM/WW/DD:1 / 1 / 4
press any key to continue . . . . .
HOPE U LIKE THIS ANSWER