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
polet [3.4K]
3 years ago
6

8.11 LAB: Count characters - functions Write a program whose input is a character and a string, and whose output indicates the n

umber of times the character appears in the string. Ex: If the input is: n Monday, the output is: 1 Ex: If the input is: z Today is Monday, the output is: 0 Ex: If the input is: n It's a sunny day, the output is: 2 Case matters. n is different than N. Ex: If the input is: n Nobody, the output is: 0 Your program must define and call the following function that returns the number of times the input character appears in the input string. int CountCharacters(char userChar, const string
Computers and Technology
1 answer:
Shkiper50 [21]3 years ago
6 0

Answer:

#include<iostream>

using namespace std;

int CountCharacters(char userChar, const string inputstr){

   int k = 0;

   int iter = 0;

   for (iter = 0; iter < inputstr.size(); iter++){

       if (inputstr[iter] ==  userChar){

           ++k;        }}

   return k;}

int main(){

   string str;

   char userChar[1];

   cout<<"Char: ";    cin>>userChar;

   cin.ignore();

   cout<<"String: ";   getline(cin, str);

   cout<<CountCharacters(userChar[0],str);

   return 0;}

Explanation:

Written in C++:

The function is defined here:

int CountCharacters(char userChar, const string inputstr){

This initializes a count variable k to 0

   int k = 0;

This initializes an iterating variable iter to 0

   int iter = 0;

This iterates through the characters of the string being passed to the function

   for (iter = 0; iter < inputstr.size(); iter++){

This checks for matching characters

       if (inputstr[iter] ==  userChar){

If found,  k is incremented by 1

           ++k;        }}

This returns the total count

   return k;}

The main begins here

int main(){

This declares a string variable

   string str;

This declares a character variable

   char userChar[1];

This gets input for the character variable

   cout<<"Char: ";    cin>>userChar;

This lets the user get another input

   cin.ignore();

This gets input for the string variable

   cout<<"String: ";   getline(cin, str);

This calls the function and return the count of character in the string

   cout<<CountCharacters(userChar[0],str);

You might be interested in
Several steps are involved in creating a presentation. What is the last step in the process before preparing to present it?
kupik [55]
The answer to this is B.
8 0
3 years ago
Read 2 more answers
In a Position Analysis Questionnaire (PAQ), _____ refers to the physical activities, tools, and devices used by a worker to perf
xxMikexx [17]

Answer:

Work Output.

Explanation:

The work output in a PAQ refers to that of the physical exercise, equipment, and technologies an individual uses to perform a service. The main justification for using a PAQ is to acquire quantitative info that helps administrators to analyze employments for payment reasons.

So, the following answer is correct about the given scenario.

8 0
4 years ago
1) ¿Que es la entrada en calor?​
Nataly [62]

Answer:

<h2><em><u>El objetivo principal de realizar la llamada entrada en calor o calentamiento es preparar el cuerpo para la actividad ficica ficica o deportiva </u></em></h2>

6 0
3 years ago
Which device assists with medical imaging? HELPPPP!!!!!!
FinnZ [79.3K]

Answer:

<h2><u>Medical imaging equipment are manufactured using technology from the semiconductor industry, including CMOS integrated circuit chips, power semiconductor devices, sensors such as image sensors (particularly CMOS sensors) and biosensors</u></h2>

Explanation:

7 0
4 years ago
____ is a linux-based operating system developed by the open handset alliance.
Misha Larkins [42]
The answer is Android
6 0
4 years ago
Other questions:
  • Almost all PCs have this type of serial connector
    8·1 answer
  • 1. What arguments can you make for the idea of a single language for all programming domains
    10·1 answer
  • If the pc-doctor software is installed on a computer's hard drive, what two different ways can the program be started?
    9·1 answer
  • If the boolean expression a is true and b is false, the value of the logical expression a or b is ________.
    14·1 answer
  • The term used for doing business online is referred to as ___.
    12·1 answer
  • Is it true or false and incomplete doing can be saved in Paint​
    15·1 answer
  • Cite an early photographic pioneer or invention. Explain their/its impact on photography as we know it today.
    14·1 answer
  • Why does a computer need programs? ​
    8·2 answers
  • Why accessing information over the internet is so convenient.​
    11·1 answer
  • Write a python program to find the volume of the pepsi present in the can which is in the shape of cylinder accepting the radius
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!