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: 75% (8 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...
-
If a store permanently offers extended shopping hours, what macro environmental factor(s) are they appealing to?
-
Nationwide Insurance developed a program to recruit new insurance agents by offering planning, training, and start-up financing to build self-sustaining agencies. These new agents would be...
-
The trial balance before adjustment of Reba McIntyre Inc. shows the following balances. Instructions Prepare the entry for estimated bad debts assuming that the allowance is to provide for doubtful...
-
When President Obama was President he had discussed raising income taxes for individuals earning over $250,000 in income. Explain how these higher income taxes will affect the aggregate demand curve....
-
The payroll records of Graham Computer Co. for the week ending October 7, the 40th week in the year, show the following: Required: 1. Complete a work sheet with the following column headings:...
-
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...
-
If an investor wanted to reduce the risk of a levered stock in their portfolio, how could they go about doing so while still retaining shares in the company?
-
Do you think it is reasonable to assume that the production of ESS follows the law of diminishing marginal product? Explain.
-
Read the following statements. In response, state True, False or Uncertain and explain why: (a) Biological diversity contributes to an increase in the stability of the supply of ecosystems services....
-
Explain how the combined effects of clouds, aerosols, forest ecosystems and ocean currents contribute to the difficulty of estimating future GW trends.
-
Briefly identify the following concepts: preventive and positive checks to population growth, exponential growth, the Malthusian trap, Ricardian rent, neo-Malthusian, real per capita output,...
-
Provide brief but critical comments on the following major UN biodiversity related treaties and policy guidelines: (a) The 1973 Convention on International Trade in Endangered Species of Wild Fauna...
-
An unknown mass of iron at 80oC is dropped into an insulated tank that contains 0.1 m3 of liquid water at 20oC. Meanwhile, a paddle wheel driven by a 200 W motor is used to stir the water. When...
-
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...
-
In each of Problems determine the sum of the Fourier series on the interval. It is not necessary (or even helpful) to write this series. 2x for-3
-
7. Consider the following pseudocode. procedure pname(N: a positive integer) k:= 0 9:= N/2 while q =[q] k=k+1 q=g/2 return k (a) (6 points) What is the value returned by this procedure when N = 7,...
-
What is the final value of count after the algorithm described below is finished? count -0 For i 1 to 3 For j=i+1 to 4 count : count + (ji) End-for End-for
Study smarter with the SolutionInn App