10.8 (Using Unions) Create union integer with members char c, short s, int i and long b. Write a program that inputs values of type char, short, int and long and stores the values in union variables of type union integer. Each union variable should be printed as a char, a short, an int |and a long. Do the values always print correctly? Sample input/output. To print in hexadecimal, use %x as the formatter. Input must be same for all cases for comparison. Note: The program accepts 4 different input types, so using a loop would not work. Simply copy and paste the same logic and just change the variable (union member) and conversion specifier. Enter data for type char:8 Breakdown of the element in the union char 8 short 56 int 56 long 56 Breakdown in hex char 38 short 38 int 38 long 38 Enter data for type short:8 Breakdown of the element in the union char short 8 int 8 long 8 Breakdown in hex char 8 short 8 int 8 long 8 Enter data for type int: Sample input and output for the remaining data types are not shown. You must include them for your assignment. Guidelines: 1. Create 4 different union integer variables. For discussion sake, we shall call it Integer1, Integer2, Integer3 and Integer4. 2. For the first variable Integer1, you will only assign value to Integer1.c. Leave the rest alone. 3. For the second variable Integer2, you will only assign value to Integer2.s. Leave the rest alone. 4. For the third variable Integer3, you will only assign value to Integer3.i. Leave the rest alone. 5. For the fourth variable Integer4, you will only assign value to Integer4.b. Leave the rest alone.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

using chapters 1 to 10 from the book C how to program edition 8

10.8 (Using Unions) Create union integer with members char c, short s, int i and long b.
Write a program that inputs values of type char, short, int and long and stores the values in union
variables of type union integer. Each union variable should be printed as a char, a short, an int
|and a long. Do the values always print correctly?
Sample input/output. To print in hexadecimal, use %x as the formatter. Input must be same for all cases for
comparison.
Note: The program accepts 4 different input types, so using a loop would not work. Simply copy and paste the
same logic and just change the variable (union member) and conversion specifier.
Enter data for type char:8
Breakdown of the element in the union
char 8
short 56
int 56
long 56
Breakdown in hex
char 38
short 38
int 38
long 38
Enter data for type short:8
Breakdown of the element in the union
char
short 8
int 8
long 8
Breakdown in hex
char 8
short 8
int 8
long 8
Enter data for type int:
Sample input and output for the remaining data types are not shown. You must include them for your
assignment.
Guidelines:
1. Create 4 different union integer variables. For discussion sake, we shall call it Integer1, Integer2,
Integer3 and Integer4.
2. For the first variable Integer1, you will only assign value to Integer1.c. Leave the rest alone.
3. For the second variable Integer2, you will only assign value to Integer2.s. Leave the rest alone.
4. For the third variable Integer3, you will only assign value to Integer3.i. Leave the rest alone.
5. For the fourth variable Integer4, you will only assign value to Integer4.b. Leave the rest alone.
Transcribed Image Text:10.8 (Using Unions) Create union integer with members char c, short s, int i and long b. Write a program that inputs values of type char, short, int and long and stores the values in union variables of type union integer. Each union variable should be printed as a char, a short, an int |and a long. Do the values always print correctly? Sample input/output. To print in hexadecimal, use %x as the formatter. Input must be same for all cases for comparison. Note: The program accepts 4 different input types, so using a loop would not work. Simply copy and paste the same logic and just change the variable (union member) and conversion specifier. Enter data for type char:8 Breakdown of the element in the union char 8 short 56 int 56 long 56 Breakdown in hex char 38 short 38 int 38 long 38 Enter data for type short:8 Breakdown of the element in the union char short 8 int 8 long 8 Breakdown in hex char 8 short 8 int 8 long 8 Enter data for type int: Sample input and output for the remaining data types are not shown. You must include them for your assignment. Guidelines: 1. Create 4 different union integer variables. For discussion sake, we shall call it Integer1, Integer2, Integer3 and Integer4. 2. For the first variable Integer1, you will only assign value to Integer1.c. Leave the rest alone. 3. For the second variable Integer2, you will only assign value to Integer2.s. Leave the rest alone. 4. For the third variable Integer3, you will only assign value to Integer3.i. Leave the rest alone. 5. For the fourth variable Integer4, you will only assign value to Integer4.b. Leave the rest alone.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY