Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are to write a subroutine named \"keypad4x4_float\" that will use the keypad

ID: 3675239 • Letter: Y

Question

You are to write a subroutine named "keypad4x4_float" that will use the keypad to input multi-digit floating point numbers. when called, the subroutine should read characters from the 4 times 4 keypad into a string which will later be used to represent a floating point number. If the characters are in the range "0" - "9". the new digit should be added to the number string. If the '#' or 'F' key is pressed, the '-' character should be stored to the string. If the '*' or 'E' key is pressed, the 'E' character should be stored to the string. If any other key is pressed, it indicates the end of input and the resulting string should be terminated. After the termination of the string, use the atof() function to create a float value and return from it from the subroutine.

Explanation / Answer

//The given code below is the function definition for the requirement stated in the question.
//We have used the return type float because we will be returning the float value to the called function.

float keypad4*4_float(char str[100])
{
char str_final[100]; // We have defined the final string to store the output value.
int a=0,i=0,j=0;
float result=0.0;
a= strlen(str); // To determine the length of the string for looping purpose.
  
// Here we check for all the possible values and append the required character to the final string.
for(i=0;i<a;i++)
{
if(str[i]=='0'|| str[i]=='1'|| str[i]=='2'|| str[i]=='4'|| str[i]='5'|| str[i]='6'|| str[i]=='7'|| str[i]=='8'|| str[i]=='9')
   {
   str_final[j++]=str[i];
   }
   else if(str[i]=='#'||str[i]=='F'||str[i]=='f') //C is case-sensitive therefore we have to manage for the cases differently.
   str_final[j++]='-';
   else if(str[i]=='*'||str[i]=='E'||str[i]=='e')
   str_final[j++]='E';
   else
   printf("End of the string");
   exit();
   }
   result=atof(str_final); //atof() function used for the conversion
   return result;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote