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
stich3 [128]
4 years ago
5

Your program must define and call the following function that returns the number of times the input character appears in the inp

ut string. int CountCharacters(char userChar, string userString)
Computers and Technology
1 answer:
vovikov84 [41]4 years ago
5 0

Answer:

The program to this question can be given as:

Program:

#include <iostream>  //header file

using namespace std;  //using name space.

int CountCharacters(char userChar,string userString) //define function.

{    

int count = 0;  //define variable

for (int i=0;i<userString.length();i++) //loop

if (userString[i]==userChar)  //if block

count++;  //increment the value.

return count;  //return value.

}

int main()  //main method.

{

   string userString= "Clanguage";  //define variable and assign value.

   char userChar = 'a';   //define variable and assign value.

   cout << CountCharacters(userChar,userString);  //calling function and print value.  

   return 0;  

}

Output:

2

Explanation:

  • In the above C++ programming language program we define a function that is "CountCharacters". Inside function parameters, we pass two parameters that are "userChar and userString". The userChar is a char variable that holds single character value and userString is a string variable that holds a string value.
  • In the function, we define an integer variable that is "count". This variable counts the match value and returns its value.
  • To counts values, we define a loop in a loop we use if statement that counts the value that how many time it occurs in a string value and return its value.
  • In the main method, we define these variables ("userChar and userString") and assign values that are "a and Clanguage " and call the function and print function return value.
You might be interested in
Eric wants your help in remembering which of the following options corresponds to a dialog box that alerts the user to an error
nignag [31]

Answer:

MsgBox("User name is missing", 1 Or 16, "User Name Error")

Explanation:

6 0
4 years ago
Bunco is a dice throwing game that requires no decisions to be made or skill on the part of the player just luck. In the simples
anygoal [31]
Abcdefghijklmnopqrstuvwxyz now I know my abcs, next time won’t you sing with me :)
8 0
2 years ago
A type of authentication that requires the user to provide something that they know, such
bagirrra123 [75]
The answer would be true
5 0
3 years ago
10
Nataly_w [17]

Ok so I don't know what your text is about so you'll have to figure that out your self

Scientists track these measurements to make a final model because using the research data from the previous model can show the grows and glows of that model. Using this data scientists can improve whats needed.

7 0
2 years ago
Descending selection sort with output during execution
FromTheMoon [43]

Answer:

Check the explanation

Explanation:

Please find the code down

def selection_sort_descend_trace(numbers):

i=len(numbers)

print("Output: ")

for num in range(0,i-1):# traversing from 0 to N-2, total N-1 iterations

val=numbers[num]

start=num+1

end=i

t=0

for j in range(start,end):

if(val<numbers[j]):

remember=j

val=numbers[j]

t=1

if(t==1):# swaping onlf if greater number is available

temp=numbers[num]

numbers[num]=val

numbers[remember]=temp

for p in range(i):# printing

print(numbers[p],end=' ')

print("\n")

if __name__ == "__main__":

print("Enter the integers separated by space: ")

numbers=[int(x) for x in input().split(' ')]

selection_sort_descend_trace(numbers)

Taking input as string and splitting with space as delimiter , converting the split part to integer , finally append in the list.

3 0
4 years ago
Other questions:
  • Write a program to read in a two values row and col to initialize a 2D array using those values. Then create a function FindTran
    15·1 answer
  • The Earth's _______ is ductile overall, tending to flow very slowly and deform in a _______ manner.
    14·2 answers
  • Need 2.5 Code Practice Answers
    14·2 answers
  • At a minimum, your vehicle insurance policy must provide coverage of
    10·1 answer
  • Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
    7·1 answer
  • What is characteristic of the Computer?
    11·2 answers
  • Which are common applications of deep learning in Artificial Intelligence (AI)?
    5·1 answer
  • Why is my Brainly scanner not work​
    5·2 answers
  • What is an example of content?
    7·1 answer
  • Discuss any 4 differences between first and second generation of programming languages <br>​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!