Programming and Graphics

(Kiana) #1

106 Introduction to C++ Programming and Graphics


cout << " (should be less than 32)" << endl;
cout <<"qtoquit" << endl;
cout << " ------------------------------" << endl;
if(!(cin >> n)) break;
cout << setw(13) << " bits " << " "
<< setw(10) << " increment" << " "
<< setw(16) << "largest integer" << endl;

intq=0;

for (i=0; i<=n-1; i++)
{
int p = ipow(two, i);
q=q+p;
cout << setw(10) << i+1 << " "
<< setw(10) << p << " "
<< setw(10) << q << endl;
};
};
return 0;
}

Thewhileloop is abandoned when a false read is encountered. The content of
the second file namedipow.ccis:


/*--------------------------------------------
function ipow computes the integer powerij
--------------------------------------------*/
int ipow(int i, int j)
{
int k, accum=1;
for (k=1; k<=j; k++)
{
accum = accum * i;
};
return accum;
}

The content of the header fileipow.his:


#ifndef IPOWH
#define IPOWH
using namespace std;
int ipow (int, int);
#endif

Note that the declaration:


int ipow (int, int)
Free download pdf