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

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=month
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