C++. Write a function named dateCalculator() that has an integer parameter repre
ID: 3796048 • Letter: C
Question
C++. Write a function named dateCalculator() that has an integer parameter representing the total number of days since the turn of the last century (1/1/1900) and three reference parameters named year, month and day. The function calculates the current year, month, and day for the given number of days passed to it. Using the reference parameters, the function should directly alter the respective actual arguments in the calling function. Test your function in the template provided. NOTE: for this problem assume each year has 365 days and each month has 30 days.
#include using namespace std;
{//write your function prototype here
int main()
{ //declare the variables needed //ask the user to enter the total number of days passed since 1/1/1900 //call the function //display the results //display the results cout << "The date corresponding to " << /*days entered */ << " days after 1/1/1900 is: " << /*resulting month*/ << "/" << /*resulting day*/ << "/" << /* resulting year*/ << "." << endl; //end the program cout << endl ; return 0; } //write your function definition here
Explanation / Answer
//Hi this solution is delivered considering 365 days in a year and 30 days in a month. We can have multiple and //advance options. But this one is basic and simple to learn.
#include <iostream>
using namespace std;
void getdate(int Day){
//calculation of years
int years = Day / 365;
// calculation of months
int months = (Day - (years * 365)) / 30;
//calculation of days
int days = (Day - (years * 365)) - (months * 30);
int currentyear = 1900 + years;
int currentmonth = 1 + months;
int currentdate = 1 + days;
// std::cout << years << std::endl;
// std::cout << months << std::endl;
// std::cout << days << std::endl;
cout << "The date corresponding to " << Day << " days after 1/1/1900 is: " << currentmonth << "/" << currentdate << "/" << currentyear << "." << endl;
//end the program
cout << endl ;
}
int main() {
// your code goes here
int days;
std::cin >> days;
getdate(days);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.