Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise 3 . Use the program shell below to implement a program called SumDigits. When completed, program SumDigits prompts for and reads a one -
Exercise
Use the program shell below to implement a program called SumDigits. When completed, program
SumDigits prompts for and reads a onedigit number, then adds the numbers from zero to the number,
inclusive, and prints the sum.
Program SumDigits prompts for and reads a onedigit number.
Values between and the digit inclusive are summed.
#include
using namespace std;
int main
int counter; Loopcontrol variable
int sum; Running sum
int digit;
cout "Enter a onedigit number; press return."
endl;
cin digit;
counter TO BE FILLED IN
sum TO BE FILLED IN
while TO BE FILLED IN
TO BE FILLED IN
cout "Sum of digits between and
digit is sum endl;
return ;
Eventcontrolled Loops
Use program shell CountUC for exercises and
Program CountUC counts the number of uppercase letters
on a line.
#include
using namespace std;
int main
char letter;
int letterCt;
TO BE FILLED IN
return ;
Exercise
Fill in the body of program CountUC so that the number of uppercase letters on a line of input is printed.
Run your program with the following input and show the result.
Hint: Remember that the ASCII code of letters are in alphabetic order, so an uppercase letter must
satisfy letterA && letterZ
You can use cin.getletter to get each character in the line and exit the loop when its
Input Output
AbbaDabbaDoo
Exercise
Change program CountUC from Exercise so that the counting stops if the input line contains a digit.
Run your program with the following data and show the results.
Input Output
ABBADABBADoo
Nested Loops and Testing the State of an IO Stream
Exercises and are based on the program SumDigits in Exercise
Exercise :
Modify your program SumDigits so that the processing is repeated until a negative digit is read. Make
sure you add this information the process stops when digit is negative in the prompt. Hint: you need to
implement an outer loop to repeat the prompting and reading data, and keep the summing from to digit
as an inner loop.
Exercise :
Modify your program in Exercise so that the values will be read from a file called digitsdat and the
process is repeated until either a negative digit is read or the end of file. Test both cases.
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