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
~ I already know this ~ who was the bits victim in five nights at freddys 4 <br> ___10 points___
Andreas93 [3]

Answer:

i dont know anything about them only that the bear is the ducks son and the duck is the fox mom.

Explanation:

6 0
3 years ago
Read 2 more answers
10 points
Bingel [31]

Answer:

cool this is cool

Explanation:reEEEEEEE

6 0
3 years ago
Alex works as a customer-service representative at an insurance company. Before starting his shift, Alex reviews issues from his
never [62]

Answer:

problem-solving

Explanation:

he is making sure all his problems have been resolved before starting a new shift.

4 0
3 years ago
Read 2 more answers
I can talk to you! How about we talk through the you know where people comment and say stuff about the question1
pychu [463]
Hmmm what do you want to talk about??
3 0
3 years ago
Read 2 more answers
Which of the following would determine how many elements are in values?
DiKsa [7]
I guess depends on the language but for both java and C++ answer 3 is correct.
3 0
3 years ago
Other questions:
  • Which statement accurately describes the clutter feature in outlook 2016
    12·1 answer
  • A newspaper publishes a negative editorial on how local politicians are dragging their feet in building a new bridge. Select the
    5·2 answers
  • The house had a wonderful pool of ... (his/its/our) own.​
    5·1 answer
  • Which device or software application detects errors in system configurations?
    8·1 answer
  • Which equation gives you the amount of work performed?
    13·1 answer
  • When doing black and white photography, which file format should you use if possible? JPEG TIFF PNG RAW
    11·2 answers
  • Which should be your first choice for the most efficient and successful job search method?
    10·1 answer
  • In this lab you are asked to declare two variables of type integer: userNum and x. The user should input should be stored using
    8·1 answer
  • What is the difference between ionizing and non-ionizing radiation?
    7·2 answers
  • What are some good apps to download to screenshot your screen?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!