Redo Listing 9.9, replacing the character array with a string object. The program should no longer have
Question:
Redo Listing 9.9, replacing the character array with a string object. The program should no longer have to check whether the input string fits, and it can compare the input string to "" to check for an empty line.
Listing 9.9
Transcribed Image Text:
Listing 9.9 static.cpp
//static.cpp
#include
Listing 9.9 static.cpp
//static.cpp
#include
// constants
const int Arsize = 10;
int main()
{
--
// function prototype
void strcount (const char str);
}
using a static local variable
}
using namespace std;
char input [Arsize];
char next;
cout << "Enter a line: \n";
cin.get (input, Arsize);
while (cin)
{
cin.get (next);
while (next != '\n')
cin.get (next);
strcount (input);
cout << "Enter next line (empty line to quit): \n";
cin.get (input, Arsize);
}
cout << "Bye\n";
return 0;
void strcount (const char str)
{
// string didn't fit!
// dispose of remainder
using namespace std;
static int total = 0;
int count = 0;
// static local variable
// automatic local variable
cout << "\"" << str <<"\" contains ";
while (*str++)
// go to end of string
count++;
total + count;
cout << count <<" characters\n";
cout << total << " characters total\n";
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 66% (9 reviews)
static2cpp using a static string include include include function prototype void strcou...View the full answer
Answered By
Dansteve Matoke
As a consequence of more than three years of experience in ACADEMIC WRITING, I have vast, diverse knowledge and impeccable grammar. I guarantee the quality of my work across multiple fields. I intend to precisely meet the clients' expectations. Let's work together to achieve exceptional grades.
0.00
0 Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
Write a bash script to check whether the input number is EVEN, ODD, or neither EVEN nor ODD.
-
Check whether organisms 1 and 2 differ and compare with Section 8.6, Exercise 39. One organism has 8 mutations in 1 million base pairs, a second has 18 in 1 million, and a third has 28 in 1 million....
-
Check whether organisms 2 and 3 differ and compare with Section 8.6, Exercise 40. One organism has 8 mutations in 1 million base pairs, a second has 18 in 1 million, and a third has 28 in 1 million....
-
Francis and Peter are in a partnership sharing profits and losses in the ratio 3:2. The following is their trial balance as at 30 September 2020. particulars D ebit C redit Buildings (cost: RM...
-
In recent years, a new theory of real business cycles (or RBCs) has been proposed (this approach is further analyzed in Chapter 31). RBC theory suggests that business fluctuations are caused by...
-
Zeller?s congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is where ? h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4:...
-
The rod has a circular cross section with a moment of inertia \(I\). If a vertical force \(\mathbf{P}\) is applied at \(A\), determine the vertical displacement at this point. Only consider the...
-
The Peachtree Airport in Atlanta serves light aircraft. It has a single runway and one air traffic controller to land planes. It takes an airplane 8 minutes to land and clear the runway...
-
Define VM sprawl and discuss its impact on resource utilization and management in virtualized infrastructures. What strategies can be employed to mitigate VM sprawl and optimize resource allocation ?
-
A ball of mass 2m slides along a frictionless track with speed u. Starting from a long distance away, it collides elastically with a stationary ball of mass m. (a) Calculate the final speeds of both...
-
Fuel cells similar to the PEM cell of Example 1.4 operate with a mixture of liquid water and methanol instead of hydrogen; the anode is placed in direct contact with the liquid fuel. Oxygen (species...
-
There are three salts that contain complex ions of chromium and have the molecular formula CrCl 3 ? 6H 2 O. Treating 0.27 g of the first salt with a strong dehydrating agent resulted in a mass loss...
-
Using the CAPM, estimate the appropriate required rate of return for the three stocks listed here, given that the risk-free rate is 5 percent and the expected return for the market is 12 percent....
-
The eight lamps are being replaced by eight white LED (light emitting diode) spotlights. They will provide the same amount of light as the halogen lamps and will be used for the same 2800 hours per...
-
Complete the function table. Function: q = 1r - 2 4 6 q 2 3
-
Find the following probabilities. It may help to sketch the pdf for Standard Normal Distribution and shade in the area that corresponds to the probability of interest. 1) Z Norm(0, 1), find Pr(Z...
-
In what ways can a distributed leadership framework enhance organizational resilience and facilitate change management in complex, interconnected ecosystems ?
-
A thin wire represented by the smooth curve C with a density rho (units of mass per length) has a mass M Find the mass of the wire C: {(x, y): y = 2x, 0 < x <6} with density p(x, y) = 3+6xy. = pd:...
-
One cold and windy winter day, Zach notices a humming sound coming from his chimney when the chimney is open at the top and closed at the bottom. He opens the chimney at the bottom and notices that...
-
On August 31, 2012, the balances of the accounts appearing in the ledger of Wood Interiors Company, a furniture wholesaler, are as follows:Prepare the August 31, 2012, closing entries for Wood...
-
For a tree T, let n I denote the number of its internal nodes, and let n E denote the number of its external nodes. Show that if every internal node in T has exactly 3 children, then n E = 2n I +1.
-
Let T be a (possibly improper) binary tree with n nodes, and let D be the sum of the depths of all the external nodes of T. Describe a configuration for T such that D is Ω(n 2 ). Such a...
-
Consider the example of a breadth-first traversal given in Figure 8.15. Using the annotated numbers from that figure, describe the contents of the queue before each pass of the while loop in Code...
-
Consider the vectors u=2ij2k and v=2i+2j+4k. Find the vector components of u that are parallel and perpendicular to v.
-
1. Determine whether the following sets form subspaces and justify your answers. (a) {(1, 2): 122 = 0} in R (b) {(1, 2) |1|-|x2|} in R2 (c) {(x1, x2, x3): x3 = 21 or x3 = 12} in R3 (d) {(x1, x2, x3):...
-
Solve the system of two equations for y two equations are: A1=ax+by A2=cx+dy
Study smarter with the SolutionInn App