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
ss7ja [257]
3 years ago
15

Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in

the string. You may assume that the string does not contain spaces and will always contain less than 50 characters.Ex: If the input is:n Mondaythe output is:1Ex: If the input is:z TodayisMondaythe output is:0Ex: If the input is:n It'ssunnytodaythe output is:2Case matters.Ex: If the input is:n Nobodythe output is:0n is different than N.C++ Code:#include #include int main(void) {/* Type your code here. */return 0;}

Computers and Technology
1 answer:
Zina [86]3 years ago
6 0

Answer:

Here is the C++ program:

#include <iostream> // to include input output functions

using namespace std; // to identify objects like cin cout

int counter(string userString, char character) { //function counter

   int count = 0;   // counts the no of times a character appears in the string

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

// loop to move through the string to find the occurrence of the character

       if (userString[i] == character) //if characters is found in the string

           count++;   //counts the occurrence of the character in the string

   return count; }   //returns the no of times character occurs in the string

int main() { //start of the main() function body

   string s; // stores the string entered by the user

   cout<<"Enter a string: "; //prompts user to enter the string

   cin>>s; //reads the string from user

   char ch; //stores the character entered by the user

   cout<<"Enter a character: "; //prompts user to enter a character

   cin>>ch; //reads the character from user

   cout << counter(s, ch) << endl; }  

//calls counter function to find the number of times a character occurs in the //string

Explanation:

The counter function works as following:

It has a count variable which stores the number of occurrences of a character in the userString.

It uses a for loop which loops through the entire string.

It has i position variable which starts with the first character of the string and checks if the first character of userString matches with the required character.

If it matches the character then count variable counts the first occurrence of the character and in the userString and is incremented to 1.

If the character does not match with the first character of the userString then the loops keeps traversing through the userString until the end of the userString is reached which is specified by the length() function which returns the length of the string.

After the loop ends the return count statement is used to return the number of occurrences of the character in the userString.

The main() function prompts the user to enter a string and a character. It then calls counter() function passing string s and character ch arguments to it in order to get the number of times ch appears in s.

The output is attached in a screenshot.

You might be interested in
❤️❤️❤️❤️❤️❤️❤️❤️IS THERE ANYONE'S STILL AWAKE?? HMM HEHE I'M HERE AGAIN~~~ FOLLOW ME FOR MOR3~~​
insens350 [35]

Answer:

hello?

Explanation:

3 0
2 years ago
Read 2 more answers
In PKI, the CA periodically distributes a(n) _________ to all users that identifies all revoked certificates.
Trava [24]

Answer:

" CRL (certificate revocation list)" is the appropriate answer.

Explanation:

  • A collection of such subscriber bases containing accreditation or certification status combined with the validation, revocation, or outdated certification within each final customer is known as CRL.
  • Only certain subscribing workstations with a certain underlying cause authentication system should have been duplicated.
4 0
3 years ago
When it comes to collecting and organizing prospect and account​ information, salespeople have a large variety of computer syste
OleMash [197]

Answer:

sales force automation systems

Explanation:

Based on the information provided within the question it can be said that in this scenario these are known as sales force automation systems (SFA). This type of system or software is used in order to automate various business tasks, including managing contacts, order processing, sales, inventory, etc. Which is why it is mostly used by the salespeople.

4 0
2 years ago
Matts has finished running some security automation scripts on three newly deployed Linux servers. After applying intrusion dete
gizmo_the_mogwai [7]

Answer: CPU

Explanation:

The management dashboard refers to the tool that's used in the presentation of the vital k management KPIs in a single place, which is efficiently managed in order to make faster and better decisions.

Based on the information given, after the application of intrusion detection, virus, and malware protection on the Linux images, he will notices an increase in CPU on his server management dashboard.

Therefore, the correct option is C.

5 0
2 years ago
Types of email resources. Examples
denis23 [38]
Newsletter emails
Milestone emails
Welcome emails
Review request emails

Hope this helps!
8 0
3 years ago
Other questions:
  • Pedestrians, cyclists, horse drawn vehicles and wheel chair users are known as ___________
    6·2 answers
  • ____ are systems in which queues of objects are waiting to be served by various servers
    5·1 answer
  • Which of the following are examples of software? Check all of the boxes that apply.
    12·2 answers
  • I need someone to transfer this into a database in excel Please help :D 7 pts
    15·1 answer
  • What is 8 hours, 5 minutes, 22 seconds minus (-) 7 hours, 24 minutes, 37 seconds?
    6·1 answer
  • What is the TAG to begin a Web page, as recommended by the W3C?
    13·1 answer
  • Select the correct answer.
    13·1 answer
  • Word processing software, spreadsheet software, database software, and presentation software are examples of what category of co
    13·1 answer
  • Assuming dataFile is an ofstream object associated with a disk file named payroll.dat, which of the following statements would w
    9·1 answer
  • Kevin would like to ensure that his software runs on a platform that is able to expand and contract as needs change. Which one o
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!