Answer to Question #243949 in C++ for Rose

Question #243949
Problem 5: Write pseudocode of a program that takes a number that represents data_Type, another variable sign_Unsign to further classify the data type as signed or unsigned, and a number from the user. Verify if that number can be stored in that given data type. Range of each datatype is given in the table below.
Input:
1. Take data_Type from the user, if the user enters value other than 1 or 2 ask to input data_Type
again.
2. Take sign_Unsign from the user, if the user enters anyother value than 0 or 1 ask to input
sign_Unsign again 3. Take number (any)
1 – short int 0 - signed 2 byte 1 - unsigned 2 bytes 2-int 0-signed 4bytes 1 - unsigned 4 bytes
-32768 to 32767
0 to 65535
-2147483648 to 2147483647 0 to 4296967295
Data_Type
Sign_Unsign
Size
Range
1
Expert's answer
2021-09-29T03:42:31-0400
short_min = -32768
short_max = 32767
ushort_max = 65535

int_min = -2147483648
int_max = 2147483647
uint_max = 4296967295

sign = input() -> 0 -- signed or 1 -- unsigned
type = input() -> 0 -- short and 1 -- int
number = input() -> any

if type == 0:
  if sign == 0:
    if short_min <= number and number <= short_max: -> Ok
  if sign == 1:
    if 0 <= number and number <= ushort_max: -> Ok
if type == 1:
  if sign == 0:
    if int_min <= number and number <= int_max: -> Ok
  if sign == 1:
    if 0 <= number and number <= uint_max: -> Ok

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS