Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question will be manually graded; it will show as a 0 / 1 6 in your score until it is graded. This question has

This question will be manually graded; it will show as a 0/16 in your score until it is graded.
This question has three parts: A), B), and C).
The following code segment reads a string (consists of letters and digits) from the keyboard and counts how many 0 s are in the string
string str;
int zeroCount=0;
getline(cin,str);
for(int i =0 ; i <= str.length()1 ; i++){
if(str[i]==0)
zeroCount++;
}
Hint: If you are not familair with length() function, str.length() returns the number of actual characters in a string, and does not count the null character at the end of the string. Ex. string str = "Arizona"; str.length() is 7(Arizona is 7 characters).
You need to write 3 different pieces of code. Do not merge all answers into one program.
A) Rewrite the above code using a while loop. [5 Points]
B) Modify the above code (code given or your answer to part A above, your choice) so that it count how many digits are in the string. ASCII values for digits are values are between 48-57.'0' is 48 and '9' is 57 in ASCII values. The string may contain both digits and other characters, so you need to check each character one by one.
Example: If the given input string is a12b34, the total digits is 4.[5 Points]
C) Write a C++ code segment that reads integers from the keyboard until user enter 0 and determine the largest integer entered. There may be any number of inputs before the user enters 0, including no inputs at all. 0 is counted as part of the input and should be shown as the largest integer if this is the case. [6 Points]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

dy dx Find the derivative of the function y=(4x+3)5(2x+1)2.

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago