please use c ++ language and do it Asap. thank you. - US ONLY CIS 25- Fall 2017-
ID: 3605182 • Letter: P
Question
please use c ++ language and do it Asap. thank you.
- US ONLY CIS 25- Fall 2017- PROGRAMMING QUESTION (10 points) A) Write Date, Time, and DateTime classes, as follows: 1. Date has year, month, and day member variables. 2. Time has hour, minute, and second member variables. 3. DateTime is an aggregate of Date and Time . Date Time has a redefined operator, which computes the number of seconds between two DateTime objects Assume all months have 30 days, all years have 360 days, and Time objects are on a 24-hour clock (no AM and PM), B) Write a main program that creates two Date Time objects and displays the number of between them, using the redefined operator.Explanation / Answer
#include <iostream>
using namespace std;
//Create a class named Date with members year, month and day.
class Date {
int year;
int month;
int day;
public:
Date(){
}
//Constructor for creating a date object
Date(int y, int m, int d) {
year = y;
month = m;
day = d;
}
};
//Create a class Time Date with members hour, minute and second
class Time {
int hour;
int minute;
int second;
public:
Time(){
}
//Constructor for creating a time object.
Time(int h, int m, int s) {
hour = h;
minute = m;
second = s;
}
//This method would return the seconds of the current time object.
int getSeconds(){
return second;
}
};
class DateTime {
Date date;
Time time;
public:
DateTime() {
}
DateTime(Date d, Time t){
date = d;
time = t;
}
Time getTime(){
return time;
}
//Overriding the operator - and it would print the diffrence in seconds of two objects.
void operator - (DateTime& obj) {
cout<<"The difference between seconds is :" << time.getSeconds() - obj.getTime().getSeconds();
}
};
int main() {
// your code goes here
//The first DateTime object.
DateTime dateTime1 = DateTime(Date(12,12,2016), Time(12,44,46));
//The second DateTime object.
DateTime dateTime2 = DateTime(Date(12,12,2016), Time(12,44,23));
//This expression would print out the difference b/w two time objects' seconds value.
dateTime1 - dateTime2;
return 0;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.