Part 3: How big are the different integers on your system? Study, and then compi
ID: 3870625 • Letter: P
Question
Part 3: How big are the different integers on your system? Study, and then compile and run variablesizes.cpp, then answer the following questions (put your answers in a text file to turn in) How long are the various integer data types on your computer system, in bits and in bytes? (This will be a function of your processor and your operating system, and can be limited by your compiler). The sizeof(...) function tells you how many bytes there are in the thing passed to it char, unsigned char short, unsigned short int, unsigned int long, unsigned long long long float double long double What are the largest and smallest values you can store in each of the integer data types above? You'll need to calculate this from the sizes you get. You can check your answers using the windows or mac os x calculator; it will help to put it in "programmer" mode. (Recall that each byte has 8 bits, and with n bits, you can represent 2" different bit patterns, or values.) What are the ranges for the floating point types on your system (what do the exponents range from/to)? The program won't tell you that, but you can find the answers with a little googling (they should also be in my tutorial on floating point numbers). How many digits of precision are there for each type? The C++ header file climits (#includeExplanation / Answer
C++ Program :-
#include <limits>
#include <iostream>
#include<iomanip>
#include <iostream>
#include <fstream>
using std::cout;
using std::endl;
using std::numeric_limits;
using namespace std;
int main()
{
ofstream cout;
cout.open ("variable_sizes.txt");
char c;
int i;
long l;
float f;
double d;
cout << "char " << setw(5) << setfill(' ')<<" size = " << sizeof(c) << endl;
// Integer value
cout << "integer " << setw(2) << setfill(' ') <<" size = "<< sizeof(i) << endl;
cout << "The range for type int is from "<< numeric_limits<int>::min()<< " to " << numeric_limits<int>::max()<<endl;
//Long value
cout << "long " << setw(5) << setfill(' ')<<" size = "<< sizeof(l) << endl;
cout << "The range for type long is from "<< numeric_limits<long>::min()<< " to "<< numeric_limits<long>::max()<<endl;
//Float value
cout << "float " << setw(4) << setfill(' ')<<" size = "<< sizeof(f) << endl;
cout << "The range for type float is from "<< numeric_limits<float>::min()<< " to "<< numeric_limits<float>::max()<<endl;
//Double value
cout << "double " << setw(3) << setfill(' ')<<" size "<< sizeof(d) << endl;
cout << "The range for type double is from "<< numeric_limits<double>::min()<< " to "<< numeric_limits<double>::max()<<endl;
return 0;
}
OUTPUT :-
variable_sizes.txt
char size = 1
integer size = 4
The range for type int is from -2147483648 to 2147483647
long size = 4
The range for type long is from -2147483648 to 2147483647
float size = 4
The range for type float is from 1.17549e-038 to 3.40282e+038
double size 8
The range for type double is from 2.22507e-308 to 1.79769e+308