1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nataly862011 [7]
3 years ago
12

Develop an algorithm and write a C++ program that finds the number of occurrences of a specified character in the string; make s

ure you take CString as input and return number of occurrences using call by reference. For example, Write a test program that reads a string and a character and displays the number of occurrences of the character in the string. Here is a sample run of the program:______.
Computers and Technology
1 answer:
nirvana33 [79]3 years ago
8 0

Answer:

The algorithm is as follows:

1. Input sentence

2. Input character

3. Length = len(sentence)

4. count = 0

5. For i = 0 to Length-1

 5.1 If sentence[i] == character

    5.1.1 count++

6. Print count

7. Stop

The program in C++ is as follows:

#include <iostream>

#include <string.h>

using namespace std;

int main(){

char str[100];   char chr;

cin.getline(str, 100);

cin>>chr;

int count = 0;

for (int i=0;i<strlen(str);i++){

 if (str[i] == chr){

  count++;} }

cout << count;

return 0;}

Explanation:

I will provide explanation for the c++ program. The explanation can also be extended to the algorithm

This declares the string and the character

char str[100];   char chr;

This gets input for the string variable

cin.getline(str, 100);

This gets input for the character variable

cin>>chr;

This initializes count to 0

int count = 0;

This iterates through the characters of the string

for (int i=0;i<strlen(str);i++){

If the current character equals the search character, count is incremented by 1

 if (str[i] == chr){  count++;} }

This prints the count

cout << count;

You might be interested in
Whenever they are passed as parameters to a function, the IO classes istream and ostream must be passed using a pass-by-referenc
morpeh [17]

Answer:

b. TRUE

Explanation:

Whenever they are passed as parameters to a function, the IO classes istream and ostream must be passed using a pass-by-reference parameter passing scheme.

This is because , assuming a pass by value semantics would require us to copy the value of the istream or ostream object which would be meaningless. In fact these objects don't even have a copy constructor at all. So such objects are always passed by reference.

7 0
3 years ago
Which of the following would be the correct si unit to use in measuring the amount of electrical current in a circuit
rjkz [21]

I think its joule i hope this helps

4 0
3 years ago
Read 2 more answers
Which type of digital picture is made by storing individual pixel values?
GaryK [48]

Answer:

Raster images

4 0
3 years ago
Which command on the home ribbon do you use to replace information in a selected cell with new information or new formatting?
Lelu [443]
Cut and paste - you use to replace information in a selected cell with new information or new formatting
3 0
3 years ago
Need help with this question​
vova2212 [387]

Answer:

B

Explanation

The backlight softens the light on an electronic device

7 0
4 years ago
Read 2 more answers
Other questions:
  • Waterpower was first harvested by ancient societies using
    5·1 answer
  • There are 5 houses in a row and in 5 different colors.
    5·1 answer
  • You have just installed the microsoft windows 7 operating system on your pc. which web browser is bundled with windows 7 and is
    12·1 answer
  • Which statement is NOT true:
    9·1 answer
  • Raul converts numbers in base 10 to base 2. Which answer best defends why Raul would need to do this?
    12·1 answer
  • Which of the following describes cloud computing?​
    10·1 answer
  • Under which menu option of a word processing program does a callout appear?
    7·2 answers
  • Assume that two int constants,FIRST_YEAR and LAST_YEAR have already been declared and initialized with year values (like 2009, 2
    9·1 answer
  • So im new how exactly does this point system work???​
    6·1 answer
  • How ict tools changed the way we live explain it​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!