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]
2 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]2 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
Two friends can share 100 songs from their Bluetooth enabled mobile devices
Umnica [9.8K]

Answer:

A

Explanation:

If they are connected via bluetooth, you can share unlimited amounts of anything.

6 0
2 years ago
Under which tab can you find the options for reusing slides from other presentations
MrRissso [65]
U could first highlight text, right click then copy, and then Ctrl + v. You could find Ctrl (or control) under the shift button to your left
I hope this helped:D
5 0
3 years ago
What are characteristics of fluent readers? Check all that apply. reading known words automatically pronouncing words correctly
IRINA_888 [86]

Answer:

D,A,B hope this is it!!!!!

7 0
2 years ago
Read 2 more answers
Enter just the letter of the correct answer
Viefleur [7K]

Answer:

C. WDS

Explanation:

DND is for rolling dice and arguing about alignments

WiFi Analyzer just monitors your WiFi's stats and health

--> WDS lets you wirelessly connect two routers for larger range

DHCP is for IP address distribution.

3 0
3 years ago
Eric is working on a computer that has a device driver error. Eric can find the name of the device driver however the actual dev
wel

Answer:

Windows\System32\drivers folder.

Explanation:

Eric operates on such a computer which has some failure on system's driver. Although the specific system may not be operational, he will locate the system driver title. Inappropriately he has no Connectivity to the internet.

Windows\System32\drivers directory could move to him to show the file of the system driver. Thus, the following answer is correct according to the given scenario.

3 0
3 years ago
Other questions:
  • Which keyboard feature is a form feed character?
    14·1 answer
  • Darpa was created to
    13·1 answer
  • What will happen if Sam goes to the View menu, clicks Toolbars, and then clicks Picture?
    12·2 answers
  • What tasks does google do?
    5·1 answer
  • You are the network administrator for a school system. Your boss informs you that she is thinking of implementing a BYOD program
    15·2 answers
  • A company that manufactures machine parts orders a new system that makes products at ten times the speed of the earlier machine.
    15·1 answer
  • What is the importance of human flourishing to science and technology?​
    8·1 answer
  • Given the statement: int list[25]; The index can go from 0 to 25 inclusive withoutgoing beyond the end of the array.true or fals
    14·1 answer
  • A debate about city schools are more better than village schools​
    8·1 answer
  • How do we “read” and “write” in MAR and MDR memory unit, please help I am very confused :)
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!