In: Computer Science
Kindly Do the program in C++ language Object Oriented
Programming.
Objectives
Implement a simple class with public and private members and
multiple
constructors.
Gain a better understanding of the building and using of classes
and objects.
Practice problem solving using OOP.
Overview
You will implement a date and day of week calculator for the
SELECTED calendar year.
The calculator repeatedly reads in three numbers from the standard
input that are
interpreted as month, day of month, days after, calculates the
dates in the year and days of
week for the dates, and outputs the information. For example, input
“1 1 31” is interpreted
as the following: the first 1 means the 1st month in the year,
January; the second 1 means
the 1st day in January; and the 31 means 31 days after the date
January 1, 2013 (we assume
the year is 2013 to simplify the program), which is February 1,
2013. The program also
calculates the days of week for each of the dates. More
specifically, for input “1 1 31”, the
calculator should produce the following output:
“31 days after Tuesday, January 1, 2013 is Friday, February 1,
2013. “
The first input number must be from 1 to 12 representing the 12
months a particular
SELECTED year, the second input number must be a day in the month
(e.g. for 1-31 for
January, 1-28 for February (for year 2013), and so forth). The
third number is larger than
or equal to 0. The program should report an error (and exit) if the
input is incorrect. If a
day is not in a particular selected year, the program should output
that. Following are a
sample input file (redirect to be the standard input) and the
corresponding output for year
2013.
Input file:
1 1 20
1 1 31
2 1 0
1 1 32
4 5 0
2 1 28
1 1 59
6 10 100
7 20 300
12 20 2
Output:
20 days after Tuesday, January 1, 2013 is Monday, January 21,
2013.
31 days after Tuesday, January 1, 2013 is Friday, February 1,
2013.
0 days after Friday, February 1, 2013 is Friday, February 1,
2013.
32 days after Tuesday, January 1, 2013 is Saturday, February 2,
2013.
0 days after Friday, April 5, 2013 is Friday, April 5, 2013.
28 days after Friday, February 1, 2013 is Friday, March 1,
2013.
59 days after Tuesday, January 1, 2013 is Friday, March 1,
2013.
100 days after Monday, June 10, 2013 is Wednesday, September 18,
2013.
300 days after Saturday, July 20, 2013 is a date not in 2013.
2 days after Friday, December 20, 2013 is Sunday, December 22,
2013.
#include<bits/stdc++.h>
using namespace std;
vector<string> months(15);
vector<int> day(15);
vector<string>
week={"Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday","Monday"};
class Date
{
public:
string month;
int dinak,year;
};
class calendar
{
private:
int days;
public:
void setdata(int
x)
{
days=x;
}
string dayofweek()
{
int rem=days%7;
return week[rem];
}
Date fn()
{
Date D;
int i=1;
while(1)
{
if(days>(day[i]))
{
days-=day[i];
i+=1;
}
else
{
D.month=months[i];
D.dinak=days;
D.year=2013;
return D;
}
}
}
};
int main()
{
int i,total,a,b,c;
months[0]="0";
months[1]="January";months[2]="February";months[3]="March";months[4]="April";months[5]="May";months[6]="June";months[7]="July";months[8]="August";
months[9]="september";months[10]="October";months[11]="November";months[12]="December";
day[0]=0;
day[1]=31;day[3]=31;day[5]=31;day[7]=31;day[9]=30;day[11]=30;
day[2]=28;day[4]=30;day[6]=30;day[8]=31;day[10]=31;day[12]=31;
cout<<"Enter
months,date,days"<<endl;
cin>>a>>b>>c;
for(i=1;i<a;i++)
{
total+=day[i];
}
total+=b;
total-=1;
calendar C;
C.setdata(total);
Date X;
X=C.fn();
total+=c;
//cout<<total<<endl;
if(total<=364)
{
cout<<c<<"
days after "<<C.dayofweek()<<",";
total+=1;
total-=c;
C.setdata(total);
X=C.fn();
cout<<X.month<<" "<<X.dinak<<" ,
"<<"2013 is ";
total-=1;
total+=c;
C.setdata(total);
string
ans=C.dayofweek();
total+=1;
C.setdata(total);
X=C.fn();
cout<<ans<<"
, "<<X.month<<" "<<X.dinak<<",
2013"<<endl;
}
else
cout<<c<<" days after Tuesday 1,2013
is a date in 2013"<<endl;
return 0;
}