Question: write a C + + program that asks the user to enter an integer. The program should read the input in as a string and

write a C++ program that asks the user to enter an integer. The program should read the input in as a string and stores it in a string variable. It will then check to make sure the input consists of only digits. If the input contains only digits, the program should calculate and display the square of the number. If the number contains anything other than digits, it should print a message telling the user how many non-digit characters they entered. Include in your program the following functions:
isNumber - accepts a string as it's only argument. Returns true if all the characters in the string are digits, false otherwise. Does not interact with the user in any way.
countNonDigits - accepts a string as it's only argument. Counts and returns the number of non-digit characters in the string. Does not interact with the user in any way.
Use isNumber to determine if the input from the user consists of only digits as part of an if statement test expression. Use countNonDigits to get the total number of non-digits in the string to display to the user if the input contains anything other than digits. A 20-point submission will:
correctly reading user input as a string - Max 3 points
correct implementation of function isNumber - Max 6 points
correct implementation of function countNonDigits - Max 6 points
correct implementation of main (asking users for input, calling functions, displaying appropriate output): 3 points
Following submission instructions - Max 2 points
A minimum 2 point penalty will be incurred for using code not covered in the course.
If your source does not compile, it will automatically receive 0 points.
Other deductions may occur according to guidelines in the syllabus.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!