Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c language do with this skeleton please atof is a function in the C programming language that converts a string into a floating-point numerical representation.

c language do with this skeleton pleaseimage
image
image
image
image

atof is a function in the C programming language that converts a string into a floating-point numerical representation. atof stands for ASCII to float. Task 1. In this part of the assignment, you are going to implement your own atof function float myAtof (char* string, char* error) that will convert an input read as a character array into a floating-point number. Your atof function will get two inputs. One for the character array to convert and the other to check for the error. The output of the function will be a floating-point number. If the character array cannot be converted (it includes letters, special characters, etc.) the error will be 1, otherwise 0. If the numbers cannot be converted (error = 1), give an error message to the user. Here are some sample outputs: Enter a number: 6 Your number is: 6.00 Process returned e (exe) Press any key to continue. Enter a number: 4.678 Your number is: 4.68 Process returned 0 (0x0) Press any key to continue. execution time: 9.563 S execution time: 5.820 s Enter a number: hello Error has been occurred due to inappropriate input! Process returned 0 (0x0) execution time: 3.126 s Press any key to continue. #include #include #define SIZE 250 float myAtof (char *string, char *error); int main() { } char string[SIZE]; float fnum1; char errorState=0; } // Array declaration. printf( Enter a number: ); gets (string); fnum1-myAtof(string, &errorState); if (errorState ==0) { printf( Your number is: %.2f , fnum1); }else if (errorState==1){ printf( Error has been occurred due to inappropriate input! ); } return 0; float myAtof (char* string, char* error) { //your code comes here!!! // Function to convert string into float. In this part of the assignment, you will use your own atof function that you implement in the task 1 to extend arithmetic operation evaluation (+,-,*/) to operate on floating-point numbers. You will get a character array from the user. The user will enter the operation in the form 1.25 + 12 0.24 * 3 etc. The output will be 1.25 12.00 13.25. Do not use the functions of String library. Use gets() function to get the operation from the user. Notice that end of input is indicated by null character \0 Numbers will be printed with two-digit precision after decimal point. If the user enters an invalid operation, give a message. Here are some sample outputs: Enter arithmetic operation: 0.00 0.00 0.00 Process returned (exe) execution time: 14.202 s Press any key to continue. Enter arithmetic operation: 6-2 6.00 2.00 4.00 Process returned 0 (0x0) execution time: 3.713 s Press any key to continue. Enter arithmetic operation: 3.7/3 3.70 3.00 1.23 Process returned 0 (exe) Press any key to continue. Enter arithmetic operation: 5.3*2.1 5.30 2.10 11.13 Process returned e (exe) Press any key to continue. execution time : 5.604 s execution time : 6.372 s Enter arithmetic operation: 3.7 * 5 Error has been occurred due to inappropriate input! Process returned 0 (0x0) execution time: 10.354 s Press any key to continue. Enter arithmetic operation: 4+hello Error has been occurred due to inappropriate input! Process returned 0 (0x0) execution time: 7.720 s Press any key to continue. Process returned 0 (0x0) Press any key to continue. Enter arithmetic operation: 4/0 Cannot divided into 0. execution time: 4.016 s

Step by Step Solution

3.51 Rating (158 Votes )

There are 3 Steps involved in it

Step: 1

Heres the implementation of the myAtof function in C programming language c Copy include stdio h inc... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Auditing and Assurance services an integrated approach

Authors: Alvin a. arens, Randal j. elder, Mark s. Beasley

14th Edition

133081605, 132575957, 9780133081602, 978-0132575959

More Books

Students also viewed these Electrical Engineering questions

Question

?

Answered: 1 week ago