6. Improve the stringToInteger function to convert an entire string of digits to a non- negative integer. For example, "345" should be converted to 345. ● ● 7. Improve your function to handle bad strings, i.e., ones that are not all digits. Start by declaring a constant of type int named INVALID_COORDINATE and give it a value of -1. Make it a global constant by putting it before the main function (and before the function prototype). You will return this constant from stringToInteger as an error value whenever the input string is bad. ● Hint: Use a loop to process the characters sequentially. Hint: You can use the .length () function to determine how many characters are in a string variable. A somewhat irrelevant example is: if(i =. Anything less than '0' or greater than '9' is not a digit. ● Reminder: If a function has a return type, it should always return a value. If the computer ever reaches the end of your function without a return statement, it will return an apparently random value (whatever is handy in memory) instead. This problem causes weird bugs. The easiest way to avoid this problem is make the last line of your function a return statement. 9. Improve your main function so there is at least one test on a bad string.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Please send me answer of this question immediately and i will give you like sure sir 

6. Improve the stringToInteger function to convert an entire string of digits to a non-
negative integer. For example, "345" should be converted to 345.
Hint: Use a loop to process the characters sequentially.
Hint: You can use the length () function to determine how many characters are in a
string variable. A somewhat irrelevant example is:
if(i <str.length())
●
●
7. Improve your function to handle bad strings, i.e., ones that are not all digits. Start by declaring a
constant of type int named INVALID_COORDINATE and give it a value of -1. Make it a
global constant by putting it before the main function (and before the function prototype). You
will return this constant from stringToInteger as an error value whenever the input string
is bad.
●
8. Change the stringToInteger function to return INVALID_COORDINATE if the string has
a length of 0. Also return INVALID_COORDINATE if any character in the string is not a digit.
Hint: You can use a FOR loop to access the characters in a string one by one.
Hint: You can compare characters with comparison operators such as < and >=.
Anything less than '0' or greater than '9' is not a digit.
●
Reminder: If a function has a return type, it should always return a value. If the
computer ever reaches the end of your function without a return statement, it will
return an apparently random value (whatever is handy in memory) instead. This
problem causes weird bugs. The easiest way to avoid this problem is make the last line
of your function a return statement.
●
9. Improve your main function so there is at least one test on a bad string.
Transcribed Image Text:6. Improve the stringToInteger function to convert an entire string of digits to a non- negative integer. For example, "345" should be converted to 345. Hint: Use a loop to process the characters sequentially. Hint: You can use the length () function to determine how many characters are in a string variable. A somewhat irrelevant example is: if(i <str.length()) ● ● 7. Improve your function to handle bad strings, i.e., ones that are not all digits. Start by declaring a constant of type int named INVALID_COORDINATE and give it a value of -1. Make it a global constant by putting it before the main function (and before the function prototype). You will return this constant from stringToInteger as an error value whenever the input string is bad. ● 8. Change the stringToInteger function to return INVALID_COORDINATE if the string has a length of 0. Also return INVALID_COORDINATE if any character in the string is not a digit. Hint: You can use a FOR loop to access the characters in a string one by one. Hint: You can compare characters with comparison operators such as < and >=. Anything less than '0' or greater than '9' is not a digit. ● Reminder: If a function has a return type, it should always return a value. If the computer ever reaches the end of your function without a return statement, it will return an apparently random value (whatever is handy in memory) instead. This problem causes weird bugs. The easiest way to avoid this problem is make the last line of your function a return statement. ● 9. Improve your main function so there is at least one test on a bad string.
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education