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
Write code to define a function named mymath. The function has three arguments in the following order: Boolean, Integer, and Int
saveliy_v [14]

Answer:

public class Main

{

public static void main(String[] args) {

Main m=new Main();

System.out.println(m.mymath(true,5,2)); // calling the function mymath

}

public int mymath(boolean a,int b,int c) // mymath function definition

{

if(a==true)

{

int d=b+c;

return d;

}

else{int e=b-c;

return e;

}

}

}

7 0
2 years ago
What kind of printer is used with multipart forms such as those with point of sale machines?A) dot-matrixB) daisy-wheelC) inkjet
ivanzaharov [21]

Answer:

The answer is "Option A".

Explanation:

The Dot matrix printer is also known as an impact matrix printer. It is a multi-part form printer because it prints data on paper. This printer uses a hammer and a ribbon printer, that shapes pictures from dots. and other options are not correct, that can be described as follows:

  • In option B, daisy-wheel printer prints data on printer only one side that's it is not correct.
  • In option C, the Inkjet printer is capable to print data in multi-part forms, but this printer does not data in continuous forms.
  • In option D, the color printer allows you to print data in color format like images, graphs, and banner. It prints data only on one side, that's why it is not correct.  
6 0
3 years ago
When you're working with a word processing document and you press the DEL Key what happens
wariber [46]
<span>The character to the right of the cursor is deleted. </span>
4 0
3 years ago
Read 2 more answers
True or False: Changing a bid package's status to "Closed" removed it from the bidder's Planroom and the bidder will no longer b
Readme [11.4K]

Answer:

True

Explanation:

It's actually true because once a bidding page status changes to closed, it means that the timeframe for bidding has stopped, hence, no bidder will be able to bid again.

7 0
3 years ago
Which of the following recommendations should you follow when placing access points to provide wireless access for users within
Colt1911 [192]

A WLAN, or wireless local area network, is created by an access point, typically in an office or big building. An access point transmits a Wi-Fi signal to a predetermined region after connecting via an Ethernet cable to a wired router, switch, or hub. Thus, option C is correct.

<h3>What access points to provide wireless access for users?</h3>

You may determine your wireless access point IP address by going to the settings menu of your adapter if you're already connected to the network via Wi-Fi or Ethernet.

Therefore, Open Network & Internet settings can be accessed by selecting with the right mouse click on the network icon in the system tray.

Learn more about wireless access here:

brainly.com/question/13073711

#SPJ1

6 0
1 year ago
Other questions:
  • ________ is used to store programs and instructions that are automatically loaded when the computer is turned on.
    14·1 answer
  • Your school computer library has a network that connects computers and devices within a few small rooms. what type of network do
    7·1 answer
  • Rewriting notes into complete sentences is unnecessary if you want to include the notes in your study guide. Truth or false?
    15·2 answers
  • A mobile device user has tried to install a new app numerous times without success. She hasclosed all unused apps, disabled live
    12·1 answer
  • True or false.local and cloud backup differs in where the backup is saved
    15·2 answers
  • ___________ key encryption in wep uses the rc4 encryption algorithm.
    9·1 answer
  • Using ________ as a promotion method will bring return visitors to your site.
    8·1 answer
  • What are some things you can do to clean up your digital footprint.
    9·1 answer
  • Create a program that finds (n+1)! -factorial- of an integer n in C++.
    13·1 answer
  • Imagine an everyday scenario in which you are using the internet: downloading a file, uploading a photo, checking your email, et
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!