Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Instructions Write a program that accepts a long integer of the form yyy

ID: 3630846 • Letter: P

Question

Problem Instructions

Write a program that accepts a long integer of the form yyyymmdd, such as 20111020. This integer will be passed to a function called date(), which will determine the corresponding month, day, and year; and return these three values to the calling function. The function prototype for date() is:

void date(int longDate, int &month, int &day, int &year);

For example, if longDate=20111020, then the number 10 should be returned in month, the number 20 in day, and the number 2011 in year. In addition, the program needs to be repeated as often as the user wishes. Please try to format your output exactly like the example. Otherwise your program will not be graded by Pinax properly.

Example:

Enter a long integer of the form yyyymmdd: 20111020
The date is 10/20/2011
Try again? [y/n] y

Enter a long integer of the form yyyymmdd: 19000305
The date is 3/5/1900
Try again? [y/n] n
Hint: date = year * 10000 + month * 100 + day

Explanation / Answer

please rate - thanks

you say accepts a long integer, but then the prototype is an int?

#include <iostream>
using namespace std;
void date(int longDate, int &month, int &day, int &year);
int main()
{int longDate;
int month,day,year;
char yes;
do
{
cout<<"Enter a long integer of the form yyyymmdd: ";
cin>>longDate;
date(longDate,month,day,year);
cout<<"The date is "<<month<<"/"<<day<<"/"<<year<<endl;
cout<<"Try again? [y/n] ";
cin>>yes;
}while(yes=='y');
return 0;
}
void date(int longDate, int &month, int &day, int &year)
{year=longDate/10000;
day=longDate%100;
month=longDate/100%100;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote