Question: C++ programming language. Create a union and show how the contents of the each member of the union occupies the same space. Your union will

C++ programming language.

Create a union and show how the contents of the each member of the union occupies the same space. Your union will have character, integer, long integer, float, and double members. You will insert values into each of the members and show how it effected the other members in the union.

#1: In your program, define a union with the following members:
Type Name Description
char ch (char is 1 byte)
short s (short is 2 bytes)
int i (int is 4 bytes)
float f (float is 4 bytes)
double d (double is 8 bytes)

#2: Your program should perform the following 5 operations:

A. Set all of the members of the union to 0. Insert the character 'A' into the member ch. Display all 5 members on the console.
B. Set all of the members of the union to 0. Insert the number 32,767 into the member s. Display all 5 members on the console.
C. Set all of the members of the union to 0. Insert the character 2,147,483,647 into the member i. Display all 5 members on the console.
D. Set all of the members of the union to 0. Insert the character 999.999 into the member f. Display all 5 members on the console.
E.

Set all of the members of the union to 0. Insert the character 999.999 into the member d. Display all 5 members on the console.

There is no need to format the values, just dump them to the console. Display a title for each data block, a label for each member and insert spaces between each output block so that the output makes sense.

#3: Test your code. Run the program to make sure your outputs work properly and your results make sense.

#4: Insert your program documentation and code comments. Provide program documentation and comment the entire program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!