1 answer

Please do it with C++. Thanks:) Write a program that reads a string and a character...

Question:

Please do it with C++. Thanks:)

Write a program that reads a string and a character from the keyboard. The program should output how many times the character appears in the string. Make the program run in a loop until the string finish is input.

Sample run:

Input a string: alicia Input a letter: a The letter appears 2 times Input a string: felix Input a letter: x The letter appears 1 time Input a string: finish Good Bye.

Answers

#include <iostream>
using namespace std;
int main() {
string str;
char ch;
int count = 0;
  
do{
count = 0;
cout<<"Input a string: ";
cin>>str;
if(str=="finish"){
cout<<"Good Bye.";
break;
}
cout<<"Input a letter: ";
cin>>ch;
for(int i=0 ;i< str.size();++i){
  
if(str.at(i)==ch)
++count;
  
}
cout<<"The letter appears "<<count<< " times"<<endl;
  
}while(1);
}



===================================================
See Output

Files saved share gcc version 4.6.3 Input a string alicia Input a letter: a The letter appears 2 times Input a string: fekix

Thanks, PLEASE RATE. let me know if there is any concern.

.

Similar Solved Questions

1 answer
The opposite angles of a parallelogram are congruent
The opposite angles of a parallelogram are congruent. The adjacent angles are supplementary. If angle X measures 110 degrees, then what are the measures of angle Y and angle Z?...
1 answer
Need help asap!!! A 23 kg body is moving through space in the positive direction of...
need help asap!!! A 23 kg body is moving through space in the positive direction of an x axis with a speed of 340 m/s when, due to an internal explosion, it breaks into three parts. One part, with a mass of 4.9 kg, moves away from the point of explosion with a speed of 51 m/s in the positive y direc...
1 answer
Problem 5.27 The diffusion coefficients for species A in metal B are given at two temperatures:...
Problem 5.27 The diffusion coefficients for species A in metal B are given at two temperatures: T(°C) 1020 1260 D (m2/s) 8.09 x 10-17 7.96% 10-15 (a) Determine the value of the activation energy Od (in J/mol). J/mol (b) Determine the value of Do. m2/s (Use scientific notation.) (c) What is the m...
1 answer
To prepare the protein sample, you need mix proteins and Laemmli buffer (5x) and then fuse...
To prepare the protein sample, you need mix proteins and Laemmli buffer (5x) and then fuse water to make up to 15ml . You have 4ml protein sample, calculate how many water and Lammeli Buffer you need to add? Laemmli final concentration should be 1x....
1 answer
Angela has $90 to spend on movies and books. The price of movies (M) is $10...
Angela has $90 to spend on movies and books. The price of movies (M) is $10 and the price of books (B) is $15. Which of the following one or more equations describe Angela's budget constraint? 10M+15B 90 2M-18 - 3B...
1 answer
Determine which sets in Exercises 1-8 are bases for R3. Of the sets that are not...
Determine which sets in Exercises 1-8 are bases for R3. Of the sets that are not bases, determine which ones are linearly independent and which ones span R. Justify your answers. ( 0...
1 answer
Git is an excellent version control system. If we exclude the fact that, it doesn't have...
Git is an excellent version control system. If we exclude the fact that, it doesn't have an excellent GUI support, it's really good and fast. But the source controls like Clearcase has large support for enterprise customers. Companies are investing huge amount for source control servers and ...
1 answer
What element do all organic compounds contain?
What element do all organic compounds contain?...
1 answer
(8 points) A electronics manufacturer has developed a new type of remote control button that is...
(8 points) A electronics manufacturer has developed a new type of remote control button that is designed to operate longer before failing to work consistently. A random sample of 17 of the new buttons is selected and each is tested in continuous operation until it fails to work consistently. The res...
1 answer
TakeAssignment/takeAssignment Main doinvoker&takeAssignmentSessionLocator=&inprogressa false G ROW Activity-Based Costing Maritime Marine Company has total estimated factory overhead...
takeAssignment/takeAssignment Main doinvoker&takeAssignmentSessionLocator=&inprogressa false G ROW Activity-Based Costing Maritime Marine Company has total estimated factory overhead for the year of $882,600, divided into four activities: fabrication, $411,800; assembly, $174,200; setup, $13...
1 answer
One mole of an ideal monatomic gas, initially at a pressure of 1.04 atm and a...
One mole of an ideal monatomic gas, initially at a pressure of 1.04 atm and a volume of 0.0124 m^3 , , is heated to a final state where the pressure is 3.04 atm and the volume is 0.0274 m^3 . The gas constant is 8.31447 J/mol · K . Determine the change in entropy for this...
1 answer
Moving to another question will save this response. Question 20 Determine the following information for the...
Moving to another question will save this response. Question 20 Determine the following information for the Sine Wave Equation Frequency in Hz The unit must be given along with the numerical answer Δ) Moving to another question will save this response....
1 answer
Se Heip Kola Corporation reports net income of $590000 that includes depreciation expense of $79,000 Also,...
Se Heip Kola Corporation reports net income of $590000 that includes depreciation expense of $79,000 Also, cash of $46.000 was borrowed on a 6-year note payablie Based on this dara, total cash infows from operating activtes ane Mutiple Cholce 5636.000 S5000 s000 se...
1 answer
A sealed container with a volume of 2.00 L contains 30.0 atm of pure O2 and...
A sealed container with a volume of 2.00 L contains 30.0 atm of pure O2 and 1.35 g of methanol (CH3OH, 32.05 g/mol) at 25 °C. The combustion finishes, and the container is cooled back to 25 °C. What is the final partial pressure of CO2? What is the final total pressure? (20 pts) please give ...
1 answer
Determine whether the given pair of graphs is isomorphic, if the graphs are not isomorphic provide...
Determine whether the given pair of graphs is isomorphic, if the graphs are not isomorphic provide an argument? A) F G B) 4) Consider the following weighted graph G below...
1 answer
Synthesize these specific structures. Be sure to include synthesis and retrosynthesis including synthons. Only carbon source permitted is/are: Pyrrole, Benzene, alkanes with less than or equal to thr...
Synthesize these specific structures. Be sure to include synthesis and retrosynthesis including synthons. Only carbon source permitted is/are: Pyrrole, Benzene, alkanes with less than or equal to three carbons, carbon dioxide, carbon monoxide, cyanide. -Reagents created in situ must be drawn from th...