Hi everyone, previously I had to write a compress function, which I will put below. Now I have to write a decompress function, I am lost on this I do not really know how to do this. Any help is appreciated.
unsigned int compress(unsigned int age, unsigned int grade, char sex, double GPA)
{
if ((age < 3) || (age > 18)) return 0;
if ((sex != 'M') && (sex != 'F')) return 0;
if (grade > 15) return 0;
if ((GPA < 0.0) || (GPA > 4.0)) return 0;
age -= 3;
sex = (sex == 'F') ? 0 : 1;
unsigned int gpa = (unsigned int)GPA;
GPA -= gpa;
GPA *= 10.0;
unsigned int gpa_frac = (unsigned int)(GPA + 0.5);
// decompress: decompresses the low-order 16 bits of info and
// returns age, grade, sex, and GPA
void decompress(unsigned int info, unsigned int& age,
unsigned int& grade, char& sex, double& GPA);
extern const int N = sizeof(int) * CHAR_BIT; // # of bits in an int
int main()
{
unsigned int age, grade, info;
char sex;
double GPA;
// Prepare for floating-point output format; show one digitafter
// the decimal point
cout << fixed << showpoint << setprecision(1);
printLine(78, cout);
cout << setw(76) << "33222222222211111111110000000000" << endl;
cout << " Age Grade Sex GPA Compress "
<< "10987654321098765432109876543210" << endl;