Explain step by step the next c++ source code for the problem shownbelow... The
ID: 3613696 • Letter: E
Question
Explain step by step the next c++ source code for the problem shownbelow...The problem is:
Use one variable to store three data:
Design a program that use data type:int,length:2 bytes variable “date” to store threevariable
“day”, “month”,and “year”.
(1). Input these three variable “day”,“month”, and “year” into variable“date”:
Hint: Design a formula converts the actual three data into thevariable “date”,
according to the format of the 2-byte integer variable“date” provided by yourself.
(2). Extract the three data from variable“date”
The source code is:
#include <iostream>
using namespace std;
int main()
{int i;
unsigned int date,month, day, year;
cout<<"Enter a month: ";
cin>>month;
cout<<"Enter a day: ";
cin>>day;
cout<<"Enter a year: ";
cin>>year;
month=month<<12;
day=day<<7;
date=month|day|(year-2000);
cout<<"The date is: ";
std::cout<<std::hex<<date<<endl;
month=date&0xf000;
month=month>>12;
day=date&0xf80;
day=day>>7;
year=date&0x7F;
std::cout<<std::dec;;
cout<<"The date is:"<<month<<"/"<<day<<"/"<<year+2000<<endl;
cout<<endl;
system("pause");
return 0;
}
Explanation / Answer
please rate - thanks #include using namespace std; int main() {int i; unsigned int date,month, day, year; //input should be self explanatory coutmonth; coutday; coutyear; // divide the 16 bits as follows //bits 0-3 month, bits 4-8 day, bits9-16 year //subtract 2000 from year so it will fit in 8 bits month=monthRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.