Starting Out with C++ from Control Structures to Objects (8th Edition)
8th Edition
ISBN: 9780133769395
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 10, Problem 8PC
Program Plan Intro
Sum of Digits in a String
- Include the required header files to the program.
- Declare function prototype which is used in the program.
- Define the “main()” function.
- Declare the required variables.
- Get the input C-string from the user and call the function “digit” with the input C-string.
- The “for” loop is used to convert the C-string to digit
- Call the function “digit” with an argument and store it in a variable.
- Sum all that values and store in a separate variable.
- Found the highest and lowest value of the C-string using “if” condition.
- Print the result.
- Define the “digit” function.
- Declare the required variable.
- Convert the character string to integer.
- Define an array to hold an empty string value.
- Convert that string to integer using “atoi” function.
- If the input is not a digit, return 0.
- Finally return the result to the main function.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Q: People often forget closing parentheses when entering formulas. Write a program that asks the user to enter a formula and prints out whether the formula has the same number of opening and closing parentheses.
Q: Write a program that asks the user to enter a word and prints out whether that word contains any vowels.
Q: Write a program that asks the user to enter a string. The program should create a new string called new_string from the user’s string such that the second character is changed to an asterisk and three exclamation points are attached to the end of the string. Finally, print new_string. Typical output is shown below: Enter your string: Qbert Q*ert!!!
Q: Write a program that asks the user to enter a string s and then converts s to lowercase, removes all the periods and commas from s, and prints the resulting string.
Q: Write a program that asks the user to enter a word and determines whether the word is a palindrome or not. A palindrome is a word that reads the same…
Lab Activity for the students:
Exercise 5: Write a program that asks the user to input a letter. The program finds and prints if the letter is
uppercase or lowercase. Then, the program asks the user to input a string and get a three-character substring
from the beginning of the string. (1 Mark )
Example : If the inputs are 'y' and "Community". Then, the program will print:
y is lowercase
The substring is: Com
4. Morse Code Converter
Morse code is a code where each letter of the English alphabet, each digit, and vario
punctuation characters are represented by a series of dots and dashes. Table 8-4 shows pe
of the code.
Write a program that asks the user to enter a string, then converts that string to Morse code
Table 8-4 Morse code
Character
Code
Character
Code
Character
Code
Character
Code
space
space
6.
comma
H.
R
period
8.
I
question mark
6.
J
T.
0.
A
K
1
W
3
E
4
Chapter 10 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Ch. 10.2 - Write a short description of each of the following...Ch. 10.2 - Prob. 10.2CPCh. 10.2 - Write an if statement that will display the word...Ch. 10.2 - What is the output of the following statement?...Ch. 10.2 - Write a loop that asks the user Do you want to...Ch. 10.4 - Write a short description of each of the following...Ch. 10.4 - Prob. 10.7CPCh. 10.4 - Prob. 10.8CPCh. 10.4 - Prob. 10.9CPCh. 10.4 - When complete, the following program skeleton will...
Ch. 10.5 - Write a short description of each of the following...Ch. 10.5 - Write a statement that will convert the string 10...Ch. 10.5 - Prob. 10.13CPCh. 10.5 - Write a statement that will convert the string...Ch. 10.5 - Prob. 10.15CPCh. 10.6 - Prob. 10.16CPCh. 10 - Prob. 1RQECh. 10 - Prob. 2RQECh. 10 - Prob. 3RQECh. 10 - Prob. 4RQECh. 10 - Prob. 5RQECh. 10 - Prob. 6RQECh. 10 - Prob. 7RQECh. 10 - Prob. 8RQECh. 10 - Prob. 9RQECh. 10 - Prob. 10RQECh. 10 - The __________ function returns true if the...Ch. 10 - Prob. 12RQECh. 10 - Prob. 13RQECh. 10 - The __________ function returns the lowercase...Ch. 10 - The _________ file must be included in a program...Ch. 10 - Prob. 16RQECh. 10 - Prob. 17RQECh. 10 - Prob. 18RQECh. 10 - Prob. 19RQECh. 10 - Prob. 20RQECh. 10 - Prob. 21RQECh. 10 - Prob. 22RQECh. 10 - Prob. 23RQECh. 10 - Prob. 24RQECh. 10 - The ________ function returns the value of a...Ch. 10 - Prob. 26RQECh. 10 - The following if statement determines whether...Ch. 10 - Assume input is a char array holding a C-string....Ch. 10 - Look at the following array definition: char...Ch. 10 - Prob. 30RQECh. 10 - Write a function that accepts a pointer to a...Ch. 10 - Prob. 32RQECh. 10 - Prob. 33RQECh. 10 - T F If touppers argument is already uppercase, it...Ch. 10 - T F If tolowers argument is already lowercase, it...Ch. 10 - T F The strlen function returns the size of the...Ch. 10 - Prob. 37RQECh. 10 - T F C-string-handling functions accept as...Ch. 10 - T F The strcat function checks to make sure the...Ch. 10 - Prob. 40RQECh. 10 - T F The strcpy function performs no bounds...Ch. 10 - T F There is no difference between 847 and 847.Ch. 10 - Prob. 43RQECh. 10 - char numeric[5]; int x = 123; numeri c = atoi(x);Ch. 10 - char string1[] = "Billy"; char string2[] = " Bob...Ch. 10 - Prob. 46RQECh. 10 - Prob. 1PCCh. 10 - Prob. 2PCCh. 10 - Prob. 3PCCh. 10 - Average Number of Letters Modify the program you...Ch. 10 - Prob. 5PCCh. 10 - Prob. 6PCCh. 10 - Name Arranger Write a program that asks for the...Ch. 10 - Prob. 8PCCh. 10 - Prob. 9PCCh. 10 - Prob. 10PCCh. 10 - Prob. 11PCCh. 10 - Password Verifier Imagine you are developing a...Ch. 10 - Prob. 13PCCh. 10 - Word Separator Write a program that accepts as...Ch. 10 - Character Analysis If you have downloaded this...Ch. 10 - Prob. 16PCCh. 10 - Prob. 18PCCh. 10 - Check Writer Write a program that displays a...
Knowledge Booster
Similar questions
- Pig LatinWrite a program that accepts a sentence as input and converts each word to “Pig Latin.” Inone version, to convert a word to Pig Latin, you remove the first letter and place that letterat the end of the word. Then, you append the string “ay” to the word. Here is an example:English: I SLEPT MOST OF THE NIGHTPig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY in pythonarrow_forwardC++ Languagearrow_forwardJava language kindly simulate it on netbeans Thanksarrow_forward
- Programming language: F95 Write a program to declare two strings of length 7 each and then form a new string by concatenation of the two strings mentioned above. Print the two strings and concatenated string in the output.arrow_forwardHelparrow_forwardJAVA PROGRAM ASAP Please CREATE A program ASAP BECAUSE IT IS LAB ASSIGNMENT so it passes all the test cases. The program must pass the test case when uploaded to Hypergrade. Chapter 9. PC #16. Morse Code Converter Morse code is a code where each letter of the English alphabet, each digit, and various punctuation characters are represented by a series of dots and dashes. Write a program that asks the user to enter a string, and then converts that string to Morse code and prints on the screen. Use hyphens for dashes and periods for dots. The Morse code table is given in a text file morse.txt. When printing morse code, display eight codes on each line except the last line. Codes should be separated from each other with one space. There should be no extra spaces at the beginning and at the end of the output. Uppercase and lowercase letters are translated the same way. Morse.txt 0 -----1 .----2 ..---3 ...--4 ....-5 .....6 -....7 --...8 ---..9 ----.,…arrow_forward
- 4. Word Separator:Write a program that accepts as input a sentence in which all of thewords are run together but the first character of each word is uppercase. Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example the string "StopAndSmellTheRoses." would be converted to "Stop and smell the roses. *python codingarrow_forwardThis one.arrow_forwardNote: you are required to use dialog boxes for input and output. Must be done in Javaarrow_forward
- Allowed libraries:arrow_forwardCreate aC++ function named countWords that counts the number of words in the current string and displays a message stating how many words are in the string Examples: The string 2015 has zero words The string "Hello World" has two words The string " I am Woman " has 3 wordsarrow_forwardName format: You must use String object and not StringBuffer or StringBuilder. Many documents use a specific format for a person's name. Write a program that take one Line as an input. Example: Scanner input = new Scanner(System.in); System.out.println(“Enter firstName middleName lastName separated by at least one blank, It may have more than one blank separating firstName middleName lastName."); Input sample : Pat Silly Doe || Note these are separated by at least one blank. String line = input.nextLine() Ex: If the input is: Pat Silly Doe the output is: Doe, P.S. If the input has the form: firstName lastName the output is: lastName, firstInitial. Ex: If the input is: Julia Clark the output is: Clark, J. Please submit the .java source file and the sample run in a text file. Thanksarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning