https://www.dropbox.com/sh/kfztz25zggqjwg0/AAAlEfj6rWfv7pDFvL_SmS2Ma?dl=0 Link t
ID: 3564945 • Letter: H
Question
https://www.dropbox.com/sh/kfztz25zggqjwg0/AAAlEfj6rWfv7pDFvL_SmS2Ma?dl=0
Link to Chrono.h and Chrono.cpp
Start with Chrono.h and Chrono.cpp in section 9.8; for
now put a dummy "return sunday;" or "return d;" in the last 3 functions on
pages 337-338. Add a prefix ++ operator to the Date class by putting the
declaration in the Date class in Chrono.h and the definition in Chrono.cpp.
The prefix ++ operator should change a date to "tomorrow" using the following
pseudocode:
Date& operator++(){
//add 1 to d //tomorrow, unless we were at the end of the month
//if is_date is false
// //need to change to first of next month
// set d to 1
// if m is December
// //need to change to next year too
// set m to January
// increment y
// else
// increment m
return *this;
}
Write a main in hw5pr3.cpp which repeatedly reads a Date with
cin >>, increments the Date with your ++, and prints "Tomorrow is" and the
new value of the Date using cout <<.
Explanation / Answer
Date& Date::operator++()
{
//add 1 to d //tomorrow, unless we were at the end of the month
++d;
//if is_date is false
if (is_date == false){
// //need to change to first of next month
// set d to 1
d = 1;
// if m is December
if(m == dec){
// //need to change to next year too
// set m to January
m = jan;
// increment y
++y;
}
// else
else {
m = Month(int(m) + 1);
}
}
// increment m
return *this;
}
main function:-
#include "stdafx.h"
#include<iostream>
#include "Chrono.h"
#include "Chrono.cpp"
using namespace std;
int main(){
Chrono::Date today;
std::cout << "Enter the the date: ";
std::cin >> today;
++today;
std::cout << "Tomorrow is " << today << endl;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.