L.A.2.1

LAB EXERCISE

 

practice

 

 

Background:

 

C++ provides a sizeof () operator which returns the size in bytes of an object.  Here are examples:

 

#include <iostream.h>

 

main ()

{

         int   number = 2;

         float   answer = 6.25;

 

         cout << "The value of number = " << number;

         cout << "     The byte size of number is " << sizeof (number) << "bytes." << endl;

         cout << "The value of answer = " << answer;

         cout << "     The byte size of answer is " << sizeof (answer) << "bytes." << endl;

         return 0;

}    

 

Run output:

 

The value of number = 2     The byte size of number is 2 bytes.

The value of answer = 6.25     The byte size of answer is 4 bytes.

 

 

Assignment:

 

Write a program which uses all of the following concepts:  data types, variables, initialization, sizeof, type conversions.  The program should solve 10 tasks:

 

1.    Declares, initializes, and prints the contents and size of an integer variable.

2.    Declares, initializes, and prints the contents and size of a long integer variable.

3.    Declares, initializes, and prints the contents and size of an unsigned integer variable.

4.    Declares, initializes, and prints the contents and size of a character variable.

5.    Declares, initializes, and prints the contents and size of a single precision float variable.

6.    Declares, initializes, and prints the contents and size of a double float variable.

7.    Declares, initializes, and prints the contents and size of a long double float variable.

8.    Declares, initializes, and prints the contents and size of a bool variable.

 

 

 

 

 

9.      Starting with the character variable from item #4 above, translate this character value into the corresponding ASCII integer value.  Store this integer value in an appropriate variable.  Print out these two variables in the following format:

 

     Letter = d            ASCII position = 100

 

10.    Starting with an integer ASCII position (make sure it is a valid ASCII value by checking H.A.2.2), convert and store this value in a character variable.  Print out these two variables as follows:

 

     ASCII position = 42         Letter = * 

 

 

Instructions:

 

1.    Write the program and verify that each section works.

 

2.    Append the run output at the bottom of the source code.

 

3.    Print the combination of source code and run output.

 

4.    Include your name as a documentation statement and a brief description of your program.