Question
A. Write a complete, working C++ program called that does the following: Extract the numeric value from a string (See Sample Output). Assume that the
A. Write a complete, working C++ program called that does the following: Extract the numeric value from a string (See Sample Output). Assume that the numeric value is always an integer, never a floating-point number.
-
Declare a string variable to read a string from the user.
-
Using suitable prompt, read a string from the user. The string can have multiple words,
each word separated by a single space.
-
Declare an integer variable named value to store numeric value extracted from the string
and initialize it to 0.
-
Declare an integer variable named index to compute the numeric value.
-
In a loop of your choice:
o Parse the string one character at a time. In this loop, you need parse the string in order of starting from the last character to the first character i.e. test the final character first.
o Check if the character is a digit. o Using variable index as index and 10 as base, compute power. o Multiply the computed power with the numeric value of extracted digit.
HINT: The ASCII value of character 0 is 48, while the numeric value is 0.o Accumulate the product of the above multiplication in the variable value. o Increment index by 1 after processing each digit.
-
Display the computed value using with a suitable message.
-
Increment the computed value by 100 and display the incremented value with a suitable
message.
-
Due to time constraints, no comments are required in this code.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started